FIX: staff should not be able to PM groups that "Nobody" can message (#16163)

If a group's messageable_level is set to nobody then staff can't should not be able to send PMs to it.

Co-authored-by: Martin Brennan <martin@discourse.org>
This commit is contained in:
Vinoth Kannan
2022-03-22 05:53:14 +05:30
committed by GitHub
parent 31bc756037
commit 8a9a7a77d8
3 changed files with 12 additions and 9 deletions

View File

@ -336,14 +336,13 @@ describe Guardian do
it "respects the group's messageable_level" do
Group::ALIAS_LEVELS.each do |level, _|
group.update!(messageable_level: Group::ALIAS_LEVELS[level])
output = level == :everyone ? true : false
user_output = level == :everyone ? true : false
admin_output = level != :nobody
mod_output = [:nobody, :only_admins].exclude?(level)
expect(Guardian.new(user).can_send_private_message?(group)).to eq(output)
end
Group::ALIAS_LEVELS.each do |level, _|
group.update!(messageable_level: Group::ALIAS_LEVELS[level])
expect(Guardian.new(admin).can_send_private_message?(group)).to eq(true)
expect(Guardian.new(user).can_send_private_message?(group)).to eq(user_output)
expect(Guardian.new(admin).can_send_private_message?(group)).to eq(admin_output)
expect(Guardian.new(moderator).can_send_private_message?(group)).to eq(mod_output)
end
end