mirror of
https://github.com/discourse/discourse.git
synced 2025-06-04 07:14:41 +08:00
FEATURE: Allow users to disable new PMs.
https://meta.discourse.org/t/is-it-possible-to-disable-private-messaging-for-a-specific-user/46391
This commit is contained in:
@ -233,6 +233,27 @@ describe Guardian do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'target user has private message disabled' do
|
||||
before do
|
||||
another_user.user_option.update!(allow_private_messages: false)
|
||||
end
|
||||
|
||||
context 'for a normal user' do
|
||||
it 'should return false' do
|
||||
expect(Guardian.new(user).can_send_private_message?(another_user)).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
context 'for a staff user' do
|
||||
it 'should return true' do
|
||||
[admin, moderator].each do |staff_user|
|
||||
expect(Guardian.new(staff_user).can_send_private_message?(another_user))
|
||||
.to eq(true)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'can_reply_as_new_topic' do
|
||||
|
@ -954,6 +954,30 @@ describe PostCreator do
|
||||
end
|
||||
end
|
||||
|
||||
context 'private message to a user that has disabled private messages' do
|
||||
let(:another_user) { Fabricate(:user) }
|
||||
|
||||
before do
|
||||
another_user.user_option.update!(allow_private_messages: false)
|
||||
end
|
||||
|
||||
it 'should not be valid' do
|
||||
post_creator = PostCreator.new(
|
||||
user,
|
||||
title: 'this message is to someone who muted me!',
|
||||
raw: "you will have to see this even if you muted me!",
|
||||
archetype: Archetype.private_message,
|
||||
target_usernames: "#{another_user.username}"
|
||||
)
|
||||
|
||||
expect(post_creator).to_not be_valid
|
||||
|
||||
expect(post_creator.errors.full_messages).to include(I18n.t(
|
||||
"not_accepting_pms", username: another_user.username
|
||||
))
|
||||
end
|
||||
end
|
||||
|
||||
context "private message to a muted user" do
|
||||
let(:muted_me) { Fabricate(:evil_trout) }
|
||||
|
||||
|
Reference in New Issue
Block a user