A platform for community discussion. Free, open, simple.
FIX: All admins should be allowed to see deleted PM posts regardless of their mod status (#30206)
Osama Sayeghe2cd1da26d0a
diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rbindex d1ac78ecf15..96c3621f8b8 100644--- a/app/controllers/posts_controller.rb+++ b/app/controllers/posts_controller.rb@@ -814,7 +814,7 @@ class PostsController < ApplicationController.order(created_at: :desc)end- if guardian.user.moderator?+ if guardian.user.moderator? && !guardian.user.admin?# Awful hack, but you can't seem to remove the `default_scope` when joining# So instead I grab the topics separatelytopic_ids = posts.dup.pluck(:topic_id)diff --git a/spec/requests/posts_controller_spec.rb b/spec/requests/posts_controller_spec.rbindex 439b3a1a39c..0791cfe1714 100644--- a/spec/requests/posts_controller_spec.rb+++ b/spec/requests/posts_controller_spec.rb@@ -2492,6 +2492,21 @@ RSpec.describe PostsController doexpect(data.length).to eq(0)end+ it "returns PMs for admins who are also moderators" do+ admin.update!(moderator: true)++ pm_post = Fabricate(:private_message_post)+ PostDestroyer.new(admin, pm_post).destroy++ sign_in(admin)++ get "/posts/#{pm_post.user.username}/deleted.json"++ expect(response.status).to eq(200)+ expect(response.parsed_body.size).to eq(1)+ expect(response.parsed_body.first["id"]).to eq(pm_post.id)+ end+it "only shows posts deleted by other users" docreate_post(user: user)post_deleted_by_user = create_post(user: user)