From 36fb9b60b26909b9f3cba05c8d8e77b1b7f9ecc2 Mon Sep 17 00:00:00 2001 From: kikito Date: Mon, 24 Aug 2015 18:35:59 +0200 Subject: [PATCH 1/4] Use a js-class instead of an id for moderator-comment-actions --- app/assets/javascripts/moderator_comment.js.coffee | 2 +- app/views/comments/_actions.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/moderator_comment.js.coffee b/app/assets/javascripts/moderator_comment.js.coffee index 7cc680169..fcc6e92c1 100644 --- a/app/assets/javascripts/moderator_comment.js.coffee +++ b/app/assets/javascripts/moderator_comment.js.coffee @@ -4,4 +4,4 @@ App.ModeratorComments = $("##{id} .comment-body:first").addClass("faded") hide_moderator_actions: (id) -> - $("##{id} #moderator-comment-actions:first").hide() \ No newline at end of file + $("##{id} .js-moderator-comment-actions").hide() diff --git a/app/views/comments/_actions.html.erb b/app/views/comments/_actions.html.erb index 8cc1b114f..27574e2fc 100644 --- a/app/views/comments/_actions.html.erb +++ b/app/views/comments/_actions.html.erb @@ -1,8 +1,8 @@ -  |  <%= link_to t("admin.actions.hide").capitalize, hide_moderation_comment_path(comment), method: :put, remote: true, data: { confirm: t('admin.actions.confirm') } %> <% unless comment.user.hidden? %> +  |  <%= link_to t("admin.actions.hide_author").capitalize, hide_moderation_user_path(comment.user_id, debate_id: @debate.id), method: :put, data: { confirm: t('admin.actions.confirm') } %> From c6976b090500e4cdf30050985f49280b885780ea Mon Sep 17 00:00:00 2001 From: kikito Date: Mon, 24 Aug 2015 18:36:56 +0200 Subject: [PATCH 2/4] Adds test for not using moderation links in my own comments --- app/views/comments/_actions.html.erb | 13 ++++++----- app/views/comments/_comment.html.erb | 4 +--- spec/features/moderation/comments_spec.rb | 27 ++++++++++++++++++++--- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/app/views/comments/_actions.html.erb b/app/views/comments/_actions.html.erb index 27574e2fc..5454179f0 100644 --- a/app/views/comments/_actions.html.erb +++ b/app/views/comments/_actions.html.erb @@ -1,10 +1,13 @@ -  |  - <%= link_to t("admin.actions.hide").capitalize, hide_moderation_comment_path(comment), - method: :put, remote: true, data: { confirm: t('admin.actions.confirm') } %> - <% unless comment.user.hidden? %> + <% if can? :hide, comment %> +  |  + <%= link_to t("admin.actions.hide").capitalize, hide_moderation_comment_path(comment), + method: :put, remote: true, data: { confirm: t('admin.actions.confirm') } %> + <% end %> + + <% if can? :hide, comment.user %>  |  <%= link_to t("admin.actions.hide_author").capitalize, hide_moderation_user_path(comment.user_id, debate_id: @debate.id), method: :put, data: { confirm: t('admin.actions.confirm') } %> <% end %> - \ No newline at end of file + diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb index 0d922be04..75cc9e6dd 100644 --- a/app/views/comments/_comment.html.erb +++ b/app/views/comments/_comment.html.erb @@ -69,9 +69,7 @@ <%= link_to(comment_link_text(comment), "", class: "js-add-comment-link", data: {'id': dom_id(comment)}) %> - <% if moderator? %> - <%= render 'comments/actions', comment: comment %> - <% end %> + <%= render 'comments/actions', comment: comment %> <%= render 'comments/form', {parent: comment, toggeable: true} %> <% end %> diff --git a/spec/features/moderation/comments_spec.rb b/spec/features/moderation/comments_spec.rb index e52a87c17..5a4100f77 100644 --- a/spec/features/moderation/comments_spec.rb +++ b/spec/features/moderation/comments_spec.rb @@ -59,17 +59,38 @@ feature 'Moderate Comments' do moderator = create(:moderator) debate = create(:debate) - create(:comment, commentable: debate) + comment = create(:comment, commentable: debate) login_as(moderator.user) visit debate_path(debate) - expect(page).to have_css("#moderator-comment-actions") + 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) - expect(page).to_not have_css("#moderator-comment-actions") + 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 From e68ee3ffae0ac2fc5bb2c93e0da280895f90e405 Mon Sep 17 00:00:00 2001 From: kikito Date: Mon, 24 Aug 2015 18:45:22 +0200 Subject: [PATCH 3/4] Replaces id by js-class in moderator-debate-actions --- app/assets/javascripts/moderator_debates.js.coffee | 2 +- app/views/debates/show.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/moderator_debates.js.coffee b/app/assets/javascripts/moderator_debates.js.coffee index 802504ec2..7cb25eb51 100644 --- a/app/assets/javascripts/moderator_debates.js.coffee +++ b/app/assets/javascripts/moderator_debates.js.coffee @@ -5,4 +5,4 @@ App.ModeratorDebates = $("#comments").addClass("faded") hide_moderator_actions: (id) -> - $("##{id} #moderator-debate-actions:first").hide() \ No newline at end of file + $("##{id} .js-moderator-debate-actions:first").hide() diff --git a/app/views/debates/show.html.erb b/app/views/debates/show.html.erb index 2c69e79f7..47ff9e34f 100644 --- a/app/views/debates/show.html.erb +++ b/app/views/debates/show.html.erb @@ -52,7 +52,7 @@ <%= render 'shared/tags', debate: @debate %> <% if moderator? %> -
+
<%= render 'actions', debate: @debate %>
<% end %> From be6a5f4f1d578771e4f787e5debd10976784a4c7 Mon Sep 17 00:00:00 2001 From: kikito Date: Mon, 24 Aug 2015 18:45:47 +0200 Subject: [PATCH 4/4] Adds test for not showing moderator actions in own debate --- app/views/debates/_actions.html.erb | 8 +++++--- spec/features/moderation/debates_spec.rb | 13 +++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/app/views/debates/_actions.html.erb b/app/views/debates/_actions.html.erb index 5a51749dc..db9821ad0 100644 --- a/app/views/debates/_actions.html.erb +++ b/app/views/debates/_actions.html.erb @@ -1,7 +1,9 @@ -<%= link_to t("admin.actions.hide").capitalize, hide_moderation_debate_path(debate), - method: :put, remote: true, data: { confirm: t('admin.actions.confirm') } %> +<% if can? :hide, debate %> + <%= link_to t("admin.actions.hide").capitalize, hide_moderation_debate_path(debate), + method: :put, remote: true, data: { confirm: t('admin.actions.confirm') } %> +<% end %> -<% unless debate.author.hidden? %> +<% if can? :hide, debate.author %>  |  <%= link_to t("admin.actions.hide_author").capitalize, hide_moderation_user_path(debate.author_id), method: :put, data: { confirm: t('admin.actions.confirm') } %> diff --git a/spec/features/moderation/debates_spec.rb b/spec/features/moderation/debates_spec.rb index bb2b58c24..1ea3101e0 100644 --- a/spec/features/moderation/debates_spec.rb +++ b/spec/features/moderation/debates_spec.rb @@ -23,6 +23,19 @@ feature 'Moderate debates' do expect(page).to have_css('.debate', count: 0) end + scenario 'Can not hide own debate' do + moderator = create(:moderator) + debate = create(:debate, author: moderator.user) + + login_as(moderator.user) + visit debate_path(debate) + + within("#debate_#{debate.id}") do + expect(page).to_not have_link('Hide') + expect(page).to_not have_link('Block author') + end + end + feature '/moderation/ menu' do background do