changes comment moderation to be similar to proposals moderation
This commit is contained in:
@@ -1,33 +1,43 @@
|
||||
class Moderation::CommentsController < 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_comments, only: :index
|
||||
before_action :load_comments, only: [:index, :moderate]
|
||||
|
||||
load_and_authorize_resource
|
||||
|
||||
def index
|
||||
@comments = @comments.send(@current_filter)
|
||||
@comments = @comments.page(params[:page])
|
||||
.send("sort_by_#{@current_order}")
|
||||
.page(params[:page])
|
||||
.per(50)
|
||||
end
|
||||
|
||||
def hide
|
||||
@comment.hide
|
||||
end
|
||||
|
||||
def hide_in_moderation_screen
|
||||
@comment.hide
|
||||
redirect_to request.query_parameters.merge(action: :index)
|
||||
def moderate
|
||||
@comments = @comments.where(id: params[:comment_ids])
|
||||
|
||||
if params[:hide_comments].present?
|
||||
@comments.accessible_by(current_ability, :hide).each(&:hide)
|
||||
|
||||
elsif params[:ignore_flags].present?
|
||||
@comments.accessible_by(current_ability, :ignore_flag).each(&:ignore_flag)
|
||||
|
||||
elsif params[:block_authors].present?
|
||||
author_ids = @comments.pluck(:user_id).uniq
|
||||
User.where(id: author_ids).accessible_by(current_ability, :block).each(&:block)
|
||||
end
|
||||
|
||||
def ignore_flag
|
||||
@comment.ignore_flag
|
||||
redirect_to request.query_parameters.merge(action: :index)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def load_comments
|
||||
@comments = Comment.accessible_by(current_ability, :hide).flagged.sort_for_moderation.includes(:commentable)
|
||||
@comments = Comment.accessible_by(current_ability, :moderate)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -59,6 +59,9 @@ class Ability
|
||||
can :ignore_flag, Comment, ignored_flag_at: nil, hidden_at: nil
|
||||
cannot :ignore_flag, Comment, user_id: user.id
|
||||
|
||||
can :moderate, Comment
|
||||
cannot :moderate, Comment, user_id: user.id
|
||||
|
||||
can :hide, Debate, hidden_at: nil
|
||||
cannot :hide, Debate, author_id: user.id
|
||||
|
||||
|
||||
@@ -18,9 +18,10 @@ class Comment < ActiveRecord::Base
|
||||
belongs_to :user, -> { with_hidden }
|
||||
|
||||
scope :recent, -> { order(id: :desc) }
|
||||
scope :sort_for_moderation, -> { order(flags_count: :desc, updated_at: :desc) }
|
||||
scope :for_render, -> { with_hidden.includes(user: :organization) }
|
||||
scope :with_visible_author, -> { joins(:user).where("users.hidden_at IS NULL") }
|
||||
scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) }
|
||||
scope :sort_by_created_at, -> { order(created_at: :desc) }
|
||||
|
||||
after_create :call_after_commented
|
||||
|
||||
|
||||
@@ -2,44 +2,76 @@
|
||||
|
||||
<%= render 'shared/filter_subnav', i18n_namespace: "moderation.comments.index" %>
|
||||
|
||||
<h3><%= page_entries_info @comments %></h3>
|
||||
<div class="row">
|
||||
<h3 class="small-8 large-8 columns"><%= page_entries_info @comments %></h3>
|
||||
<div class="small-4 large-4 columns">
|
||||
<div class="right">
|
||||
<%= t("moderation.comments.index.order") %>
|
||||
<%= render 'shared/order_selector', i18n_namespace: "moderation.comments.index" %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%= form_tag moderate_moderation_comments_path(request.query_parameters), method: :put do %>
|
||||
<p class="right js-check">
|
||||
<%= t('shared.check') %>:
|
||||
<%= link_to t('shared.check_all'), '#', data: {check_all: "comment_ids[]"} %>
|
||||
|
|
||||
<%= link_to t('shared.check_none'), '#', data: {check_none: "comment_ids[]"} %>
|
||||
</p>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th>
|
||||
<%= t("moderation.comments.index.headers.commentable") %> |
|
||||
<%= t("moderation.comments.index.headers.commentable_type") %> |
|
||||
<%= t("moderation.comments.index.headers.updated_at") %>
|
||||
<%= t("moderation.comments.index.headers.comment") %>
|
||||
</th>
|
||||
<th>
|
||||
<%= t("moderation.comments.index.headers.moderate") %>
|
||||
</th>
|
||||
<th><%= t("moderation.comments.index.headers.comment") %></th>
|
||||
<th class="text-center"><%= t("moderation.comments.index.headers.flags") %></th>
|
||||
<th class="text-center" colspan="2"> </th>
|
||||
</tr>
|
||||
|
||||
<% @comments.each do |comment| %>
|
||||
<tr id="comment_<%= comment.id %>">
|
||||
<td>
|
||||
<%= comment.commentable_type.constantize.model_name.human %> -
|
||||
<%= link_to comment.commentable.title, comment.commentable %>
|
||||
<br>
|
||||
<%= comment.commentable_type.constantize.model_name.human %>
|
||||
<span class="date"><%= l comment.updated_at.to_date %></span>
|
||||
<span class="bullet"> • </span>
|
||||
<%= comment.flags_count %><i class="icon-flag flag-disable"></i>
|
||||
<span class="bullet"> • </span>
|
||||
<%= comment.author.username %>
|
||||
<br>
|
||||
<p>
|
||||
<%= comment.body %>
|
||||
</p>
|
||||
</td>
|
||||
<td><%= text_with_links comment.body %></td>
|
||||
<td class="text-center"><%= comment.flags_count %></td>
|
||||
<td>
|
||||
<%= link_to t("moderation.comments.index.hide"), hide_in_moderation_screen_moderation_comment_path(comment, request.query_parameters), method: :put, class: "delete" %>
|
||||
<td class="text-center">
|
||||
<%= check_box_tag "comment_ids[]", comment.id, nil, id: "#{dom_id(comment)}_check" %>
|
||||
</td>
|
||||
<% if can? :ignore_flag, comment %>
|
||||
<td>
|
||||
<%= link_to t("moderation.comments.index.ignore_flag"), ignore_flag_moderation_comment_path(comment, request.query_parameters), method: :put, class: "button radius tiny warning" %>
|
||||
</td>
|
||||
<% end %>
|
||||
<% if comment.ignored_flag? %>
|
||||
<td class="ignored">
|
||||
<%= t("moderation.comments.index.ignored_flag") %>
|
||||
</td>
|
||||
<% end %>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
|
||||
<%= submit_tag t('moderation.comments.index.block_authors'),
|
||||
name: "block_authors",
|
||||
class: "button radius alert",
|
||||
data: {confirm: t('moderation.comments.index.confirm')}
|
||||
%>
|
||||
|
||||
<div class="right">
|
||||
<%= submit_tag t('moderation.comments.index.hide_comments'),
|
||||
name: "hide_comments",
|
||||
class: "button radius alert",
|
||||
data: {confirm: t('moderation.comments.index.confirm')}
|
||||
%>
|
||||
<%= submit_tag t('moderation.comments.index.ignore_flags'),
|
||||
name: "ignore_flags",
|
||||
class: "button radius success",
|
||||
data: {confirm: t('moderation.comments.index.confirm')}
|
||||
%>
|
||||
</div>
|
||||
|
||||
<%= paginate @comments %>
|
||||
|
||||
<% end %>
|
||||
|
||||
@@ -110,6 +110,7 @@ ignore_unused:
|
||||
- 'admin.users.index.filter*'
|
||||
- 'admin.comments.index.hidden_*'
|
||||
- 'moderation.comments.index.filter*'
|
||||
- 'moderation.comments.index.order*'
|
||||
- 'moderation.debates.index.filter*'
|
||||
- 'moderation.proposals.index.filter*'
|
||||
- 'moderation.proposals.index.order*'
|
||||
|
||||
@@ -10,21 +10,23 @@ en:
|
||||
title: Moderation
|
||||
comments:
|
||||
index:
|
||||
title: Comments flagged as inappropriate
|
||||
hide_comments: Hide comments
|
||||
block_authors: Block authors
|
||||
ignore_flags: Ignore flags
|
||||
title: Comments
|
||||
headers:
|
||||
flags: Flags
|
||||
updated_at: Date
|
||||
commentable_type: Type
|
||||
commentable: Root
|
||||
comment: Comment
|
||||
hide: Hide
|
||||
ignore_flag: Ignore
|
||||
ignored_flag: Ignored
|
||||
moderate: Moderate
|
||||
filter: Filter
|
||||
filters:
|
||||
all: All
|
||||
pending_flag_review: Pending
|
||||
with_ignored_flag: Ignored
|
||||
order: Order
|
||||
orders:
|
||||
created_at: Newest
|
||||
flags: Most flagged
|
||||
confirm: Are you sure?
|
||||
debates:
|
||||
index:
|
||||
hide_debates: Hide debates
|
||||
|
||||
@@ -10,21 +10,23 @@ es:
|
||||
title: Moderación
|
||||
comments:
|
||||
index:
|
||||
title: Comentarios denunciados como inapropiados
|
||||
hide_comments: Ocultar comentarios
|
||||
block_authors: Bloquear autores
|
||||
ignore_flags: Marcar como revisados
|
||||
title: Comentarios
|
||||
headers:
|
||||
flags: Denuncias
|
||||
updated_at: Fecha
|
||||
commentable_type: Tipo
|
||||
commentable: Raíz
|
||||
comment: Comentario
|
||||
hide: Ocultar
|
||||
ignore_flag: Ignorar
|
||||
ignored_flag: Ignorado
|
||||
moderate: Moderar
|
||||
filter: Filtrar
|
||||
filters:
|
||||
all: Todos
|
||||
pending_flag_review: Pendientes
|
||||
with_ignored_flag: Ignorados
|
||||
with_ignored_flag: Marcados como revisados
|
||||
order: Orden
|
||||
orders:
|
||||
created_at: Más nuevos
|
||||
flags: Más denunciados
|
||||
confirm: ¿Estás seguro?
|
||||
debates:
|
||||
index:
|
||||
hide_debates: Ocultar debates
|
||||
|
||||
@@ -145,8 +145,9 @@ Rails.application.routes.draw do
|
||||
resources :comments, only: :index do
|
||||
member do
|
||||
put :hide
|
||||
put :hide_in_moderation_screen
|
||||
put :ignore_flag
|
||||
end
|
||||
collection do
|
||||
put :moderate
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,18 +1,15 @@
|
||||
require 'rails_helper'
|
||||
|
||||
feature 'Moderate Comments' do
|
||||
feature 'Moderate comments' do
|
||||
|
||||
feature 'Hiding Comments' do
|
||||
|
||||
scenario 'Hide without children hides the comment completely', :js do
|
||||
scenario 'Hide', :js do
|
||||
citizen = create(:user)
|
||||
moderator = create(:moderator)
|
||||
|
||||
debate = create(:debate)
|
||||
comment = create(:comment, commentable: debate, body: 'SPAM')
|
||||
comment = create(:comment)
|
||||
|
||||
login_as(moderator.user)
|
||||
visit debate_path(debate)
|
||||
visit debate_path(comment.commentable)
|
||||
|
||||
within("#comment_#{comment.id}") do
|
||||
click_link 'Hide'
|
||||
@@ -20,86 +17,105 @@ feature 'Moderate Comments' do
|
||||
end
|
||||
|
||||
login_as(citizen)
|
||||
visit debate_path(debate)
|
||||
visit debate_path(comment.commentable)
|
||||
|
||||
expect(page).to have_css('.comment', count: 1)
|
||||
expect(page).to_not have_content('This comment has been deleted')
|
||||
expect(page).to_not have_content('SPAM')
|
||||
end
|
||||
|
||||
scenario 'Children visible', :js do
|
||||
citizen = create(:user)
|
||||
scenario 'Can not hide own comment' do
|
||||
moderator = create(:moderator)
|
||||
|
||||
debate = create(:debate)
|
||||
comment = create(:comment, commentable: debate, body: 'SPAM')
|
||||
create(:comment, commentable: debate, body: 'Acceptable reply', parent_id: comment.id)
|
||||
comment = create(:comment, user: moderator.user)
|
||||
|
||||
login_as(moderator.user)
|
||||
visit debate_path(debate)
|
||||
visit debate_path(comment.commentable)
|
||||
|
||||
within("#comment_#{comment.id}") do
|
||||
first(:link, "Hide").click
|
||||
expect(page).to have_css('.comment .faded')
|
||||
end
|
||||
|
||||
login_as(citizen)
|
||||
visit debate_path(debate)
|
||||
|
||||
expect(page).to have_css('.comment', count: 2)
|
||||
expect(page).to have_content('This comment has been deleted')
|
||||
expect(page).to_not have_content('SPAM')
|
||||
|
||||
expect(page).to have_content('Acceptable reply')
|
||||
expect(page).to_not have_link('Hide')
|
||||
expect(page).to_not have_link('Block author')
|
||||
end
|
||||
end
|
||||
|
||||
scenario 'Moderator actions in the comment' do
|
||||
citizen = create(:user)
|
||||
moderator = create(:moderator)
|
||||
|
||||
debate = create(:debate)
|
||||
comment = create(:comment, commentable: debate)
|
||||
|
||||
login_as(moderator.user)
|
||||
visit debate_path(debate)
|
||||
|
||||
within "#comment_#{comment.id}" do
|
||||
expect(page).to have_link("Hide")
|
||||
expect(page).to have_link("Ban author")
|
||||
end
|
||||
|
||||
login_as(citizen)
|
||||
visit debate_path(debate)
|
||||
|
||||
within "#comment_#{comment.id}" do
|
||||
expect(page).to_not have_link("Hide")
|
||||
expect(page).to_not have_link("Ban author")
|
||||
end
|
||||
end
|
||||
|
||||
scenario 'Moderator actions do not appear in own comments' do
|
||||
moderator = create(:moderator)
|
||||
|
||||
debate = create(:debate)
|
||||
comment = create(:comment, commentable: debate, user: moderator.user)
|
||||
|
||||
login_as(moderator.user)
|
||||
visit debate_path(debate)
|
||||
|
||||
within "#comment_#{comment.id}" do
|
||||
expect(page).to_not have_link("Hide")
|
||||
expect(page).to_not have_link("Ban author")
|
||||
end
|
||||
end
|
||||
|
||||
feature '/moderation/ menu' do
|
||||
feature '/moderation/ screen' do
|
||||
|
||||
background do
|
||||
moderator = create(:moderator)
|
||||
login_as(moderator.user)
|
||||
end
|
||||
|
||||
feature 'moderate in bulk' do
|
||||
feature "When a comment has been selected for moderation" do
|
||||
background do
|
||||
@comment = create(:comment)
|
||||
visit moderation_comments_path
|
||||
within('.sub-nav') do
|
||||
click_link "All"
|
||||
end
|
||||
|
||||
within("#comment_#{@comment.id}") do
|
||||
check "comment_#{@comment.id}_check"
|
||||
end
|
||||
|
||||
expect(page).to_not have_css("comment_#{@comment.id}")
|
||||
end
|
||||
|
||||
scenario 'Hide the comment' do
|
||||
click_on "Hide comments"
|
||||
expect(page).to_not have_css("comment_#{@comment.id}")
|
||||
expect(@comment.reload).to be_hidden
|
||||
expect(@comment.user).to_not be_hidden
|
||||
end
|
||||
|
||||
scenario 'Block the user' do
|
||||
click_on "Block authors"
|
||||
expect(page).to_not have_css("comment_#{@comment.id}")
|
||||
expect(@comment.reload).to be_hidden
|
||||
expect(@comment.user).to be_hidden
|
||||
end
|
||||
|
||||
scenario 'Ignore the comment' do
|
||||
click_on "Ignore flags"
|
||||
expect(page).to_not have_css("comment_#{@comment.id}")
|
||||
expect(@comment.reload).to be_ignored_flag
|
||||
expect(@comment.reload).to_not be_hidden
|
||||
expect(@comment.user).to_not be_hidden
|
||||
end
|
||||
end
|
||||
|
||||
scenario "select all/none", :js do
|
||||
create_list(:comment, 2)
|
||||
|
||||
visit moderation_comments_path
|
||||
|
||||
within('.js-check') { click_on 'All' }
|
||||
|
||||
all('input[type=checkbox]').each do |checkbox|
|
||||
expect(checkbox).to be_checked
|
||||
end
|
||||
|
||||
within('.js-check') { click_on 'None' }
|
||||
|
||||
all('input[type=checkbox]').each do |checkbox|
|
||||
expect(checkbox).to_not be_checked
|
||||
end
|
||||
end
|
||||
|
||||
scenario "remembering page, filter and order" do
|
||||
create_list(:comment, 52)
|
||||
|
||||
visit moderation_comments_path(filter: 'all', page: '2', order: 'created_at')
|
||||
|
||||
click_on "Ignore flags"
|
||||
|
||||
expect(page).to have_selector('.js-order-selector[data-order="created_at"]')
|
||||
|
||||
expect(current_url).to include('filter=all')
|
||||
expect(current_url).to include('page=2')
|
||||
expect(current_url).to include('order=created_at')
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Current filter is properly highlighted" do
|
||||
visit moderation_comments_path
|
||||
expect(page).to_not have_link('Pending')
|
||||
@@ -107,98 +123,74 @@ feature 'Moderate Comments' do
|
||||
expect(page).to have_link('Ignored')
|
||||
|
||||
visit moderation_comments_path(filter: 'all')
|
||||
within('.sub-nav') do
|
||||
expect(page).to_not have_link('All')
|
||||
expect(page).to have_link('Pending')
|
||||
expect(page).to have_link('Ignored')
|
||||
end
|
||||
|
||||
visit moderation_comments_path(filter: 'pending_flag_review')
|
||||
within('.sub-nav') do
|
||||
expect(page).to have_link('All')
|
||||
expect(page).to_not have_link('Pending')
|
||||
expect(page).to have_link('Ignored')
|
||||
end
|
||||
|
||||
visit moderation_comments_path(filter: 'with_ignored_flag')
|
||||
within('.sub-nav') do
|
||||
expect(page).to have_link('All')
|
||||
expect(page).to have_link('Pending')
|
||||
expect(page).to_not have_link('Ignored')
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Filtering comments" do
|
||||
create(:comment, body: "Regular comment")
|
||||
create(:comment, :flagged, body: "Pending comment")
|
||||
create(:comment, :flagged, :hidden, body: "Hidden comment")
|
||||
create(:comment, :hidden, body: "Hidden comment")
|
||||
create(:comment, :flagged, :with_ignored_flag, body: "Ignored comment")
|
||||
|
||||
visit moderation_comments_path(filter: 'all')
|
||||
expect(page).to have_content('Regular comment')
|
||||
expect(page).to have_content('Pending comment')
|
||||
expect(page).to_not have_content('Hidden comment')
|
||||
expect(page).to have_content('Ignored comment')
|
||||
|
||||
visit moderation_comments_path(filter: 'pending_flag_review')
|
||||
expect(page).to_not have_content('Regular comment')
|
||||
expect(page).to have_content('Pending comment')
|
||||
expect(page).to_not have_content('Hidden comment')
|
||||
expect(page).to_not have_content('Ignored comment')
|
||||
|
||||
visit moderation_comments_path(filter: 'with_ignored_flag')
|
||||
expect(page).to_not have_content('Regular comment')
|
||||
expect(page).to_not have_content('Pending comment')
|
||||
expect(page).to_not have_content('Hidden comment')
|
||||
expect(page).to have_content('Ignored comment')
|
||||
end
|
||||
|
||||
scenario "Reviewing links remember the pagination setting and the filter" do
|
||||
per_page = Kaminari.config.default_per_page
|
||||
(per_page + 2).times { create(:comment, :flagged) }
|
||||
scenario "sorting comments" do
|
||||
create(:comment, body: "Flagged comment", created_at: Time.now - 1.day, flags_count: 5)
|
||||
create(:comment, body: "Flagged newer comment", created_at: Time.now - 12.hours, flags_count: 3)
|
||||
create(:comment, body: "Newer comment", created_at: Time.now)
|
||||
|
||||
visit moderation_comments_path(filter: 'pending_flag_review', page: 2)
|
||||
visit moderation_comments_path(order: 'created_at')
|
||||
|
||||
click_link('Ignore', match: :first, exact: true)
|
||||
expect("Flagged newer comment").to appear_before("Flagged comment")
|
||||
|
||||
expect(current_url).to include('filter=pending_flag_review')
|
||||
expect(current_url).to include('page=2')
|
||||
end
|
||||
visit moderation_comments_path(order: 'flags')
|
||||
|
||||
feature 'A flagged comment exists' do
|
||||
expect("Flagged comment").to appear_before("Flagged newer comment")
|
||||
|
||||
background do
|
||||
debate = create(:debate, title: 'Democracy')
|
||||
@comment = create(:comment, :flagged, commentable: debate, body: 'spammy spam')
|
||||
visit moderation_comments_path
|
||||
end
|
||||
visit moderation_comments_path(filter: 'all', order: 'created_at')
|
||||
|
||||
scenario 'It is displayed with the correct attributes' do
|
||||
within("#comment_#{@comment.id}") do
|
||||
expect(page).to have_link('Democracy')
|
||||
expect(page).to have_content('spammy spam')
|
||||
expect(page).to have_content('1')
|
||||
expect(page).to have_link('Hide')
|
||||
expect(page).to have_link('Ignore')
|
||||
end
|
||||
end
|
||||
expect("Newer comment").to appear_before("Flagged newer comment")
|
||||
expect("Flagged newer comment").to appear_before("Flagged comment")
|
||||
|
||||
scenario 'Hiding the comment' do
|
||||
within("#comment_#{@comment.id}") do
|
||||
click_link('Hide')
|
||||
end
|
||||
visit moderation_comments_path(filter: 'all', order: 'flags')
|
||||
|
||||
expect(current_path).to eq(moderation_comments_path)
|
||||
expect(page).to_not have_selector("#comment_#{@comment.id}")
|
||||
|
||||
expect(@comment.reload).to be_hidden
|
||||
end
|
||||
|
||||
scenario 'Marking the comment as ignored' do
|
||||
within("#comment_#{@comment.id}") do
|
||||
click_link('Ignore')
|
||||
end
|
||||
|
||||
expect(current_path).to eq(moderation_comments_path)
|
||||
|
||||
click_link('Ignored')
|
||||
|
||||
within("#comment_#{@comment.id}") do
|
||||
expect(page).to have_content('Ignored')
|
||||
end
|
||||
|
||||
expect(@comment.reload).to be_ignored_flag
|
||||
end
|
||||
expect("Flagged comment").to appear_before("Flagged newer comment")
|
||||
expect("Flagged newer comment").to appear_before("Newer comment")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -173,6 +173,9 @@ describe Ability do
|
||||
it { should_not be_able_to(:hide, hidden_comment) }
|
||||
it { should_not be_able_to(:hide, own_comment) }
|
||||
|
||||
it { should be_able_to(:moderate, comment) }
|
||||
it { should_not be_able_to(:moderate, own_comment) }
|
||||
|
||||
it { should be_able_to(:hide, debate) }
|
||||
it { should be_able_to(:hide_in_moderation_screen, debate) }
|
||||
it { should_not be_able_to(:hide, hidden_debate) }
|
||||
@@ -193,6 +196,9 @@ describe Ability do
|
||||
it { should_not be_able_to(:ignore_flag, ignored_debate) }
|
||||
it { should_not be_able_to(:ignore_flag, own_debate) }
|
||||
|
||||
it { should be_able_to(:moderate, debate) }
|
||||
it { should_not be_able_to(:moderate, own_debate) }
|
||||
|
||||
it { should be_able_to(:ignore_flag, proposal) }
|
||||
it { should_not be_able_to(:ignore_flag, hidden_proposal) }
|
||||
it { should_not be_able_to(:ignore_flag, ignored_proposal) }
|
||||
|
||||
Reference in New Issue
Block a user