Merge pull request #437 from AyuntamientoMadrid/debate-moderation-2

Bulk moderation
This commit is contained in:
Raimond Garcia
2015-09-08 20:55:51 +02:00
11 changed files with 187 additions and 12 deletions

View File

@@ -32,6 +32,7 @@ var initialize_modules = function() {
App.Stats.initialize();
App.Dropdown.initialize();
App.LocationChanger.initialize();
App.CheckAllNone.initialize();
};
$(function(){

View File

@@ -0,0 +1,13 @@
App.CheckAllNone =
initialize: ->
$('[data-check-all]').on 'click', ->
target_name = $(this).data('check-all')
$("[name='" + target_name + "']").prop('checked', true)
$('[data-check-none]').on 'click', ->
target_name = $(this).data('check-none')
$("[name='" + target_name + "']").prop('checked', false)

View 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

View File

@@ -1,28 +1,26 @@
class Moderation::UsersController < Moderation::BaseController
before_filter :load_users, only: :index
load_and_authorize_resource
def index
@users = User.with_hidden.search(params[:name_or_email]).page(params[:page]).for_render
end
def hide_in_moderation_screen
hide_user
@user.block
redirect_to request.query_parameters.merge(action: :index), notice: I18n.t('moderation.users.notice_hide')
end
def hide
hide_user
@user.block
redirect_to debates_path
end
private
def hide_user
user = User.find(params[:id])
debates_ids = Debate.where(author_id: user.id).pluck(:id)
comments_ids = Comment.where(user_id: user.id).pluck(:id)
user.hide
Debate.hide_all debates_ids
Comment.hide_all comments_ids
end
def load_users
@users = User.with_hidden.search(params[:name_or_email]).page(params[:page]).for_render
end
end
end

View File

@@ -117,6 +117,15 @@ class User < ActiveRecord::Base
update official_position: nil, official_level: 0
end
def block
debates_ids = Debate.where(author_id: id).pluck(:id)
comments_ids = Comment.where(user_id: id).pluck(:id)
self.hide
Debate.hide_all debates_ids
Comment.hide_all comments_ids
end
def self.search(term)
term.present? ? where("email = ? OR username ILIKE ?", term, "%#{term}%") : none
end

View File

@@ -24,5 +24,12 @@
<%= t("moderation.menu.users") %>
<% end %>
</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>
</nav>

View File

@@ -0,0 +1,46 @@
<h2><%= t("moderation.bulk.index.title") %></h2>
<h3><%= page_entries_info @debates %></h3>
<%= form_tag moderation_bulk_hide_path, method: :put do %>
<p class="right">
<%= 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[]"} %>
</p>
<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">&nbsp;&bullet;&nbsp;</span>
<%= debate.author.username %>
<span class="bullet">&nbsp;&bullet;&nbsp;</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 %>

View File

@@ -4,6 +4,7 @@ en:
flagged_debates: Debates
flagged_comments: Comments
users: Ban users
bulk: Bulk moderation
dashboard:
index:
title: Moderation
@@ -41,6 +42,19 @@ 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?
check: Select
check_all: All
check_none: None
users:
notice_hide: User banned.
index:

View File

@@ -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,19 @@ 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?
check: Seleccionar
check_all: Todos
check_none: Ninguno
users:
notice_hide: Usuario bloqueado. Se han ocultado todos sus debates y comentarios.
index:

View File

@@ -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]

View File

@@ -0,0 +1,52 @@
require 'rails_helper'
feature 'Moderate in bulk' do
background do
moderator = create(:moderator)
login_as(moderator.user)
end
feature "When a debate has been selected for moderation" do
background do
@debate = create(:debate)
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
scenario "select all/none", :js do
create_list(:debate, 20)
visit moderation_bulk_path
click_on 'All'
all('input[type=checkbox]').each do |checkbox|
expect(checkbox).to be_checked
end
click_on 'None'
all('input[type=checkbox]').each do |checkbox|
expect(checkbox).to_not be_checked
end
end
end