Skip to content

Commit

Permalink
FIX: Improve error messages if user cannot send PM emails (discourse#…
Browse files Browse the repository at this point in the history
  • Loading branch information
nbianca authored Mar 30, 2021
1 parent 21b4fef commit 52a5c7e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
topicId=topicId
filterPlaceholder="composer.users_placeholder"
includeMessageableGroups=true
allowEmails=true
allowEmails=currentUser.can_send_private_email_messages
autoWrap=true
)
}}
1 change: 1 addition & 0 deletions config/locales/server.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
2 changes: 1 addition & 1 deletion lib/topic_creator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def process_private_message(topic)
end

if @opts[:target_emails].present? && !@guardian.can_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])
Expand Down
11 changes: 11 additions & 0 deletions spec/components/topic_creator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,17 @@
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
Expand Down

0 comments on commit 52a5c7e

Please sign in to comment.