Merge pull request #2897 from techAPJ/patch-1
FEATURE: show full user name in emails
This commit is contained in:
commit
7659d491fd
|
@ -126,7 +126,8 @@ class UserNotifications < ActionMailer::Base
|
||||||
send_notification_email(
|
send_notification_email(
|
||||||
title: post.topic.title,
|
title: post.topic.title,
|
||||||
post: post,
|
post: post,
|
||||||
from_alias: post.user.username,
|
username: post.user.username,
|
||||||
|
from_alias: SiteSetting.enable_email_names ? post.user.name : post.user.username,
|
||||||
allow_reply_by_email: true,
|
allow_reply_by_email: true,
|
||||||
use_site_subject: true,
|
use_site_subject: true,
|
||||||
add_re_to_subject: true,
|
add_re_to_subject: true,
|
||||||
|
@ -170,7 +171,11 @@ class UserNotifications < ActionMailer::Base
|
||||||
return unless @notification = opts[:notification]
|
return unless @notification = opts[:notification]
|
||||||
return unless @post = opts[:post]
|
return unless @post = opts[:post]
|
||||||
|
|
||||||
username = @notification.data_hash[:original_username]
|
user_name = @notification.data_hash[:original_username]
|
||||||
|
if @post && SiteSetting.enable_email_names
|
||||||
|
user_name = User.find_by(id: @post.user_id).name
|
||||||
|
end
|
||||||
|
|
||||||
notification_type = opts[:notification_type] || Notification.types[@notification.notification_type].to_s
|
notification_type = opts[:notification_type] || Notification.types[@notification.notification_type].to_s
|
||||||
|
|
||||||
return if user.mailing_list_mode && !@post.topic.private_message? &&
|
return if user.mailing_list_mode && !@post.topic.private_message? &&
|
||||||
|
@ -185,7 +190,8 @@ class UserNotifications < ActionMailer::Base
|
||||||
send_notification_email(
|
send_notification_email(
|
||||||
title: title,
|
title: title,
|
||||||
post: @post,
|
post: @post,
|
||||||
from_alias: username,
|
username: @notification.data_hash[:original_username],
|
||||||
|
from_alias: user_name,
|
||||||
allow_reply_by_email: allow_reply_by_email,
|
allow_reply_by_email: allow_reply_by_email,
|
||||||
use_site_subject: use_site_subject,
|
use_site_subject: use_site_subject,
|
||||||
add_re_to_subject: add_re_to_subject,
|
add_re_to_subject: add_re_to_subject,
|
||||||
|
@ -202,6 +208,7 @@ class UserNotifications < ActionMailer::Base
|
||||||
allow_reply_by_email = opts[:allow_reply_by_email]
|
allow_reply_by_email = opts[:allow_reply_by_email]
|
||||||
use_site_subject = opts[:use_site_subject]
|
use_site_subject = opts[:use_site_subject]
|
||||||
add_re_to_subject = opts[:add_re_to_subject] && post.post_number > 1
|
add_re_to_subject = opts[:add_re_to_subject] && post.post_number > 1
|
||||||
|
username = opts[:username]
|
||||||
from_alias = opts[:from_alias]
|
from_alias = opts[:from_alias]
|
||||||
notification_type = opts[:notification_type]
|
notification_type = opts[:notification_type]
|
||||||
user = opts[:user]
|
user = opts[:user]
|
||||||
|
@ -254,7 +261,7 @@ class UserNotifications < ActionMailer::Base
|
||||||
post_id: post.id,
|
post_id: post.id,
|
||||||
topic_id: post.topic_id,
|
topic_id: post.topic_id,
|
||||||
context: context,
|
context: context,
|
||||||
username: from_alias,
|
username: username,
|
||||||
add_unsubscribe_link: true,
|
add_unsubscribe_link: true,
|
||||||
allow_reply_by_email: allow_reply_by_email,
|
allow_reply_by_email: allow_reply_by_email,
|
||||||
use_site_subject: use_site_subject,
|
use_site_subject: use_site_subject,
|
||||||
|
|
|
@ -941,6 +941,8 @@ en:
|
||||||
strip_images_from_short_emails: "Strip images from emails having size less than 2800 Bytes"
|
strip_images_from_short_emails: "Strip images from emails having size less than 2800 Bytes"
|
||||||
short_email_length: "Short email length in Bytes"
|
short_email_length: "Short email length in Bytes"
|
||||||
|
|
||||||
|
enable_email_names: "Allow showing user full name in emails. Disable to hide full name in emails."
|
||||||
|
|
||||||
pop3_polling_enabled: "Poll via POP3 for email replies."
|
pop3_polling_enabled: "Poll via POP3 for email replies."
|
||||||
pop3_polling_ssl: "Use SSL while connecting to the POP3 server. (Recommended)"
|
pop3_polling_ssl: "Use SSL while connecting to the POP3 server. (Recommended)"
|
||||||
pop3_polling_period_mins: "The period in minutes between checking the POP3 account for email. NOTE: requires restart."
|
pop3_polling_period_mins: "The period in minutes between checking the POP3 account for email. NOTE: requires restart."
|
||||||
|
|
|
@ -416,6 +416,7 @@ email:
|
||||||
disable_emails: false
|
disable_emails: false
|
||||||
strip_images_from_short_emails: true
|
strip_images_from_short_emails: true
|
||||||
short_email_length: 2800
|
short_email_length: 2800
|
||||||
|
enable_email_names: true
|
||||||
|
|
||||||
files:
|
files:
|
||||||
max_image_size_kb:
|
max_image_size_kb:
|
||||||
|
|
|
@ -71,16 +71,21 @@ describe UserNotifications do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '.user_replied' do
|
describe '.user_replied' do
|
||||||
|
let(:response_by_user) { Fabricate(:user, name: "John Doe") }
|
||||||
let(:category) { Fabricate(:category, name: 'India') }
|
let(:category) { Fabricate(:category, name: 'India') }
|
||||||
let(:topic) { Fabricate(:topic, category: category) }
|
let(:topic) { Fabricate(:topic, category: category) }
|
||||||
let(:post) { Fabricate(:post, topic: topic) }
|
let(:post) { Fabricate(:post, topic: topic) }
|
||||||
let(:response) { Fabricate(:post, topic: post.topic)}
|
let(:response) { Fabricate(:post, topic: post.topic, user: response_by_user)}
|
||||||
let(:user) { Fabricate(:user) }
|
let(:user) { Fabricate(:user) }
|
||||||
let(:notification) { Fabricate(:notification, user: user) }
|
let(:notification) { Fabricate(:notification, user: user) }
|
||||||
|
|
||||||
it 'generates a correct email' do
|
it 'generates a correct email' do
|
||||||
|
SiteSetting.stubs(:enable_email_names).returns(true)
|
||||||
mail = UserNotifications.user_replied(response.user, post: response, notification: notification)
|
mail = UserNotifications.user_replied(response.user, post: response, notification: notification)
|
||||||
|
|
||||||
|
# from should include full user name
|
||||||
|
expect(mail[:from].display_names).to eql(['John Doe'])
|
||||||
|
|
||||||
# subject should include category name
|
# subject should include category name
|
||||||
expect(mail.subject).to match(/India/)
|
expect(mail.subject).to match(/India/)
|
||||||
|
|
||||||
|
@ -109,14 +114,19 @@ describe UserNotifications do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '.user_posted' do
|
describe '.user_posted' do
|
||||||
|
let(:response_by_user) { Fabricate(:user, name: "John Doe") }
|
||||||
let(:post) { Fabricate(:post) }
|
let(:post) { Fabricate(:post) }
|
||||||
let(:response) { Fabricate(:post, topic: post.topic)}
|
let(:response) { Fabricate(:post, topic: post.topic, user: response_by_user)}
|
||||||
let(:user) { Fabricate(:user) }
|
let(:user) { Fabricate(:user) }
|
||||||
let(:notification) { Fabricate(:notification, user: user) }
|
let(:notification) { Fabricate(:notification, user: user) }
|
||||||
|
|
||||||
it 'generates a correct email' do
|
it 'generates a correct email' do
|
||||||
|
SiteSetting.stubs(:enable_email_names).returns(false)
|
||||||
mail = UserNotifications.user_posted(response.user, post: response, notification: notification)
|
mail = UserNotifications.user_posted(response.user, post: response, notification: notification)
|
||||||
|
|
||||||
|
# from should not include full user name if "show user full names" is disabled
|
||||||
|
expect(mail[:from].display_names).to_not eql(['John Doe'])
|
||||||
|
|
||||||
# subject should not include category name
|
# subject should not include category name
|
||||||
expect(mail.subject).not_to match(/Uncategorized/)
|
expect(mail.subject).not_to match(/Uncategorized/)
|
||||||
|
|
||||||
|
@ -133,14 +143,19 @@ describe UserNotifications do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '.user_private_message' do
|
describe '.user_private_message' do
|
||||||
|
let(:response_by_user) { Fabricate(:user, name: "John Doe") }
|
||||||
let(:topic) { Fabricate(:private_message_topic) }
|
let(:topic) { Fabricate(:private_message_topic) }
|
||||||
let(:response) { Fabricate(:post, topic: topic)}
|
let(:response) { Fabricate(:post, topic: topic, user: response_by_user)}
|
||||||
let(:user) { Fabricate(:user) }
|
let(:user) { Fabricate(:user) }
|
||||||
let(:notification) { Fabricate(:notification, user: user) }
|
let(:notification) { Fabricate(:notification, user: user) }
|
||||||
|
|
||||||
it 'generates a correct email' do
|
it 'generates a correct email' do
|
||||||
|
SiteSetting.stubs(:enable_email_names).returns(true)
|
||||||
mail = UserNotifications.user_private_message(response.user, post: response, notification: notification)
|
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'])
|
||||||
|
|
||||||
# subject should include "[PM]"
|
# subject should include "[PM]"
|
||||||
expect(mail.subject).to match("[PM]")
|
expect(mail.subject).to match("[PM]")
|
||||||
|
|
||||||
|
@ -224,7 +239,8 @@ describe UserNotifications do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "has a from alias" do
|
it "has a from alias" do
|
||||||
expects_build_with(has_entry(:from_alias, "#{username}"))
|
SiteSetting.stubs(:enable_email_names).returns(true)
|
||||||
|
expects_build_with(has_entry(:from_alias, "#{user.name}"))
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should explain how to respond" do
|
it "should explain how to respond" do
|
||||||
|
|
Loading…
Reference in New Issue