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