diff --git a/app/controllers/moderation/bulk_controller.rb b/app/controllers/moderation/bulk_controller.rb new file mode 100644 index 000000000..aa28b3213 --- /dev/null +++ b/app/controllers/moderation/bulk_controller.rb @@ -0,0 +1,18 @@ +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/views/moderation/_menu.html.erb b/app/views/moderation/_menu.html.erb index 2b5f938bd..2f8954290 100644 --- a/app/views/moderation/_menu.html.erb +++ b/app/views/moderation/_menu.html.erb @@ -24,5 +24,12 @@ <%= t("moderation.menu.users") %> <% end %> + +
  • > + <%= link_to moderation_bulk_path do %> + + <%= t("moderation.menu.bulk") %> + <% end %> +
  • diff --git a/app/views/moderation/bulk/index.html.erb b/app/views/moderation/bulk/index.html.erb new file mode 100644 index 000000000..77d283b80 --- /dev/null +++ b/app/views/moderation/bulk/index.html.erb @@ -0,0 +1,39 @@ +

    <%= t("moderation.bulk.index.title") %>

    + +

    <%= page_entries_info @debates %>

    + +<%= form_tag moderation_bulk_hide_path, method: :put do %> + + + + + + + <% @debates.each do |debate| %> + + + + + + <% end %> +
    + <%= 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" %> +
    + + <%= submit_tag t('moderation.bulk.index.hide_debates'), class: "button radius", data: {confirm: t('moderation.bulk.index.confirm')} %> + <%= submit_tag t('moderation.bulk.index.block_authors'), class: "button radius", data: {confirm: t('moderation.bulk.index.confirm')} %> +<% end %> + +<%= paginate @debates %> diff --git a/config/locales/moderation.en.yml b/config/locales/moderation.en.yml index 21db348a7..0503a9981 100644 --- a/config/locales/moderation.en.yml +++ b/config/locales/moderation.en.yml @@ -4,6 +4,7 @@ en: flagged_debates: Debates flagged_comments: Comments users: Ban users + bulk: Bulk moderation dashboard: index: title: Moderation @@ -41,6 +42,16 @@ en: all: All pending_flag_review: Pending with_ignored_flag: Ignored + bulk: + index: + title: Bulk moderation + headers: + debate: Debate + flags: Denuncias + moderate: Moderar + hide_debates: Hide debates + block_authors: Block authors + confirm: Are you sure? users: notice_hide: User banned. index: diff --git a/config/locales/moderation.es.yml b/config/locales/moderation.es.yml index 2c397c4de..549a724b1 100644 --- a/config/locales/moderation.es.yml +++ b/config/locales/moderation.es.yml @@ -4,6 +4,7 @@ es: flagged_debates: Debates flagged_comments: Comentarios users: Bloquear usuarios + bulk: Moderar en bloque dashboard: index: title: Moderación @@ -41,6 +42,16 @@ es: all: Todos pending_flag_review: Pendientes with_ignored_flag: Ignorados + bulk: + index: + title: Moderar en bloque + headers: + debate: Debate + flags: Denuncias + moderate: Moderar + hide_debates: Ocultar debates + block_authors: Bloquear usuarios + confirm: ¿Estás seguro? users: notice_hide: Usuario bloqueado. Se han ocultado todos sus debates y comentarios. index: diff --git a/config/routes.rb b/config/routes.rb index f7748fad4..87a75d9ea 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -119,6 +119,9 @@ Rails.application.routes.draw do put :ignore_flag end end + + get '/bulk', to: "bulk#index" + put '/bulk/hide', to: "bulk#hide" end resource :stats, only: [:show] diff --git a/spec/features/moderation/bulk_spec.rb b/spec/features/moderation/bulk_spec.rb new file mode 100644 index 000000000..e1869da90 --- /dev/null +++ b/spec/features/moderation/bulk_spec.rb @@ -0,0 +1,35 @@ +require 'rails_helper' + +feature 'Moderate in bulk' do + + feature "When a debate has been selected for moderation" do + background do + moderator = create(:moderator) + @debate = create(:debate) + + login_as(moderator.user) + visit moderation_bulk_path + + within("#debate_#{@debate.id}") do + check "debate_#{@debate.id}_check" + end + + expect(page).to_not have_css("debate_#{@debate.id}") + end + + scenario 'Hide the debate' do + click_on "Hide debates" + expect(page).to_not have_css("debate_#{@debate.id}") + expect(@debate.reload).to be_hidden + expect(@debate.author).to_not be_hidden + end + + scenario 'Block the author' do + click_on "Block authors" + expect(page).to_not have_css("debate_#{@debate.id}") + expect(@debate.reload).to be_hidden + expect(@debate.author).to be_hidden + end + end + +end