FIX: do not show name in email if name on posts are disabled

This commit is contained in:
Arpit Jalan 2015-02-18 01:07:22 +05:30
parent 38cc1bf6c1
commit 6e5540c107
2 changed files with 15 additions and 7 deletions

View File

@ -129,7 +129,7 @@ class UserNotifications < ActionMailer::Base
title: post.topic.title,
post: post,
username: post.user.username,
from_alias: (SiteSetting.enable_names && !post.user.name.empty?) ? post.user.name : post.user.username,
from_alias: (SiteSetting.enable_names && SiteSetting.display_name_on_posts && !post.user.name.empty?) ? post.user.name : post.user.username,
allow_reply_by_email: true,
use_site_subject: true,
add_re_to_subject: true,
@ -174,7 +174,7 @@ class UserNotifications < ActionMailer::Base
return unless @post = opts[:post]
user_name = @notification.data_hash[:original_username]
if @post && SiteSetting.enable_names
if @post && SiteSetting.enable_names && SiteSetting.display_name_on_posts
user_name = User.find_by(id: @post.user_id).name if !User.find_by(id: @post.user_id).name.empty?
end

View File

@ -90,7 +90,8 @@ describe UserNotifications do
let(:notification) { Fabricate(:notification, user: user) }
it 'generates a correct email' do
SiteSetting.stubs(:enable_names).returns(true)
SiteSetting.enable_names = true
SiteSetting.display_name_on_posts = true
mail = UserNotifications.user_replied(response.user, post: response, notification: notification)
# from should include full user name
@ -138,7 +139,7 @@ describe UserNotifications do
let(:notification) { Fabricate(:notification, user: user, data: {original_username: response_by_user.username}.to_json) }
it 'generates a correct email' do
SiteSetting.stubs(:enable_names).returns(false)
SiteSetting.enable_names = false
mail = UserNotifications.user_posted(response.user, post: response, notification: notification)
# from should not include full user name if "show user full names" is disabled
@ -170,7 +171,7 @@ describe UserNotifications do
let(:notification) { Fabricate(:notification, user: user, data: {original_username: response_by_user.username}.to_json) }
it 'generates a correct email' do
SiteSetting.stubs(:enable_names).returns(true)
SiteSetting.enable_names = true
mail = UserNotifications.user_private_message(response.user, post: response, notification: notification)
# from should include username if full user name is not provided
@ -267,11 +268,18 @@ describe UserNotifications do
expects_build_with(has_key(:topic_id))
end
it "has a from alias" do
SiteSetting.stubs(:enable_names).returns(true)
it "should have user name as from_alias" do
SiteSetting.enable_names = true
SiteSetting.display_name_on_posts = true
expects_build_with(has_entry(:from_alias, "#{user.name}"))
end
it "should not have user name as from_alias if display_name_on_posts is disabled" do
SiteSetting.enable_names = false
SiteSetting.display_name_on_posts = false
expects_build_with(has_entry(:from_alias, "walterwhite"))
end
it "should explain how to respond" do
expects_build_with(Not(has_entry(:include_respond_instructions, false)))
end