0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-06 13:08:40 +08:00
discourse/app/serializers/admin_user_list_serializer.rb
Régis Hanol a1ebd19813
FEATURE: Bulk suspend users and filter the admin users list by activation (#41227)
- Adds an activation filter (All / Activated / Not activated) to the
Admin > Users > New tab so unverified accounts can be isolated in the
UI.
- Adds a bulk suspend action next to the existing bulk delete, plus a
"Select all" / "Clear all" control so a whole page of accounts can be
actioned at once.
- Shows the suspend reason on the Suspended tab, mirroring the silenced
tab.

Already-suspended users are excluded from bulk suspension, and the
penalty-reason columns are populated from a single batched query instead
of one query per row.

**SCREENSHOTS**

<img width="1400" height="1200"
alt="desktop-horizon-light-admin-users-activation-filter"
src="https://github.com/user-attachments/assets/31165d10-42cb-479b-897c-fafeb3283526"
/>
<img width="1400" height="1200"
alt="desktop-horizon-light-admin-users-bulk-select"
src="https://github.com/user-attachments/assets/037e8149-2ac6-40de-aaae-0d0e443ec143"
/>
<img width="1400" height="1200"
alt="desktop-horizon-light-admin-users-suspended"
src="https://github.com/user-attachments/assets/e6dbefed-4aaf-49bb-a9bd-52c7253e14b6"
/>
<img width="1400" height="1200"
alt="desktop-horizon-light-admin-users-bulk-suspend"
src="https://github.com/user-attachments/assets/5bdf85ef-4e30-4d8d-b521-d8639c1a2b97"
/>
2026-06-29 11:26:34 +02:00

145 lines
3.2 KiB
Ruby
Vendored

# 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,
:can_be_suspended,
:silence_reason,
:suspend_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
return true if scope.is_staff? && object.id == scope.user.id
staged_or_desired = object.staged? || @options[:emails_desired]
return true if staged_or_desired && scope.can_check_emails?(object)
false
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 can_be_suspended
scope.can_suspend?(object) && !object.suspended?
end
def include_can_be_suspended?
@options[:include_can_be_suspended]
end
def silence_reason
User.format_penalty_reason(@options[:silence_reasons].to_h[object.id])
end
def include_silence_reason?
@options[:include_silence_reason]
end
def suspend_reason
User.format_penalty_reason(@options[:suspend_reasons].to_h[object.id])
end
def include_suspend_reason?
@options[:include_suspend_reason]
end
end