Unifies bulk & debates moderation forms in a single one

This commit is contained in:
kikito
2015-09-21 15:41:01 +02:00
parent 8fc2058bd9
commit 757205a93e
15 changed files with 229 additions and 283 deletions

View File

@@ -1,32 +1,43 @@
class Moderation::DebatesController < Moderation::BaseController
has_filters %w{pending_flag_review all with_ignored_flag}, only: :index
has_orders %w{flags created_at}, only: :index
before_action :load_debates, only: :index
before_action :load_debates, only: [:index, :moderate]
load_and_authorize_resource
def index
@debates = @debates.send(@current_filter).page(params[:page])
@debates = @debates.send(@current_filter)
.send("sort_by_#{@current_order}")
.page(params[:page])
.per(50)
end
def hide
@debate.hide
end
def hide_in_moderation_screen
@debate.hide
redirect_to request.query_parameters.merge(action: :index)
end
def moderate
@debates = @debates.where(id: params[:debate_ids])
if params[:hide_debates].present?
@debates.accessible_by(current_ability, :hide).each(&:hide)
elsif params[:ignore_flags].present?
@debates.accessible_by(current_ability, :ignore_flag).each(&:ignore_flag)
elsif params[:block_authors].present?
author_ids = @debates.pluck(:author_id).uniq
User.where(id: author_ids).accessible_by(current_ability, :block).each(&:block)
end
def ignore_flag
@debate.ignore_flag
redirect_to request.query_parameters.merge(action: :index)
end
private
def load_debates
@debates = Debate.accessible_by(current_ability, :hide).flagged.sort_for_moderation
@debates = Debate.accessible_by(current_ability, :moderate)
end
end