FIX: Always let moderators to see their group PMs (#10813)

When enable_personal_messages was disabled, moderators could not see
the private messages for the "moderators" group. The link was displayed
on the client side, but the checks on the server side did not allow it.
This commit is contained in:
Bianca Nenciu 2020-10-05 19:38:08 +03:00 committed by GitHub
parent 969917c4a2
commit 318efa8093
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View File

@ -35,6 +35,7 @@ module GroupGuardian
def can_see_group_messages?(group)
return true if is_admin?
return true if is_moderator? && group.id == Group::AUTO_GROUPS[:moderators]
SiteSetting.enable_personal_messages? && group.users.include?(user)
end

View File

@ -197,6 +197,17 @@ RSpec.describe ListController do
.to eq(topic.id)
end
it 'should display moderator group private messages for a moderator' do
moderator = Fabricate(:moderator)
group = Group.find(Group::AUTO_GROUPS[:moderators])
topic = Fabricate(:private_message_topic, allowed_groups: [group])
sign_in(moderator)
get "/topics/private-messages-group/#{moderator.username}/#{group.name}.json"
expect(response.status).to eq(200)
end
it "should not display group private messages for a moderator's group" do
moderator = Fabricate(:moderator)
sign_in(moderator)