Adds first version of comment moderation

Missing:
* Ensure removing a flag updates the flagged_at attribute correctly
* Showing the debate when the comment is not a “root”
* Filter (pending / reviewed / all)
* Order
* Same for debates
This commit is contained in:
kikito
2015-08-21 22:01:47 +02:00
parent b7718a2e5d
commit 00b51bbc23
3 changed files with 153 additions and 41 deletions

View File

@@ -1,8 +1,31 @@
class Moderation::CommentsController < Moderation::BaseController
before_filter :load_comments, only: :index
load_and_authorize_resource
def index
@comments = @comments.page(params[:page])
end
def hide
@comment = Comment.find(params[:id])
@comment.hide
end
end
def hide_in_moderation_screen
@comment.hide
redirect_to action: :index
end
def mark_as_reviewed
@comment.mark_as_reviewed
redirect_to action: :index
end
private
def load_comments
@comments = Comment.accessible_by(current_ability, :hide).where('inappropiate_flags_count > 0').includes(:commentable)
end
end

View File

@@ -0,0 +1,36 @@
<h2><%= t('moderation.comments.index.title') %></h2>
<h3><%= page_entries_info @comments %></h3>
<table>
<tr>
<th><%= t('moderation.comments.index.flags') %></th>
<th><%= t('moderation.comments.index.debate') %></th>
<th><%= t('moderation.comments.index.comment') %></th>
<th><%= t('moderation.comments.index.updated_at') %></th>
</tr>
<% @comments.each do |comment| %>
<tr id="comment_<%= comment.id %>">
<td><%= comment.inappropiate_flags_count %></td>
<td><%= link_to(comment.debate.title, comment.debate) %></td>
<td><%= comment.body %></td>
<td><%= l comment.updated_at.to_date %></td>
<td>
<%= link_to t('moderation.comments.index.hide'), hide_in_moderation_screen_moderation_comment_path(comment), method: :put %>
</td>
<% if can? :mark_as_reviewed, comment %>
<td>
<%= link_to t('moderation.comments.index.mark_as_reviewed'), mark_as_reviewed_moderation_comment_path(comment), method: :put %>
</td>
<% end %>
<% if comment.reviewed? %>
<td>
<%= t('moderation.comments.index.reviewed') %>
</td>
<% end %>
</tr>
<% end %>
</table>
<%= paginate @comments %>

View File

@@ -2,61 +2,64 @@ require 'rails_helper'
feature 'Moderate Comments' do
scenario 'Hide', :js do
citizen = create(:user)
moderator = create(:moderator)
feature 'Hiding Comments' do
debate = create(:debate)
comment = create(:comment, commentable: debate, body: 'SPAM')
scenario 'Hide', :js do
citizen = create(:user)
moderator = create(:moderator)
login_as(moderator.user)
visit debate_path(debate)
debate = create(:debate)
comment = create(:comment, commentable: debate, body: 'SPAM')
within("#comment_#{comment.id}") do
click_link 'Hide'
expect(page).to have_css('.comment .faded')
login_as(moderator.user)
visit debate_path(debate)
within("#comment_#{comment.id}") do
click_link 'Hide'
expect(page).to have_css('.comment .faded')
end
login_as(citizen)
visit debate_path(debate)
expect(page).to have_css('.comment', count: 1)
expect(page).to have_content('This comment has been deleted')
expect(page).to_not have_content('SPAM')
end
login_as(citizen)
visit debate_path(debate)
scenario 'Children visible', :js do
citizen = create(:user)
moderator = create(:moderator)
expect(page).to have_css('.comment', count: 1)
expect(page).to have_content('This comment has been deleted')
expect(page).to_not have_content('SPAM')
end
debate = create(:debate)
comment = create(:comment, commentable: debate, body: 'SPAM')
create(:comment, commentable: debate, body: 'Acceptable reply', parent_id: comment.id)
scenario 'Children visible', :js do
citizen = create(:user)
moderator = create(:moderator)
login_as(moderator.user)
visit debate_path(debate)
debate = create(:debate)
comment = create(:comment, commentable: debate, body: 'SPAM')
reply = create(:comment, commentable: debate, body: 'Acceptable reply', parent_id: comment.id)
within("#comment_#{comment.id}") do
first(:link, "Hide").click
expect(page).to have_css('.comment .faded')
end
login_as(moderator.user)
visit debate_path(debate)
login_as(citizen)
visit debate_path(debate)
within("#comment_#{comment.id}") do
first(:link, "Hide").click
expect(page).to have_css('.comment .faded')
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')
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')
end
scenario 'Moderator actions' do
scenario 'Moderator actions in the comment' do
citizen = create(:user)
moderator = create(:moderator)
debate = create(:debate)
comment = create(:comment, commentable: debate)
create(:comment, commentable: debate)
login_as(moderator.user)
visit debate_path(debate)
@@ -69,4 +72,54 @@ feature 'Moderate Comments' do
expect(page).to_not have_css("#moderator-comment-actions")
end
end
feature '/moderation/ menu' do
background do
moderator = create(:moderator)
login_as(moderator.user)
user = create(:user)
debate = create(:debate, title: 'Democracy')
@comment = create(:comment, commentable: debate, body: 'spammy spam')
InappropiateFlag.flag!(user, @comment)
visit moderation_comments_path
end
scenario 'Flagged comment shows the right params' 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_content('Mark as reviewed')
end
end
scenario 'Hiding a comment' do
within("#comment_#{@comment.id}") do
click_link('Hide')
end
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 a comment as reviewed' do
within("#comment_#{@comment.id}") do
click_link('Mark as reviewed')
end
expect(current_path).to eq(moderation_comments_path)
within("#comment_#{@comment.id}") do
expect(page).to have_content('Reviewed')
end
expect(@comment.reload).to be_reviewed
end
end
end