2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-11-27 02:56:12 +08:00
|
|
|
class AdminUserListSerializer < BasicUserSerializer
|
|
|
|
|
|
|
|
attributes :email,
|
2018-07-03 19:51:22 +08:00
|
|
|
:secondary_emails,
|
2014-11-27 02:56:12 +08:00
|
|
|
:active,
|
|
|
|
:admin,
|
|
|
|
:moderator,
|
2014-12-20 17:24:16 +08:00
|
|
|
:last_seen_at,
|
|
|
|
:last_emailed_at,
|
|
|
|
:created_at,
|
2014-11-27 02:56:12 +08:00
|
|
|
:last_seen_age,
|
|
|
|
:last_emailed_age,
|
|
|
|
:created_at_age,
|
|
|
|
:trust_level,
|
2017-11-24 04:55:44 +08:00
|
|
|
:manual_locked_trust_level,
|
2014-11-27 02:56:12 +08:00
|
|
|
:flag_level,
|
|
|
|
:username,
|
|
|
|
:title,
|
|
|
|
:avatar_template,
|
|
|
|
:approved,
|
|
|
|
:suspended_at,
|
|
|
|
:suspended_till,
|
2017-11-11 01:18:08 +08:00
|
|
|
:silenced,
|
2017-11-14 02:41:36 +08:00
|
|
|
:silenced_till,
|
2016-01-19 23:41:07 +08:00
|
|
|
:time_read,
|
2018-02-22 08:59:11 +08:00
|
|
|
:staged,
|
|
|
|
:second_factor_enabled
|
2014-11-27 02:56:12 +08:00
|
|
|
|
|
|
|
[:days_visited, :posts_read_count, :topics_entered, :post_count].each do |sym|
|
|
|
|
attributes sym
|
|
|
|
define_method sym do
|
2019-05-07 09:27:05 +08:00
|
|
|
object.user_stat.public_send(sym)
|
2014-11-27 02:56:12 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_email?
|
|
|
|
# staff members can always see their email
|
2018-12-19 17:24:57 +08:00
|
|
|
(scope.is_staff? && (object.id == scope.user.id || object.staged?)) ||
|
2019-01-18 22:26:44 +08:00
|
|
|
(@options[:emails_desired] && scope.can_check_emails?(object))
|
2014-11-27 02:56:12 +08:00
|
|
|
end
|
|
|
|
|
2018-07-03 19:51:22 +08:00
|
|
|
alias_method :include_secondary_emails?, :include_email?
|
2014-11-27 02:56:12 +08:00
|
|
|
alias_method :include_associated_accounts?, :include_email?
|
|
|
|
|
2017-11-14 02:41:36 +08:00
|
|
|
def silenced
|
|
|
|
object.silenced?
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_silenced?
|
|
|
|
object.silenced?
|
|
|
|
end
|
|
|
|
|
|
|
|
def silenced_till
|
|
|
|
object.silenced_till
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_silenced_till?
|
|
|
|
object.silenced_till?
|
|
|
|
end
|
|
|
|
|
2017-10-14 00:17:26 +08:00
|
|
|
def include_suspended_at?
|
|
|
|
object.suspended?
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_suspended_till?
|
|
|
|
object.suspended?
|
|
|
|
end
|
|
|
|
|
2014-11-27 02:56:12 +08:00
|
|
|
def can_impersonate
|
|
|
|
scope.can_impersonate?(object)
|
|
|
|
end
|
2016-01-19 23:41:07 +08:00
|
|
|
|
2014-12-20 17:24:16 +08:00
|
|
|
def last_emailed_at
|
|
|
|
return nil if object.last_emailed_at.blank?
|
|
|
|
object.last_emailed_at
|
|
|
|
end
|
2014-11-27 02:56:12 +08:00
|
|
|
|
|
|
|
def last_emailed_age
|
|
|
|
return nil if object.last_emailed_at.blank?
|
2017-11-18 06:08:49 +08:00
|
|
|
Time.now - object.last_emailed_at
|
2014-11-27 02:56:12 +08:00
|
|
|
end
|
2016-01-19 23:41:07 +08:00
|
|
|
|
2014-12-20 17:24:16 +08:00
|
|
|
def last_seen_at
|
|
|
|
return nil if object.last_seen_at.blank?
|
|
|
|
object.last_seen_at
|
|
|
|
end
|
2014-11-27 02:56:12 +08:00
|
|
|
|
|
|
|
def last_seen_age
|
|
|
|
return nil if object.last_seen_at.blank?
|
2017-11-18 06:08:49 +08:00
|
|
|
Time.now - object.last_seen_at
|
2014-11-27 02:56:12 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def time_read
|
|
|
|
return nil if object.user_stat.time_read.blank?
|
2017-11-18 06:08:49 +08:00
|
|
|
object.user_stat.time_read
|
2014-11-27 02:56:12 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def created_at_age
|
2017-11-18 06:08:49 +08:00
|
|
|
Time.now - object.created_at
|
2014-11-27 02:56:12 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def include_approved?
|
|
|
|
SiteSetting.must_approve_users
|
|
|
|
end
|
|
|
|
|
2018-02-22 08:59:11 +08:00
|
|
|
def include_second_factor_enabled?
|
2021-02-08 18:04:33 +08:00
|
|
|
!SiteSetting.enable_discourse_connect &&
|
2019-03-15 14:59:16 +08:00
|
|
|
SiteSetting.enable_local_logins &&
|
2020-02-03 12:37:46 +08:00
|
|
|
object.has_any_second_factor_methods_enabled?
|
2018-02-22 08:59:11 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def second_factor_enabled
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2014-11-27 02:56:12 +08:00
|
|
|
end
|