mirror of
https://github.com/Retrospring/retrospring.git
synced 2024-11-20 16:19:52 +01:00
Unmask author when in moderation mode
This commit is contained in:
parent
1b09d51443
commit
93f8bf35d2
1 changed files with 19 additions and 6 deletions
|
@ -1,23 +1,36 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module UserHelper
|
||||
# Decides what user name to show.
|
||||
# @param context_user [User] the user whose the profile preferences should be applied
|
||||
# @return [String] The user name
|
||||
def user_screen_name(user, context_user: nil, anonymous: false, url: true, link_only: false)
|
||||
return anonymous_name(context_user) if user.nil? || anonymous
|
||||
return profile_link(user) if should_unmask?(user, anonymous)
|
||||
return anonymous_name(context_user) if anonymous?(user, anonymous)
|
||||
|
||||
name = user.profile.display_name.presence || user.screen_name
|
||||
if url
|
||||
link = show_user_profile_path(user.screen_name)
|
||||
return link if link_only
|
||||
return show_user_profile_path(user.screen_name) if link_only
|
||||
|
||||
return link_to(name, link, class: ("user--banned" if user.banned?).to_s)
|
||||
return profile_link(user)
|
||||
end
|
||||
name.strip
|
||||
user.profile.safe_name.strip
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def profile_link(user)
|
||||
link_to(user.profile.safe_name, show_user_profile_path(user.screen_name), class: ("user--banned" if user.banned?).to_s)
|
||||
end
|
||||
|
||||
def should_unmask?(user, anonymous)
|
||||
user.present? && moderation_view? && anonymous
|
||||
end
|
||||
|
||||
def anonymous_name(context_user)
|
||||
sanitize(context_user&.profile&.anon_display_name.presence || APP_CONFIG["anonymous_name"], tags: [])
|
||||
end
|
||||
|
||||
def anonymous?(user, anonymous)
|
||||
user.nil? || anonymous
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue