mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-30 10:58:31 -05:00
FIX: if full user name is not provided, username should be present in email From header
This commit is contained in:
parent
a05408ac9d
commit
f84bdfdde3
2 changed files with 11 additions and 8 deletions
|
@ -127,7 +127,7 @@ class UserNotifications < ActionMailer::Base
|
|||
title: post.topic.title,
|
||||
post: post,
|
||||
username: post.user.username,
|
||||
from_alias: SiteSetting.enable_email_names ? post.user.name : post.user.username,
|
||||
from_alias: (SiteSetting.enable_email_names && !post.user.name.empty?) ? post.user.name : post.user.username,
|
||||
allow_reply_by_email: true,
|
||||
use_site_subject: true,
|
||||
add_re_to_subject: true,
|
||||
|
@ -173,7 +173,7 @@ class UserNotifications < ActionMailer::Base
|
|||
|
||||
user_name = @notification.data_hash[:original_username]
|
||||
if @post && SiteSetting.enable_email_names
|
||||
user_name = User.find_by(id: @post.user_id).name
|
||||
user_name = User.find_by(id: @post.user_id).name if !User.find_by(id: @post.user_id).name.empty?
|
||||
end
|
||||
|
||||
notification_type = opts[:notification_type] || Notification.types[@notification.notification_type].to_s
|
||||
|
|
|
@ -131,11 +131,11 @@ describe UserNotifications do
|
|||
end
|
||||
|
||||
describe '.user_posted' do
|
||||
let(:response_by_user) { Fabricate(:user, name: "John Doe") }
|
||||
let(:response_by_user) { Fabricate(:user, name: "John Doe", username: "john") }
|
||||
let(:post) { Fabricate(:post) }
|
||||
let(:response) { Fabricate(:post, topic: post.topic, user: response_by_user)}
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:notification) { Fabricate(:notification, user: user) }
|
||||
let(:notification) { Fabricate(:notification, user: user, data: {original_username: response_by_user.username}.to_json) }
|
||||
|
||||
it 'generates a correct email' do
|
||||
SiteSetting.stubs(:enable_email_names).returns(false)
|
||||
|
@ -144,6 +144,9 @@ describe UserNotifications do
|
|||
# from should not include full user name if "show user full names" is disabled
|
||||
expect(mail[:from].display_names).to_not eql(['John Doe'])
|
||||
|
||||
# from should include username if "show user full names" is disabled
|
||||
expect(mail[:from].display_names).to eql(['john'])
|
||||
|
||||
# subject should not include category name
|
||||
expect(mail.subject).not_to match(/Uncategorized/)
|
||||
|
||||
|
@ -160,18 +163,18 @@ describe UserNotifications do
|
|||
end
|
||||
|
||||
describe '.user_private_message' do
|
||||
let(:response_by_user) { Fabricate(:user, name: "John Doe") }
|
||||
let(:response_by_user) { Fabricate(:user, name: "", username: "john") }
|
||||
let(:topic) { Fabricate(:private_message_topic) }
|
||||
let(:response) { Fabricate(:post, topic: topic, user: response_by_user)}
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:notification) { Fabricate(:notification, user: user) }
|
||||
let(:notification) { Fabricate(:notification, user: user, data: {original_username: response_by_user.username}.to_json) }
|
||||
|
||||
it 'generates a correct email' do
|
||||
SiteSetting.stubs(:enable_email_names).returns(true)
|
||||
mail = UserNotifications.user_private_message(response.user, post: response, notification: notification)
|
||||
|
||||
# from should include full user name
|
||||
expect(mail[:from].display_names).to eql(['John Doe'])
|
||||
# from should include username if full user name is not provided
|
||||
expect(mail[:from].display_names).to eql(['john'])
|
||||
|
||||
# subject should include "[PM]"
|
||||
expect(mail.subject).to match("[PM]")
|
||||
|
|
Loading…
Reference in a new issue