SM MS; Read email sent to diaspora-dev for more information about this

commit. Add migration and rake task to copy hidden information from
share_visibilities to users. see: http://devblog.joindiaspora.com/?p=44
This commit is contained in:
Maxwell Salzberg
2012-01-07 17:52:35 -08:00
parent a658552c3f
commit 254860bddc
16 changed files with 291 additions and 114 deletions

View File

@@ -11,37 +11,14 @@ class ShareVisibilitiesController < ApplicationController
params[:shareable_id] ||= params[:post_id]
params[:shareable_type] ||= 'Post'
@post = accessible_post
@contact = current_user.contact_for(@post.author)
if @contact && @vis = ShareVisibility.where(:contact_id => @contact.id,
:shareable_id => params[:shareable_id],
:shareable_type => params[:shareable_type]).first
@vis.hidden = !@vis.hidden
if @vis.save
update_cache(@vis)
render :nothing => true, :status => 200
return
end
end
render :nothing => true, :status => 403
vis = current_user.toggle_hidden_shareable(accessible_post)
RedisCache.update_cache_for(current_user, accessible_post, vis)
render :nothing => true, :status => 200
end
protected
def update_cache(visibility)
return unless RedisCache.configured?
cache = RedisCache.new(current_user, 'created_at')
if visibility.hidden?
cache.remove(accessible_post.id)
else
cache.add(accessible_post.created_at.to_i, accessible_post.id)
end
end
def accessible_post
@post ||= Post.where(:id => params[:post_id]).select("id, guid, author_id, created_at").first
@post ||= params[:shareable_type].constantize.where(:id => params[:post_id]).select("id, guid, author_id, created_at").first
end
end