Implements basic bulk debates functionality
This commit is contained in:
18
app/controllers/moderation/bulk_controller.rb
Normal file
18
app/controllers/moderation/bulk_controller.rb
Normal file
@@ -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
|
||||||
@@ -24,5 +24,12 @@
|
|||||||
<%= t("moderation.menu.users") %>
|
<%= t("moderation.menu.users") %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
|
<li <%= "class=active" if controller_name == "bulk" %>>
|
||||||
|
<%= link_to moderation_bulk_path do %>
|
||||||
|
<i class="icon-debates"></i>
|
||||||
|
<%= t("moderation.menu.bulk") %>
|
||||||
|
<% end %>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
|||||||
39
app/views/moderation/bulk/index.html.erb
Normal file
39
app/views/moderation/bulk/index.html.erb
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<h2><%= t("moderation.bulk.index.title") %></h2>
|
||||||
|
|
||||||
|
<h3><%= page_entries_info @debates %></h3>
|
||||||
|
|
||||||
|
<%= form_tag moderation_bulk_hide_path, method: :put do %>
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
<%= t("moderation.bulk.index.headers.debate") %>
|
||||||
|
</th>
|
||||||
|
<th class="text-center"><%= t("moderation.bulk.index.headers.flags") %></th>
|
||||||
|
<th>
|
||||||
|
<%= t("moderation.bulk.index.headers.moderate") %>
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
<% @debates.each do |debate| %>
|
||||||
|
<tr id="debate_<%= debate.id %>">
|
||||||
|
<td>
|
||||||
|
<%= link_to debate.title, debate, target: "_blank" %>
|
||||||
|
<span class="bullet"> • </span>
|
||||||
|
<%= debate.author.username %>
|
||||||
|
<span class="bullet"> • </span>
|
||||||
|
<span class="date"><%= l debate.updated_at.to_date %></span>
|
||||||
|
<br>
|
||||||
|
<%= debate.description %>
|
||||||
|
</td>
|
||||||
|
<td class="text-center"><%= debate.flags_count %></td>
|
||||||
|
<td class="text-center">
|
||||||
|
<%= check_box_tag "debate_ids[]", debate.id, nil, id: "#{dom_id(debate)}_check" %>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<%= 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 %>
|
||||||
@@ -4,6 +4,7 @@ en:
|
|||||||
flagged_debates: Debates
|
flagged_debates: Debates
|
||||||
flagged_comments: Comments
|
flagged_comments: Comments
|
||||||
users: Ban users
|
users: Ban users
|
||||||
|
bulk: Bulk moderation
|
||||||
dashboard:
|
dashboard:
|
||||||
index:
|
index:
|
||||||
title: Moderation
|
title: Moderation
|
||||||
@@ -41,6 +42,16 @@ en:
|
|||||||
all: All
|
all: All
|
||||||
pending_flag_review: Pending
|
pending_flag_review: Pending
|
||||||
with_ignored_flag: Ignored
|
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:
|
users:
|
||||||
notice_hide: User banned.
|
notice_hide: User banned.
|
||||||
index:
|
index:
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ es:
|
|||||||
flagged_debates: Debates
|
flagged_debates: Debates
|
||||||
flagged_comments: Comentarios
|
flagged_comments: Comentarios
|
||||||
users: Bloquear usuarios
|
users: Bloquear usuarios
|
||||||
|
bulk: Moderar en bloque
|
||||||
dashboard:
|
dashboard:
|
||||||
index:
|
index:
|
||||||
title: Moderación
|
title: Moderación
|
||||||
@@ -41,6 +42,16 @@ es:
|
|||||||
all: Todos
|
all: Todos
|
||||||
pending_flag_review: Pendientes
|
pending_flag_review: Pendientes
|
||||||
with_ignored_flag: Ignorados
|
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:
|
users:
|
||||||
notice_hide: Usuario bloqueado. Se han ocultado todos sus debates y comentarios.
|
notice_hide: Usuario bloqueado. Se han ocultado todos sus debates y comentarios.
|
||||||
index:
|
index:
|
||||||
|
|||||||
@@ -119,6 +119,9 @@ Rails.application.routes.draw do
|
|||||||
put :ignore_flag
|
put :ignore_flag
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
get '/bulk', to: "bulk#index"
|
||||||
|
put '/bulk/hide', to: "bulk#hide"
|
||||||
end
|
end
|
||||||
|
|
||||||
resource :stats, only: [:show]
|
resource :stats, only: [:show]
|
||||||
|
|||||||
35
spec/features/moderation/bulk_spec.rb
Normal file
35
spec/features/moderation/bulk_spec.rb
Normal file
@@ -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
|
||||||
Reference in New Issue
Block a user