From b0b1ace7d94996a74a9667605ad1fb27c04f7136 Mon Sep 17 00:00:00 2001 From: PJ Date: Mon, 10 Jul 2023 11:46:46 +0100 Subject: [PATCH] Prevent comments by the staff account from being hidden (#19698) * don't show hide/unhide on comments made by staff account * block staff account comments from being hidden on the backend as well * moar specs --- app/models/comment.rb | 4 ++ app/policies/comment_policy.rb | 2 +- app/views/comments/_comment_header.html.erb | 35 ++++++------- .../articleFlows/hideArticleComments.spec.js | 11 ++++ spec/models/comment_spec.rb | 19 +++++++ spec/policies/comment_policy_spec.rb | 13 +++++ spec/requests/comments_spec.rb | 21 ++++++++ spec/support/seeds/seeds_e2e.rb | 51 +++++++++++++++++++ 8 files changed, 138 insertions(+), 18 deletions(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index 80762cd34..9b77b4f0e 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -194,6 +194,10 @@ class Comment < ApplicationRecord ancestry && Comment.exists?(id: ancestry) end + def by_staff_account? + user == User.staff_account + end + def privileged_reaction_counts @privileged_reaction_counts ||= reactions.privileged_category.group(:category).count end diff --git a/app/policies/comment_policy.rb b/app/policies/comment_policy.rb index b7b483260..ab097c4e2 100644 --- a/app/policies/comment_policy.rb +++ b/app/policies/comment_policy.rb @@ -37,7 +37,7 @@ class CommentPolicy < ApplicationPolicy end def hide? - user_commentable_author? + user_commentable_author? && !record.by_staff_account? end alias unhide? hide? diff --git a/app/views/comments/_comment_header.html.erb b/app/views/comments/_comment_header.html.erb index ccc0ea540..fc6294d9d 100644 --- a/app/views/comments/_comment_header.html.erb +++ b/app/views/comments/_comment_header.html.erb @@ -31,23 +31,24 @@