implements /moderation/debates
This commit is contained in:
@@ -26,17 +26,17 @@ class Moderation::CommentsController < Moderation::BaseController
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def load_comments
|
def load_comments
|
||||||
@comments = Comment.accessible_by(current_ability, :hide).flagged_as_inappropiate.sorted_for_moderation.includes(:commentable)
|
@comments = Comment.accessible_by(current_ability, :hide).flagged_as_inappropiate.sorted_for_moderation.includes(:commentable)
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_valid_filters
|
def set_valid_filters
|
||||||
@valid_filters = %w{all pending_review reviewed}
|
@valid_filters = %w{all pending_review reviewed}
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_filter
|
def parse_filter
|
||||||
@filter = params[:filter]
|
@filter = params[:filter]
|
||||||
@filter = 'all' unless @valid_filters.include?(@filter)
|
@filter = 'all' unless @valid_filters.include?(@filter)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,8 +1,42 @@
|
|||||||
class Moderation::DebatesController < Moderation::BaseController
|
class Moderation::DebatesController < Moderation::BaseController
|
||||||
|
before_filter :set_valid_filters, only: :index
|
||||||
|
before_filter :parse_filter, only: :index
|
||||||
|
before_filter :load_debates, only: :index
|
||||||
|
|
||||||
|
load_and_authorize_resource
|
||||||
|
|
||||||
|
def index
|
||||||
|
@debates = @debates.send(@filter)
|
||||||
|
@debates = @debates.page(params[:page])
|
||||||
|
end
|
||||||
|
|
||||||
def hide
|
def hide
|
||||||
@debate = Debate.find(params[:id])
|
|
||||||
@debate.hide
|
@debate.hide
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def hide_in_moderation_screen
|
||||||
|
@debate.hide
|
||||||
|
redirect_to request.query_parameters.merge(action: :index)
|
||||||
|
end
|
||||||
|
|
||||||
|
def mark_as_reviewed
|
||||||
|
@debate.mark_as_reviewed
|
||||||
|
redirect_to request.query_parameters.merge(action: :index)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def load_debates
|
||||||
|
@debates = Debate.accessible_by(current_ability, :hide).flagged_as_inappropiate.sorted_for_moderation
|
||||||
|
end
|
||||||
|
|
||||||
|
def set_valid_filters
|
||||||
|
@valid_filters = %w{all pending_review reviewed}
|
||||||
|
end
|
||||||
|
|
||||||
|
def parse_filter
|
||||||
|
@filter = params[:filter]
|
||||||
|
@filter = 'all' unless @valid_filters.include?(@filter)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@@ -23,6 +23,11 @@ class Debate < ActiveRecord::Base
|
|||||||
before_validation :sanitize_description
|
before_validation :sanitize_description
|
||||||
before_validation :sanitize_tag_list
|
before_validation :sanitize_tag_list
|
||||||
|
|
||||||
|
scope :sorted_for_moderation, -> { order(inappropiate_flags_count: :desc, updated_at: :desc) }
|
||||||
|
scope :pending_review, -> { where(reviewed_at: nil, hidden_at: nil) }
|
||||||
|
scope :reviewed, -> { where("reviewed_at IS NOT NULL AND hidden_at IS NULL") }
|
||||||
|
scope :flagged_as_inappropiate, -> { where("inappropiate_flags_count > 0") }
|
||||||
|
|
||||||
# Ahoy setup
|
# Ahoy setup
|
||||||
visitable # Ahoy will automatically assign visit_id on create
|
visitable # Ahoy will automatically assign visit_id on create
|
||||||
|
|
||||||
|
|||||||
@@ -16,11 +16,11 @@
|
|||||||
|
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<th><%= t('moderation.comments.index.flags') %></th>
|
<th><%= t('moderation.comments.index.headers.flags') %></th>
|
||||||
<th><%= t('moderation.comments.index.updated_at') %></th>
|
<th><%= t('moderation.comments.index.headers.updated_at') %></th>
|
||||||
<th><%= t('moderation.comments.index.commentable_type') %></th>
|
<th><%= t('moderation.comments.index.headers.commentable_type') %></th>
|
||||||
<th><%= t('moderation.comments.index.commentable') %></th>
|
<th><%= t('moderation.comments.index.headers.commentable') %></th>
|
||||||
<th><%= t('moderation.comments.index.comment') %></th>
|
<th><%= t('moderation.comments.index.headers.comment') %></th>
|
||||||
</tr>
|
</tr>
|
||||||
<% @comments.each do |comment| %>
|
<% @comments.each do |comment| %>
|
||||||
<tr id="comment_<%= comment.id %>">
|
<tr id="comment_<%= comment.id %>">
|
||||||
|
|||||||
48
app/views/moderation/debates/index.html.erb
Normal file
48
app/views/moderation/debates/index.html.erb
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
<h2><%= t('moderation.debates.index.title') %></h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<%= t('moderation.debates.index.filter') %>:
|
||||||
|
<% @valid_filters.each do |filter| %>
|
||||||
|
<% if @filter == filter %>
|
||||||
|
<%= t("moderation.debates.index.filters.#{filter}") %>
|
||||||
|
<% else %>
|
||||||
|
<%= link_to t("moderation.debates.index.filters.#{filter}"),
|
||||||
|
moderation_debates_path(filter: filter) %>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h3><%= page_entries_info @debates %></h3>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<th><%= t('moderation.debates.index.headers.flags') %></th>
|
||||||
|
<th><%= t('moderation.debates.index.headers.updated_at') %></th>
|
||||||
|
<th><%= t('moderation.debates.index.headers.title') %></th>
|
||||||
|
<th><%= t('moderation.debates.index.headers.description') %></th>
|
||||||
|
</tr>
|
||||||
|
<% @debates.each do |debate| %>
|
||||||
|
<tr id="debate_<%= debate.id %>">
|
||||||
|
<td><%= debate.inappropiate_flags_count %></td>
|
||||||
|
<td><%= l debate.updated_at.to_date %></td>
|
||||||
|
<td><%= link_to debate.title, debate %></td>
|
||||||
|
<td><%= debate.description %></td>
|
||||||
|
<td>
|
||||||
|
<%= link_to t('moderation.debates.index.hide'), hide_in_moderation_screen_moderation_debate_path(debate, request.query_parameters), method: :put %>
|
||||||
|
</td>
|
||||||
|
<% if can? :mark_as_reviewed, debate %>
|
||||||
|
<td>
|
||||||
|
<%= link_to t('moderation.debates.index.mark_as_reviewed'), mark_as_reviewed_moderation_debate_path(debate, request.query_parameters), method: :put %>
|
||||||
|
</td>
|
||||||
|
<% end %>
|
||||||
|
<% if debate.reviewed? %>
|
||||||
|
<td>
|
||||||
|
<%= t('moderation.debates.index.reviewed') %>
|
||||||
|
</td>
|
||||||
|
<% end %>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<%= paginate @debates %>
|
||||||
|
|
||||||
@@ -6,11 +6,28 @@ en:
|
|||||||
comments:
|
comments:
|
||||||
index:
|
index:
|
||||||
title: Comments flagged as inappropiate
|
title: Comments flagged as inappropiate
|
||||||
commentable_type: Type
|
headers:
|
||||||
commentable: Root
|
flags: Flags
|
||||||
comment: Comment
|
updated_at: Date
|
||||||
updated_at: Date
|
commentable_type: Type
|
||||||
flags: Flags
|
commentable: Root
|
||||||
|
comment: Comment
|
||||||
|
hide: Hide
|
||||||
|
mark_as_reviewed: Mark as reviewed
|
||||||
|
reviewed: Reviewed
|
||||||
|
filter: Filter
|
||||||
|
filters:
|
||||||
|
all: All
|
||||||
|
pending_review: Pending
|
||||||
|
reviewed: Reviewed
|
||||||
|
debates:
|
||||||
|
index:
|
||||||
|
title: Debates flagged as inappropiate
|
||||||
|
headers:
|
||||||
|
flags: Flags
|
||||||
|
updated_at: Date
|
||||||
|
title: Title
|
||||||
|
description: Description
|
||||||
hide: Hide
|
hide: Hide
|
||||||
mark_as_reviewed: Mark as reviewed
|
mark_as_reviewed: Mark as reviewed
|
||||||
reviewed: Reviewed
|
reviewed: Reviewed
|
||||||
|
|||||||
@@ -6,11 +6,28 @@ es:
|
|||||||
comments:
|
comments:
|
||||||
index:
|
index:
|
||||||
title: Comentarios Denunciados como Inapropiados
|
title: Comentarios Denunciados como Inapropiados
|
||||||
commentable_type: Tipo
|
headers:
|
||||||
commentable: Raíz
|
flags: Denuncias
|
||||||
comment: Comentario
|
updated_at: Fecha
|
||||||
updated_at: Fecha
|
commentable_type: Tipo
|
||||||
flags: Denuncias
|
commentable: Raíz
|
||||||
|
comment: Comentario
|
||||||
|
hide: Ocultar
|
||||||
|
mark_as_reviewed: Marcar como revisado
|
||||||
|
reviewed: Revisado
|
||||||
|
filter: Filtrar
|
||||||
|
filters:
|
||||||
|
all: Todos
|
||||||
|
pending_review: Pendientes
|
||||||
|
reviewed: Revisados
|
||||||
|
debates:
|
||||||
|
index:
|
||||||
|
title: Debates Denunciados como Inapropiados
|
||||||
|
headers:
|
||||||
|
flags: Denuncias
|
||||||
|
updated_at: Fecha
|
||||||
|
title: Title
|
||||||
|
description: Descripción
|
||||||
hide: Ocultar
|
hide: Ocultar
|
||||||
mark_as_reviewed: Marcar como revisado
|
mark_as_reviewed: Marcar como revisado
|
||||||
reviewed: Revisado
|
reviewed: Revisado
|
||||||
|
|||||||
@@ -23,4 +23,113 @@ feature 'Moderate debates' do
|
|||||||
expect(page).to have_css('.debate', count: 0)
|
expect(page).to have_css('.debate', count: 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
feature '/moderation/ menu' do
|
||||||
|
|
||||||
|
background do
|
||||||
|
moderator = create(:moderator)
|
||||||
|
login_as(moderator.user)
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Current filter is properly highlighted" do
|
||||||
|
visit moderation_debates_path
|
||||||
|
expect(page).to_not have_link('All')
|
||||||
|
expect(page).to have_link('Pending')
|
||||||
|
expect(page).to have_link('Reviewed')
|
||||||
|
|
||||||
|
visit moderation_debates_path(filter: 'all')
|
||||||
|
expect(page).to_not have_link('All')
|
||||||
|
expect(page).to have_link('Pending')
|
||||||
|
expect(page).to have_link('Reviewed')
|
||||||
|
|
||||||
|
visit moderation_debates_path(filter: 'pending_review')
|
||||||
|
expect(page).to have_link('All')
|
||||||
|
expect(page).to_not have_link('Pending')
|
||||||
|
expect(page).to have_link('Reviewed')
|
||||||
|
|
||||||
|
visit moderation_debates_path(filter: 'reviewed')
|
||||||
|
expect(page).to have_link('All')
|
||||||
|
expect(page).to have_link('Pending')
|
||||||
|
expect(page).to_not have_link('Reviewed')
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Filtering debates" do
|
||||||
|
create(:debate, :flagged_as_inappropiate, title: "Pending debate")
|
||||||
|
create(:debate, :flagged_as_inappropiate, :hidden, title: "Hidden debate")
|
||||||
|
create(:debate, :flagged_as_inappropiate, :reviewed, title: "Reviewed debate")
|
||||||
|
|
||||||
|
visit moderation_debates_path(filter: 'all')
|
||||||
|
expect(page).to have_content('Pending debate')
|
||||||
|
expect(page).to_not have_content('Hidden debate')
|
||||||
|
expect(page).to have_content('Reviewed debate')
|
||||||
|
|
||||||
|
visit moderation_debates_path(filter: 'pending_review')
|
||||||
|
expect(page).to have_content('Pending debate')
|
||||||
|
expect(page).to_not have_content('Hidden debate')
|
||||||
|
expect(page).to_not have_content('Reviewed debate')
|
||||||
|
|
||||||
|
visit moderation_debates_path(filter: 'reviewed')
|
||||||
|
expect(page).to_not have_content('Pending debate')
|
||||||
|
expect(page).to_not have_content('Hidden debate')
|
||||||
|
expect(page).to have_content('Reviewed debate')
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Reviewing links remember the pagination setting and the filter" do
|
||||||
|
per_page = Kaminari.config.default_per_page
|
||||||
|
(per_page + 2).times { create(:debate, :flagged_as_inappropiate) }
|
||||||
|
|
||||||
|
visit moderation_debates_path(filter: 'pending_review', page: 2)
|
||||||
|
|
||||||
|
click_link('Mark as reviewed', match: :first)
|
||||||
|
|
||||||
|
uri = URI.parse(current_url)
|
||||||
|
query_params = Rack::Utils.parse_nested_query(uri.query).symbolize_keys
|
||||||
|
|
||||||
|
expect(query_params[:filter]).to eq('pending_review')
|
||||||
|
expect(query_params[:page]).to eq('2')
|
||||||
|
end
|
||||||
|
|
||||||
|
feature 'A flagged debate exists' do
|
||||||
|
|
||||||
|
background do
|
||||||
|
@debate = create(:debate, :flagged_as_inappropiate, title: 'spammy spam', description: 'buy buy buy')
|
||||||
|
visit moderation_debates_path
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'It is displayed with the correct attributes' do
|
||||||
|
within("#debate_#{@debate.id}") do
|
||||||
|
expect(page).to have_link('spammy spam')
|
||||||
|
expect(page).to have_content('buy buy buy')
|
||||||
|
expect(page).to have_content('1')
|
||||||
|
expect(page).to have_link('Hide')
|
||||||
|
expect(page).to have_link('Mark as reviewed')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'Hiding the debate' do
|
||||||
|
within("#debate_#{@debate.id}") do
|
||||||
|
click_link('Hide')
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(current_path).to eq(moderation_debates_path)
|
||||||
|
expect(page).to_not have_selector("#debate_#{@debate.id}")
|
||||||
|
|
||||||
|
expect(@debate.reload).to be_hidden
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'Marking the debate as reviewed' do
|
||||||
|
within("#debate_#{@debate.id}") do
|
||||||
|
click_link('Mark as reviewed')
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(current_path).to eq(moderation_debates_path)
|
||||||
|
|
||||||
|
within("#debate_#{@debate.id}") do
|
||||||
|
expect(page).to have_content('Reviewed')
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(@debate.reload).to be_reviewed
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
Reference in New Issue
Block a user