diff --git a/app/controllers/moderation/bulk_controller.rb b/app/controllers/moderation/bulk_controller.rb deleted file mode 100644 index aa28b3213..000000000 --- a/app/controllers/moderation/bulk_controller.rb +++ /dev/null @@ -1,18 +0,0 @@ -class Moderation::BulkController < Moderation::BaseController - - def index - @debates = Debate.sort_for_moderation.page(params[:page]).per(100).includes(:author) - end - - def hide - debates = Debate.where(id: params[:debate_ids]) - if params[:commit] == t('moderation.bulk.index.hide_debates') - debates.each(&:hide) - elsif params[:commit] == t('moderation.bulk.index.block_authors') - debates.includes(:author).map(&:author).uniq.each(&:block) - end - - redirect_to action: :index - end - -end diff --git a/app/controllers/moderation/debates_controller.rb b/app/controllers/moderation/debates_controller.rb index c54851cb9..1fe3eb4b4 100644 --- a/app/controllers/moderation/debates_controller.rb +++ b/app/controllers/moderation/debates_controller.rb @@ -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 diff --git a/app/models/ability.rb b/app/models/ability.rb index 23c6f9f01..bbe59f736 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -65,6 +65,9 @@ class Ability can :ignore_flag, Debate, ignored_flag_at: nil, hidden_at: nil cannot :ignore_flag, Debate, author_id: user.id + can :moderate, Debate + cannot :moderate, Debate, author_id: user.id + can :hide, Proposal, hidden_at: nil cannot :hide, Proposal, author_id: user.id diff --git a/app/models/debate.rb b/app/models/debate.rb index 4785ab04f..d6483f0ad 100644 --- a/app/models/debate.rb +++ b/app/models/debate.rb @@ -25,13 +25,13 @@ class Debate < ActiveRecord::Base before_save :calculate_hot_score, :calculate_confidence_score - scope :sort_for_moderation, -> { order(flags_count: :desc, updated_at: :desc) } scope :for_render, -> { includes(:tags) } scope :sort_by_hot_score , -> { order(hot_score: :desc) } scope :sort_by_confidence_score , -> { order(confidence_score: :desc) } scope :sort_by_created_at, -> { order(created_at: :desc) } scope :sort_by_most_commented, -> { order(comments_count: :desc) } scope :sort_by_random, -> { order("RANDOM()") } + scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) } # Ahoy setup visitable # Ahoy will automatically assign visit_id on create diff --git a/app/views/moderation/_menu.html.erb b/app/views/moderation/_menu.html.erb index 04bd02f4d..577b66342 100644 --- a/app/views/moderation/_menu.html.erb +++ b/app/views/moderation/_menu.html.erb @@ -31,12 +31,5 @@ <%= t("moderation.menu.users") %> <% end %> - -
- <%= t('moderation.bulk.index.check') %>: - <%= link_to t('moderation.bulk.index.check_all'), '#', data: {check_all: "debate_ids[]"} %> - | - <%= link_to t('moderation.bulk.index.check_none'), '#', data: {check_none: "debate_ids[]"} %> -
- -| - <%= t("moderation.bulk.index.headers.debate") %> - | -<%= t("moderation.bulk.index.headers.flags") %> | -- <%= t("moderation.bulk.index.headers.moderate") %> - | -
|---|---|---|
|
- <%= link_to debate.title, debate, target: "_blank" %>
- •
- <%= debate.author.username %>
- •
- <%= l debate.updated_at.to_date %>
- - <%= debate.description %> - |
- <%= debate.flags_count %> | -- <%= check_box_tag "debate_ids[]", debate.id, nil, id: "#{dom_id(debate)}_check" %> - | -
| - <%= t("moderation.debates.index.headers.title") %> | - <%= t("moderation.debates.index.headers.updated_at") %> | - <%= t("moderation.debates.index.headers.description") %> - | -<%= t("moderation.debates.index.headers.flags") %> | -<%= t("moderation.debates.index.headers.actions") %> | -||||
|---|---|---|---|---|---|---|
|
- <%= link_to debate.title, debate, target: "_blank" %>
- - <%= l debate.updated_at.to_date %> - - <%= debate.description %> - |
- <%= debate.flags_count %> | -- <%= link_to t("moderation.debates.index.hide"), hide_in_moderation_screen_moderation_debate_path(debate, request.query_parameters), method: :put, class: "delete" %> - | - <% if can? :ignore_flag, debate %> -- <%= link_to t("moderation.debates.index.ignore_flag"), ignore_flag_moderation_debate_path(debate, request.query_parameters), method: :put, class: "button radius tiny warning" %> - | - <% end %> - <% if debate.ignored_flag? %> -- <%= t("moderation.debates.index.ignored_flag") %> - | - <% end %> +<%= form_tag moderate_moderation_debates_path(request.query_parameters), method: :put do %> +||
| + <%= t("moderation.debates.index.headers.debate") %> + | ++ <%= t("moderation.debates.index.headers.moderate") %> + |
|---|