mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 10:52:45 +08:00
DEV: enforces system user membership (#23771)
System user will automatically adds itself to the channel when trying to send a message.
This commit is contained in:
parent
08df8fc1d1
commit
8447928840
|
@ -24,6 +24,7 @@ module Chat
|
|||
model :channel
|
||||
policy :allowed_to_join_channel
|
||||
policy :allowed_to_create_message_in_channel, class_name: Chat::Channel::MessageCreationPolicy
|
||||
step :enforce_system_membership
|
||||
model :channel_membership
|
||||
model :reply, optional: true
|
||||
policy :ensure_reply_consistency
|
||||
|
@ -72,6 +73,10 @@ module Chat
|
|||
guardian.can_join_chat_channel?(channel)
|
||||
end
|
||||
|
||||
def enforce_system_membership(guardian:, channel:, **)
|
||||
channel.add(guardian.user) if guardian.user.is_system_user?
|
||||
end
|
||||
|
||||
def fetch_channel_membership(guardian:, channel:, **)
|
||||
Chat::ChannelMembershipManager.new(channel).find_for_user(guardian.user)
|
||||
end
|
||||
|
|
|
@ -183,6 +183,12 @@ RSpec.describe Chat::CreateMessage do
|
|||
it { is_expected.to fail_a_policy(:allowed_to_join_channel) }
|
||||
end
|
||||
|
||||
context "when user is system" do
|
||||
fab!(:user) { Discourse.system_user }
|
||||
|
||||
it { is_expected.to be_a_success }
|
||||
end
|
||||
|
||||
context "when user can join channel" do
|
||||
before { user.groups << Group.find(Group::AUTO_GROUPS[:trust_level_1]) }
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user