From 7fb984f9152d18844502df46d934da9c6deda05c Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Thu, 27 Jul 2023 18:07:35 +0100 Subject: [PATCH] Allow moderator to unhide diary entries as well as hide them --- app/abilities/ability.rb | 2 +- .../diary_entries_controller_test.rb | 20 +++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/abilities/ability.rb b/app/abilities/ability.rb index 5d196fa98..cdf28bd4f 100644 --- a/app/abilities/ability.rb +++ b/app/abilities/ability.rb @@ -56,7 +56,7 @@ class Ability can [:account, :go_public], User if user.moderator? - can [:hide, :hidecomment], DiaryEntry + can [:hide, :unhide, :hidecomment, :unhidecomment], DiaryEntry can [:index, :show, :resolve, :ignore, :reopen], Issue can :create, IssueComment can [:new, :create, :edit, :update, :destroy], Redaction diff --git a/test/controllers/diary_entries_controller_test.rb b/test/controllers/diary_entries_controller_test.rb index 5a35ff035..8d646c426 100644 --- a/test/controllers/diary_entries_controller_test.rb +++ b/test/controllers/diary_entries_controller_test.rb @@ -689,6 +689,12 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest get diary_entry_path(:display_name => deleted_user.display_name, :id => diary_entry_deleted_user) assert_response :not_found + # Now try as a moderator + session_for(create(:moderator_user)) + get diary_entry_path(:display_name => user.display_name, :id => diary_entry_deleted) + assert_response :success + assert_template :show + # Finally try as an administrator session_for(create(:administrator_user)) get diary_entry_path(:display_name => user.display_name, :id => diary_entry_deleted) @@ -770,8 +776,11 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest session_for(create(:moderator_user)) post unhide_diary_entry_path(:display_name => user.display_name, :id => diary_entry) assert_response :redirect - assert_redirected_to :controller => :errors, :action => :forbidden - assert_not DiaryEntry.find(diary_entry.id).visible + assert_redirected_to :action => :index, :display_name => user.display_name + assert DiaryEntry.find(diary_entry.id).visible + + # Reset + diary_entry.reload.update(:visible => true) # Finally try as an administrator session_for(create(:administrator_user)) @@ -837,8 +846,11 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest session_for(create(:moderator_user)) post unhide_diary_comment_path(:display_name => user.display_name, :id => diary_entry, :comment => diary_comment) assert_response :redirect - assert_redirected_to :controller => :errors, :action => :forbidden - assert_not DiaryComment.find(diary_comment.id).visible + assert_redirected_to :action => :show, :display_name => user.display_name, :id => diary_entry.id + assert DiaryComment.find(diary_comment.id).visible + + # Reset + diary_comment.reload.update(:visible => true) # Finally try as an administrator session_for(create(:administrator_user)) -- 2.39.5