discourse/app/serializers/admin_user_list_serializer.rb
Linca a3cff97b48
FEATURE: Make it easier for staff to see if a profile is silenced (#33537)
This commit make it easier for staff to see if a profile is silenced by
aligning it with how suspended notices are shown.

- The number of times a profile has been silenced is shown in the staff
counters banner at the top of the public user profiles.
- Clicking on the silenced note in the staff counters banner goes to a
filtered view of the staff action logs for the user and the silenced
action.
- The profile indicates if a user is silenced and shows the date they
are silenced until. This looks exactly the same as how it currently
displays for suspended users, with the added info of the date. This is
also displayed on the user card, the same as suspended notices currently
are.

## Screenshots


![image](https://github.com/user-attachments/assets/43cf8134-3391-43ff-98fe-fcba07c9e3dd)

![image](https://github.com/user-attachments/assets/2804dcba-70b2-4cf2-8a93-63433a23b481)
2025-07-14 12:44:31 +08:00

123 lines
2.7 KiB
Ruby

# frozen_string_literal: true
class AdminUserListSerializer < BasicUserSerializer
attributes :email,
:secondary_emails,
:active,
:admin,
:moderator,
:last_seen_at,
:last_emailed_at,
:created_at,
:last_seen_age,
:last_emailed_age,
:created_at_age,
:trust_level,
:manual_locked_trust_level,
:username,
:title,
:avatar_template,
:approved,
:suspended_at,
:suspended_till,
:silenced_till,
:time_read,
:staged,
:second_factor_enabled,
:can_be_deleted,
:silence_reason
%i[days_visited posts_read_count topics_entered post_count].each do |sym|
attributes sym
define_method sym do
object.user_stat.public_send(sym)
end
end
def include_email?
# staff members can always see their email
(scope.is_staff? && (object.id == scope.user.id || object.staged?)) ||
(@options[:emails_desired] && scope.can_check_emails?(object))
end
alias_method :include_secondary_emails?, :include_email?
alias_method :include_associated_accounts?, :include_email?
def silenced_till
object.silenced_till
end
def include_silenced_till?
object.silenced_till?
end
def include_suspended_at?
object.suspended?
end
def include_suspended_till?
object.suspended?
end
def can_impersonate
scope.can_impersonate?(object)
end
def last_emailed_at
return nil if object.last_emailed_at.blank?
object.last_emailed_at
end
def last_emailed_age
return nil if object.last_emailed_at.blank?
Time.now - object.last_emailed_at
end
def last_seen_at
return nil if object.last_seen_at.blank?
object.last_seen_at
end
def last_seen_age
return nil if object.last_seen_at.blank?
Time.now - object.last_seen_at
end
def time_read
return nil if object.user_stat.time_read.blank?
object.user_stat.time_read
end
def created_at_age
Time.now - object.created_at
end
def include_approved?
SiteSetting.must_approve_users
end
def include_second_factor_enabled?
!SiteSetting.enable_discourse_connect && SiteSetting.enable_local_logins &&
object.has_any_second_factor_methods_enabled?
end
def second_factor_enabled
true
end
def can_be_deleted
scope.can_delete_user?(object)
end
def include_can_be_deleted?
@options[:include_can_be_deleted]
end
def silence_reason
PrettyText.cleanup(object.silence_reason)
end
def include_silence_reason?
@options[:include_silence_reason]
end
end