mirror of
https://github.com/discourse/discourse.git
synced 2025-06-06 23:07:28 +08:00
REFACTOR: Add full_url
and display_name
to User
Lets stop writing the same code over and over again.
This commit is contained in:

committed by
Gerhard Schlager

parent
650adbe423
commit
b3cda195b8
@ -245,8 +245,8 @@ class ListController < ApplicationController
|
|||||||
ensure_can_see_profile!(target_user)
|
ensure_can_see_profile!(target_user)
|
||||||
|
|
||||||
@title = "#{SiteSetting.title} - #{I18n.t("rss_description.user_topics", username: target_user.username)}"
|
@title = "#{SiteSetting.title} - #{I18n.t("rss_description.user_topics", username: target_user.username)}"
|
||||||
@link = "#{Discourse.base_url}/u/#{target_user.username}/activity/topics"
|
@link = "#{target_user.full_url}/activity/topics"
|
||||||
@atom_link = "#{Discourse.base_url}/u/#{target_user.username}/activity/topics.rss"
|
@atom_link = "#{target_user.full_url}/activity/topics.rss"
|
||||||
@description = I18n.t("rss_description.user_topics", username: target_user.username)
|
@description = I18n.t("rss_description.user_topics", username: target_user.username)
|
||||||
|
|
||||||
@topic_list = TopicQuery
|
@topic_list = TopicQuery
|
||||||
|
@ -132,7 +132,7 @@ class PostsController < ApplicationController
|
|||||||
format.rss do
|
format.rss do
|
||||||
@posts = posts
|
@posts = posts
|
||||||
@title = "#{SiteSetting.title} - #{I18n.t("rss_description.user_posts", username: user.username)}"
|
@title = "#{SiteSetting.title} - #{I18n.t("rss_description.user_posts", username: user.username)}"
|
||||||
@link = "#{Discourse.base_url}/u/#{user.username}/activity"
|
@link = "#{user.full_url}/activity"
|
||||||
@description = I18n.t("rss_description.user_posts", username: user.username)
|
@description = I18n.t("rss_description.user_posts", username: user.username)
|
||||||
render 'posts/latest', formats: [:rss]
|
render 'posts/latest', formats: [:rss]
|
||||||
end
|
end
|
||||||
|
@ -658,13 +658,7 @@ module ApplicationHelper
|
|||||||
end
|
end
|
||||||
|
|
||||||
def rss_creator(user)
|
def rss_creator(user)
|
||||||
if user
|
user&.display_name
|
||||||
if SiteSetting.prioritize_username_in_ux
|
|
||||||
"#{user.username}"
|
|
||||||
else
|
|
||||||
"#{user.name.presence || user.username }"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def authentication_data
|
def authentication_data
|
||||||
|
@ -83,18 +83,10 @@ class GroupSmtpMailer < ActionMailer::Base
|
|||||||
post.topic.allowed_users.each do |u|
|
post.topic.allowed_users.each do |u|
|
||||||
next if u.id == recipient_user.id
|
next if u.id == recipient_user.id
|
||||||
|
|
||||||
if SiteSetting.prioritize_username_in_ux?
|
if u.staged?
|
||||||
if u.staged?
|
list.push("#{u.email}")
|
||||||
list.push("#{u.email}")
|
|
||||||
else
|
|
||||||
list.push("[#{u.username}](#{Discourse.base_url}/u/#{u.username_lower})")
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
if u.staged?
|
list.push("[#{u.display_name}](#{u.full_url})")
|
||||||
list.push("#{u.email}")
|
|
||||||
else
|
|
||||||
list.push("[#{u.name.blank? ? u.username : u.name}](#{Discourse.base_url}/u/#{u.username_lower})")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -561,12 +561,7 @@ class UserNotifications < ActionMailer::Base
|
|||||||
|
|
||||||
post.topic.allowed_users.each do |u|
|
post.topic.allowed_users.each do |u|
|
||||||
next if u.id == user.id
|
next if u.id == user.id
|
||||||
|
participant_list.push "[#{u.display_name}](#{u.full_url})"
|
||||||
if SiteSetting.prioritize_username_in_ux?
|
|
||||||
participant_list.push "[#{u.username}](#{Discourse.base_url}/u/#{u.username_lower})"
|
|
||||||
else
|
|
||||||
participant_list.push "[#{u.name.blank? ? u.username : u.name}](#{Discourse.base_url}/u/#{u.username_lower})"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
participants += participant_list.join(", ")
|
participants += participant_list.join(", ")
|
||||||
|
@ -16,12 +16,6 @@ class TopicPoster < OpenStruct
|
|||||||
end
|
end
|
||||||
|
|
||||||
def name_and_description
|
def name_and_description
|
||||||
if SiteSetting.prioritize_username_in_ux? || user.name.blank?
|
I18n.t("js.user.avatar.name_and_description", name: user.display_name, description: description)
|
||||||
name = user.username
|
|
||||||
else
|
|
||||||
name = user.name
|
|
||||||
end
|
|
||||||
|
|
||||||
I18n.t("js.user.avatar.name_and_description", name: name, description: description)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1461,6 +1461,18 @@ class User < ActiveRecord::Base
|
|||||||
username_lower == User.normalize_username(another_username)
|
username_lower == User.normalize_username(another_username)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def full_url
|
||||||
|
"#{Discourse.base_url}/u/#{encoded_username}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def display_name
|
||||||
|
if SiteSetting.prioritize_username_in_ux?
|
||||||
|
username
|
||||||
|
else
|
||||||
|
name.presence || username
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def badge_grant
|
def badge_grant
|
||||||
|
@ -62,7 +62,7 @@ class SystemMessage
|
|||||||
{
|
{
|
||||||
site_name: SiteSetting.title,
|
site_name: SiteSetting.title,
|
||||||
username: @recipient.username,
|
username: @recipient.username,
|
||||||
user_preferences_url: "#{Discourse.base_url}/u/#{@recipient.username_lower}/preferences",
|
user_preferences_url: "#{@recipient.full_url}/preferences",
|
||||||
new_user_tips: I18n.with_locale(@recipient.effective_locale) { I18n.t('system_messages.usage_tips.text_body_template', base_url: Discourse.base_url) },
|
new_user_tips: I18n.with_locale(@recipient.effective_locale) { I18n.t('system_messages.usage_tips.text_body_template', base_url: Discourse.base_url) },
|
||||||
site_password: "",
|
site_password: "",
|
||||||
base_url: Discourse.base_url,
|
base_url: Discourse.base_url,
|
||||||
|
Reference in New Issue
Block a user