Skip to content

A platform for community discussion. Free, open, simple.

FIX: Improve error messages if user cannot send PM emails (#12547)

Bianca Nenciu52a5c7e438d2
diff --git a/app/assets/javascripts/discourse/app/templates/components/composer-user-selector.hbs b/app/assets/javascripts/discourse/app/templates/components/composer-user-selector.hbs
index c7a563cb356..b18046a5d77 100644
--- a/app/assets/javascripts/discourse/app/templates/components/composer-user-selector.hbs
+++ b/app/assets/javascripts/discourse/app/templates/components/composer-user-selector.hbs
@@ -7,7 +7,7 @@
topicId=topicId
filterPlaceholder="composer.users_placeholder"
includeMessageableGroups=true
- allowEmails=true
+ allowEmails=currentUser.can_send_private_email_messages
autoWrap=true
)
}}
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index 37e1f1e81b0..adb389628c9 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -568,6 +568,7 @@ en:
cant_send_pm: "Sorry, you cannot send a personal message to that user."
no_user_selected: "You must select a valid user."
reply_by_email_disabled: "Reply by email has been disabled."
+ send_to_email_disabled: "Sorry, you cannot send personal messages to email."
target_user_not_found: "One of the users you are sending this message to could not be found."
unable_to_update: "There was an error updating that topic."
unable_to_tag: "There was an error tagging the topic."
diff --git a/lib/topic_creator.rb b/lib/topic_creator.rb
index 30c8de2dd4e..a06f81f151b 100644
--- a/lib/topic_creator.rb
+++ b/lib/topic_creator.rb
@@ -193,7 +193,7 @@ class TopicCreator
end
if @opts[:target_emails].present? && [email protected]_send_private_messages_to_email? then
- rollback_with!(topic, :reply_by_email_disabled)
+ rollback_with!(topic, :send_to_email_disabled)
end
add_users(topic, @opts[:target_usernames])
diff --git a/spec/components/topic_creator_spec.rb b/spec/components/topic_creator_spec.rb
index 5613e9b0ef8..32484ae5e7d 100644
--- a/spec/components/topic_creator_spec.rb
+++ b/spec/components/topic_creator_spec.rb
@@ -245,6 +245,17 @@ describe TopicCreator do
end.to raise_error(ActiveRecord::Rollback)
end
end
+
+ context 'to emails' do
+ it 'works for staff' do
+ expect(TopicCreator.create(admin, Guardian.new(admin), pm_valid_attrs.merge(target_emails: '[email protected]'))).to be_valid
+ end
+
+ it 'does not work for non-staff' do
+ user.update!(trust_level: TrustLevel[4])
+ expect { TopicCreator.create(user, Guardian.new(user), pm_valid_attrs.merge(target_emails: '[email protected]')) }.to raise_error(ActiveRecord::Rollback)
+ end
+ end
end
context 'setting timestamps' do