From 0279c0879230bfba6a1601a1cbd7d7d6db35277e Mon Sep 17 00:00:00 2001 From: kikito Date: Mon, 24 Aug 2015 17:23:50 +0200 Subject: [PATCH 1/6] fixes typo --- config/locales/es.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/locales/es.yml b/config/locales/es.yml index ef903082f..2d6b7d987 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -143,4 +143,4 @@ es: manage: all: "No tienes permiso para realizar la acción '%{action}' sobre %{subject}." welcome: - last_debates: Úlitmos debates + last_debates: Últimos debates From 36fb9b60b26909b9f3cba05c8d8e77b1b7f9ecc2 Mon Sep 17 00:00:00 2001 From: kikito Date: Mon, 24 Aug 2015 18:35:59 +0200 Subject: [PATCH 2/6] 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 3/6] 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 4/6] 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 5/6] 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 From 7edb45b0d7b3ff021821c242fd9af721c80739da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Mon, 24 Aug 2015 18:51:28 +0200 Subject: [PATCH 6/6] configures the null cache store in all environments This commit allows us to use caching and Rails.cache. Temporarily we configure the null store in all environments, but those will probably be memcached in the future. References #235 --- config/environments/development.rb | 2 ++ config/environments/production.rb | 2 +- config/environments/staging.rb | 2 +- config/environments/test.rb | 2 ++ spec/features/comments_spec.rb | 2 +- 5 files changed, 7 insertions(+), 3 deletions(-) diff --git a/config/environments/development.rb b/config/environments/development.rb index 63168eb28..acf67286d 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -42,4 +42,6 @@ Rails.application.configure do # Raises error for missing translations # config.action_view.raise_on_missing_translations = true + + config.cache_store = :null_store end diff --git a/config/environments/production.rb b/config/environments/production.rb index 76ec52249..e84606f73 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -55,7 +55,7 @@ Rails.application.configure do # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) # Use a different cache store in production. - # config.cache_store = :mem_cache_store + config.cache_store = :null_store # Enable serving of images, stylesheets, and JavaScripts from an asset server. # config.action_controller.asset_host = 'http://assets.example.com' diff --git a/config/environments/staging.rb b/config/environments/staging.rb index 76ec52249..e84606f73 100644 --- a/config/environments/staging.rb +++ b/config/environments/staging.rb @@ -55,7 +55,7 @@ Rails.application.configure do # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) # Use a different cache store in production. - # config.cache_store = :mem_cache_store + config.cache_store = :null_store # Enable serving of images, stylesheets, and JavaScripts from an asset server. # config.action_controller.asset_host = 'http://assets.example.com' diff --git a/config/environments/test.rb b/config/environments/test.rb index 34034499f..a76376fe6 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -43,4 +43,6 @@ Rails.application.configure do # Raises error for missing translations # config.action_view.raise_on_missing_translations = true + + config.cache_store = :null_store end diff --git a/spec/features/comments_spec.rb b/spec/features/comments_spec.rb index 10a919a07..ce5403a56 100644 --- a/spec/features/comments_spec.rb +++ b/spec/features/comments_spec.rb @@ -168,4 +168,4 @@ feature 'Comments' do expect(InappropiateFlag.flagged?(user, comment)).to_not be end -end +end \ No newline at end of file