From c96ba248cf96017576f3978a040078b06510e27c Mon Sep 17 00:00:00 2001 From: welp Date: Thu, 21 Nov 2024 13:44:22 -0800 Subject: [PATCH 1/2] AO3-5977 Hide "Approve All Unreviewed Comments" button from admins on works Also hides "Approve All Unreviewed Comments" when there are no unreviewed comments. --- app/views/comments/unreviewed.html.erb | 10 ++++++---- features/admins/admin_works.feature | 13 +++++++++++++ features/step_definitions/web_steps.rb | 6 ++++++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/app/views/comments/unreviewed.html.erb b/app/views/comments/unreviewed.html.erb index 51ad90d82e6..86d4de17b3c 100644 --- a/app/views/comments/unreviewed.html.erb +++ b/app/views/comments/unreviewed.html.erb @@ -3,10 +3,12 @@ - +<% if @comments[0] && can_review_comment?(@comments[0]) %> + +<% end %> diff --git a/features/admins/admin_works.feature b/features/admins/admin_works.feature index 39807cbd650..ae7740c3843 100644 --- a/features/admins/admin_works.feature +++ b/features/admins/admin_works.feature @@ -330,6 +330,19 @@ Feature: Admin Actions for Works, Comments, Series, Bookmarks Then I should see "rolex" And I should not see "This comment has been marked as spam." + Scenario: Moderated comments cannot be approved by admin + Given the moderated work "Moderation" by "author" + And I am logged in as "commenter" + And I post the comment "Test comment" on the work "Moderation" + When I am logged in as a "superadmin" admin + And I view the work "Moderation" + Then I should see "Unreviewed Comments (1)" + And the comment on "Moderation" should be marked as unreviewed + When I follow "Unreviewed Comments (1)" + Then I should see "Test comment" + And I should not see button "Approve All Unreviewed Comments" + And I should not see button "Approve" + Scenario: Admin can edit language on works when posting without previewing Given basic languages And I am logged in as "regular_user" diff --git a/features/step_definitions/web_steps.rb b/features/step_definitions/web_steps.rb index dc0334376cb..5031fd5df4a 100644 --- a/features/step_definitions/web_steps.rb +++ b/features/step_definitions/web_steps.rb @@ -257,6 +257,12 @@ def with_scope(locator) end end +Then /^(?:|I )should not see button "([^"]*)"(?: within "([^"]*)")?$/ do |text, selector| + with_scope(selector) do + page.body.should_not have_button(text) + end +end + Then /^(?:|I )should be on (.+)$/ do |page_name| current_path = URI.parse(current_url).path if current_path.respond_to? :should From b583a752eb43821e1f14cd9e5a6639bd005b1de5 Mon Sep 17 00:00:00 2001 From: welp Date: Mon, 25 Nov 2024 23:45:55 -0800 Subject: [PATCH 2/2] Simplify test, check --- app/helpers/comments_helper.rb | 4 ++++ app/views/comments/unreviewed.html.erb | 2 +- features/admins/admin_works.feature | 4 ++-- features/step_definitions/web_steps.rb | 6 ------ 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/app/helpers/comments_helper.rb b/app/helpers/comments_helper.rb index fd87f3e7946..0285291d0bb 100644 --- a/app/helpers/comments_helper.rb +++ b/app/helpers/comments_helper.rb @@ -210,6 +210,10 @@ def can_review_comment?(comment) is_author_of?(comment.ultimate_parent) || policy(comment).can_review_comment? end + def can_review_all_comments?(commentable) + commentable.is_a?(AdminPost) || is_author_of?(commentable) + end + #### HELPERS FOR REPLYING TO COMMENTS ##### # return link to add new reply to a comment diff --git a/app/views/comments/unreviewed.html.erb b/app/views/comments/unreviewed.html.erb index 86d4de17b3c..f70d57605ec 100644 --- a/app/views/comments/unreviewed.html.erb +++ b/app/views/comments/unreviewed.html.erb @@ -3,7 +3,7 @@ -<% if @comments[0] && can_review_comment?(@comments[0]) %> +<% if can_review_all_comments?(@commentable) %>