Merge pull request #1376 from gcapizzi/lists_controller_refactoring

ListController refactoring
This commit is contained in:
Robin Ward 2013-08-25 07:29:35 -07:00
commit e1efde6707
1 changed files with 9 additions and 4 deletions

View File

@ -8,10 +8,7 @@ class ListController < ApplicationController
[:latest, :hot, :favorited, :read, :posted, :unread, :new].each do |filter|
define_method(filter) do
list_opts = build_topic_list_options
user = current_user
if params[:user_id] && guardian.is_staff?
user = User.find(params[:user_id].to_i)
end
user = list_target_user
list = TopicQuery.new(user, list_opts).public_send("list_#{filter}")
list.more_topics_url = url_for(self.public_send "#{filter}_path".to_sym, list_opts.merge(format: 'json', page: next_page))
@ -149,4 +146,12 @@ class ListController < ApplicationController
exclude_category: (params[:exclude_category] || menu_item.try(:filter))
}
end
def list_target_user
if params[:user_id] && guardian.is_staff?
User.find(params[:user_id].to_i)
else
current_user
end
end
end