From 115c45400278243aa90d4997af9a8b87647552bd Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 14 Nov 2016 11:09:24 +1100 Subject: [PATCH] FIX: if prioritizing names in ux choose name over username in email --- app/helpers/user_notifications_helper.rb | 11 ++++++++ app/views/email/_post.html.erb | 2 ++ spec/mailers/user_notifications_spec.rb | 33 ++++++++++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/app/helpers/user_notifications_helper.rb b/app/helpers/user_notifications_helper.rb index 84b5204f841..8fca6d8ce26 100644 --- a/app/helpers/user_notifications_helper.rb +++ b/app/helpers/user_notifications_helper.rb @@ -58,7 +58,18 @@ module UserNotificationsHelper name.downcase.gsub(/[\s_-]/, '') end + def show_username_on_post(post) + return true if SiteSetting.prioritize_username_in_ux + return true unless SiteSetting.enable_names? + return true unless SiteSetting.display_name_on_posts? + return true unless post.user.name.present? + + normalize_name(post.user.name) != normalize_name(post.user.username) + end + def show_name_on_post(post) + return true unless SiteSetting.prioritize_username_in_ux + SiteSetting.enable_names? && SiteSetting.display_name_on_posts? && post.user.name.present? && diff --git a/app/views/email/_post.html.erb b/app/views/email/_post.html.erb index 42bb7afb836..3f0d21580f4 100644 --- a/app/views/email/_post.html.erb +++ b/app/views/email/_post.html.erb @@ -8,7 +8,9 @@ + <%- if show_username_on_post(post) %> <%= post.user.username %> + <% end %> <%- if show_name_on_post(post) %> <%= post.user.name %> <% end %> diff --git a/spec/mailers/user_notifications_spec.rb b/spec/mailers/user_notifications_spec.rb index bee8d13f25e..bc7dfb4fddb 100644 --- a/spec/mailers/user_notifications_spec.rb +++ b/spec/mailers/user_notifications_spec.rb @@ -232,6 +232,39 @@ describe UserNotifications do expect(mail.html_part.to_s.scan(/In Reply To/).count).to eq(0) + + + + SiteSetting.enable_names = true + SiteSetting.display_name_on_posts = true + SiteSetting.prioritize_username_in_ux = false + + response.user.username = "bobmarley" + response.user.name = "Bob Marley" + response.user.save + + mail = UserNotifications.user_replied(response.user, + post: response, + notification_type: notification.notification_type, + notification_data_hash: notification.data_hash + ) + + + mail_html = mail.html_part.to_s + expect(mail_html.scan(/>Bob Marley/).count).to eq(1) + expect(mail_html.scan(/>bobmarley/).count).to eq(0) + + SiteSetting.prioritize_username_in_ux = true + + mail = UserNotifications.user_replied(response.user, + post: response, + notification_type: notification.notification_type, + notification_data_hash: notification.data_hash + ) + + mail_html = mail.html_part.to_s + expect(mail_html.scan(/>Bob Marley/).count).to eq(0) + expect(mail_html.scan(/>bobmarley/).count).to eq(1) end end