]> git.openstreetmap.org Git - rails.git/commitdiff
Allow administrators to see deleted diary entries
authorTom Hughes <tom@compton.nu>
Wed, 26 Jul 2023 18:01:48 +0000 (19:01 +0100)
committerTom Hughes <tom@compton.nu>
Thu, 27 Jul 2023 17:03:58 +0000 (18:03 +0100)
app/controllers/diary_entries_controller.rb
test/controllers/diary_entries_controller_test.rb

index 4cdc1b55a817cb740b83d8920f7f0698327e9d05..6e7378bf32cf08020cd0ae9a71a0227bdc216cd6 100644 (file)
@@ -62,7 +62,9 @@ class DiaryEntriesController < ApplicationController
   end
 
   def show
-    @entry = @user.diary_entries.visible.where(:id => params[:id]).first
+    entries = @user.diary_entries
+    entries = entries.visible unless can? :unhide, DiaryEntry
+    @entry = entries.where(:id => params[:id]).first
     if @entry
       @title = t ".title", :user => params[:display_name], :title => @entry.title
       @comments = can?(:unhidecomment, DiaryEntry) ? @entry.comments : @entry.visible_comments
index 42d0426455262048d047748d51641c14a13f82c6..5a35ff035fecf21222ccecfec37cfd8c147b38b5 100644 (file)
@@ -680,14 +680,20 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest
     assert_response :not_found
 
     # Try an entry by a suspended user
-    diary_entry_suspended = create(:diary_entry, :user => suspended_user)
-    get diary_entry_path(:display_name => suspended_user.display_name, :id => diary_entry_suspended)
+    diary_entry_suspended_user = create(:diary_entry, :user => suspended_user)
+    get diary_entry_path(:display_name => suspended_user.display_name, :id => diary_entry_suspended_user)
     assert_response :not_found
 
     # Try an entry by a deleted user
-    diary_entry_deleted = create(:diary_entry, :user => deleted_user)
-    get diary_entry_path(:display_name => deleted_user.display_name, :id => diary_entry_deleted)
+    diary_entry_deleted_user = create(:diary_entry, :user => deleted_user)
+    get diary_entry_path(:display_name => deleted_user.display_name, :id => diary_entry_deleted_user)
     assert_response :not_found
+
+    # Finally try as an administrator
+    session_for(create(:administrator_user))
+    get diary_entry_path(:display_name => user.display_name, :id => diary_entry_deleted)
+    assert_response :success
+    assert_template :show
   end
 
   def test_show_hidden_comments