FIX: if prioritizing names in ux choose name over username in email

This commit is contained in:
Sam 2016-11-14 11:09:24 +11:00
parent 3ed2d645a3
commit 115c454002
3 changed files with 46 additions and 0 deletions

View File

@ -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? &&

View File

@ -8,7 +8,9 @@
<img src="<%= post.user.small_avatar_url %>" title="<%= post.user.username%>">
</td>
<td>
<%- if show_username_on_post(post) %>
<a class="username" href="<%=Discourse.base_url%>/users/<%= post.user.username_lower%>" target="_blank"><%= post.user.username %></a>
<% end %>
<%- if show_name_on_post(post) %>
<a class="user-name" href="<%=Discourse.base_url%>/users/<%= post.user.username_lower%>" target="_blank"><%= post.user.name %></a>
<% end %>

View File

@ -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