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