2013-02-06 03:16:51 +08:00
|
|
|
class AdminUserSerializer < BasicUserSerializer
|
|
|
|
|
2013-02-07 23:45:24 +08:00
|
|
|
attributes :email,
|
|
|
|
:active,
|
|
|
|
:admin,
|
2013-04-05 04:14:55 +08:00
|
|
|
:moderator,
|
2013-02-07 23:45:24 +08:00
|
|
|
:last_seen_age,
|
2013-02-06 03:16:51 +08:00
|
|
|
:last_emailed_age,
|
2013-02-07 23:45:24 +08:00
|
|
|
:created_at_age,
|
2013-02-06 03:16:51 +08:00
|
|
|
:username_lower,
|
|
|
|
:trust_level,
|
2014-09-30 11:12:33 +08:00
|
|
|
:trust_level_locked,
|
2013-02-06 03:16:51 +08:00
|
|
|
:flag_level,
|
2013-02-07 23:45:24 +08:00
|
|
|
:username,
|
2013-06-26 06:39:20 +08:00
|
|
|
:title,
|
2013-02-06 03:16:51 +08:00
|
|
|
:avatar_template,
|
|
|
|
:can_approve,
|
|
|
|
:approved,
|
2013-11-08 02:53:32 +08:00
|
|
|
:suspended_at,
|
|
|
|
:suspended_till,
|
|
|
|
:suspended,
|
2013-05-08 09:58:34 +08:00
|
|
|
:ip_address,
|
2014-04-30 02:37:56 +08:00
|
|
|
:registration_ip_address,
|
2013-05-08 09:58:34 +08:00
|
|
|
:can_send_activation_email,
|
|
|
|
:can_activate,
|
2013-05-31 23:41:40 +08:00
|
|
|
:can_deactivate,
|
2013-10-04 11:28:49 +08:00
|
|
|
:blocked,
|
2014-09-25 13:50:54 +08:00
|
|
|
:time_read,
|
|
|
|
:associated_accounts
|
2013-10-04 11:28:49 +08:00
|
|
|
|
2014-08-23 08:34:48 +08:00
|
|
|
has_one :single_sign_on_record, serializer: SingleSignOnRecordSerializer, embed: :objects
|
|
|
|
|
2013-10-04 11:28:49 +08:00
|
|
|
[:days_visited,:posts_read_count,:topics_entered].each do |sym|
|
|
|
|
attributes sym
|
|
|
|
define_method sym do
|
|
|
|
object.user_stat.send(sym)
|
|
|
|
end
|
|
|
|
end
|
2013-02-06 03:16:51 +08:00
|
|
|
|
2014-09-30 04:31:05 +08:00
|
|
|
def include_email?
|
|
|
|
# staff members can always see their email
|
2014-11-03 19:46:08 +08:00
|
|
|
(scope.is_staff? && object.id == scope.user.id) || scope.can_see_emails?
|
2014-09-30 04:31:05 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
alias_method :include_associated_accounts?, :include_email?
|
|
|
|
|
2013-11-08 02:53:32 +08:00
|
|
|
def suspended
|
|
|
|
object.suspended?
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_impersonate
|
|
|
|
scope.can_impersonate?(object)
|
|
|
|
end
|
|
|
|
|
|
|
|
def last_emailed_age
|
|
|
|
return nil if object.last_emailed_at.blank?
|
|
|
|
AgeWords.age_words(Time.now - object.last_emailed_at)
|
|
|
|
end
|
|
|
|
|
|
|
|
def last_seen_age
|
|
|
|
return nil if object.last_seen_at.blank?
|
|
|
|
AgeWords.age_words(Time.now - object.last_seen_at)
|
|
|
|
end
|
|
|
|
|
|
|
|
def time_read
|
2013-10-04 11:28:49 +08:00
|
|
|
return nil if object.user_stat.time_read.blank?
|
|
|
|
AgeWords.age_words(object.user_stat.time_read)
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def created_at_age
|
|
|
|
AgeWords.age_words(Time.now - object.created_at)
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_approve
|
|
|
|
scope.can_approve?(object)
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_can_approve?
|
|
|
|
SiteSetting.must_approve_users
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_approved?
|
|
|
|
SiteSetting.must_approve_users
|
|
|
|
end
|
|
|
|
|
2013-05-08 09:58:34 +08:00
|
|
|
def can_send_activation_email
|
|
|
|
scope.can_send_activation_email?(object)
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_activate
|
|
|
|
scope.can_activate?(object)
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_deactivate
|
|
|
|
scope.can_deactivate?(object)
|
|
|
|
end
|
|
|
|
|
2013-11-06 04:00:47 +08:00
|
|
|
def ip_address
|
|
|
|
object.ip_address.try(:to_s)
|
|
|
|
end
|
|
|
|
|
2014-04-30 02:37:56 +08:00
|
|
|
def registration_ip_address
|
|
|
|
object.registration_ip_address.try(:to_s)
|
|
|
|
end
|
|
|
|
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|