refactors moderator actions

This commit is contained in:
rgarcia
2015-10-11 13:40:58 +02:00
parent b4adca0559
commit 3edc23abe5
4 changed files with 76 additions and 123 deletions

View File

@@ -1,53 +1,20 @@
class Moderation::CommentsController < Moderation::BaseController
include ModerateActions
has_filters %w{pending_flag_review all with_ignored_flag}, only: :index
has_orders %w{flags created_at}, only: :index
before_action :load_comments, only: [:index, :moderate]
before_action :load_resources, only: [:index, :moderate]
load_and_authorize_resource
def index
@comments = @comments.send(@current_filter)
.send("sort_by_#{@current_order}")
.page(params[:page])
.per(50)
end
def hide
hide_comment @comment
end
def moderate
@comments = @comments.where(id: params[:comment_ids])
if params[:hide_comments].present?
@comments.accessible_by(current_ability, :hide).each {|comment| hide_comment comment}
elsif params[:ignore_flags].present?
@comments.accessible_by(current_ability, :ignore_flag).each(&:ignore_flag)
elsif params[:block_authors].present?
author_ids = @comments.pluck(:user_id).uniq
User.where(id: author_ids).accessible_by(current_ability, :block).each {|user| block_user user}
end
redirect_to request.query_parameters.merge(action: :index)
end
private
def load_comments
@comments = Comment.accessible_by(current_ability, :moderate)
def resource_model
Comment
end
def hide_comment(comment)
comment.hide
Activity.log(current_user, :hide, comment)
def author_id
:user_id
end
def block_user(user)
user.block
Activity.log(current_user, :block, user)
end
end