mirror of
https://github.com/discourse/discourse.git
synced 2025-05-28 13:51:18 +08:00
DEV: Use guardian user for can_chat? (#19418)
Instead of passing `user` to `guardian.can_chat?`, we can just use the inner `@user` that is part of the guardian instance already to determine whether that user can chat, since this is how it works for all other usages of guardian even within chat.
This commit is contained in:
@ -13,28 +13,28 @@ RSpec.describe Chat::GuardianExtensions do
|
||||
|
||||
it "cannot chat if the user is not in the Chat.allowed_group_ids" do
|
||||
SiteSetting.chat_allowed_groups = ""
|
||||
expect(guardian.can_chat?(user)).to eq(false)
|
||||
expect(guardian.can_chat?).to eq(false)
|
||||
end
|
||||
|
||||
it "staff can always chat regardless of chat_allowed_grups" do
|
||||
SiteSetting.chat_allowed_groups = ""
|
||||
expect(guardian.can_chat?(staff)).to eq(true)
|
||||
expect(staff_guardian.can_chat?).to eq(true)
|
||||
end
|
||||
|
||||
it "allows TL1 to chat by default and by extension higher trust levels" do
|
||||
Group.refresh_automatic_groups!
|
||||
expect(guardian.can_chat?(user)).to eq(true)
|
||||
expect(guardian.can_chat?).to eq(true)
|
||||
user.update!(trust_level: TrustLevel[3])
|
||||
Group.refresh_automatic_groups!
|
||||
expect(guardian.can_chat?(user)).to eq(true)
|
||||
expect(guardian.can_chat?).to eq(true)
|
||||
end
|
||||
|
||||
it "allows user in specific group to chat" do
|
||||
SiteSetting.chat_allowed_groups = chat_group.id
|
||||
expect(guardian.can_chat?(user)).to eq(false)
|
||||
expect(guardian.can_chat?).to eq(false)
|
||||
chat_group.add(user)
|
||||
user.reload
|
||||
expect(guardian.can_chat?(user)).to eq(true)
|
||||
expect(guardian.can_chat?).to eq(true)
|
||||
end
|
||||
|
||||
describe "chat channel" do
|
||||
|
Reference in New Issue
Block a user