discourse/app/serializers/admin_user_list_serializer.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

116 lines
2.5 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
class AdminUserListSerializer < BasicUserSerializer
attributes :email,
2018-07-03 07:51:22 -04:00
: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,
:flag_level,
:username,
:title,
:avatar_template,
:approved,
:suspended_at,
:suspended_till,
2017-11-10 12:18:08 -05:00
:silenced,
:silenced_till,
:time_read,
:staged,
:second_factor_enabled
%i[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)
end
end
def include_email?
# staff members can always see their email
(scope.is_staff? && (object.id == scope.user.id || object.staged?)) ||
(@options[:emails_desired] && scope.can_check_emails?(object))
end
2018-07-03 07:51:22 -04:00
alias_method :include_secondary_emails?, :include_email?
alias_method :include_associated_accounts?, :include_email?
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
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?
FEATURE: Rename 'Discourse SSO' to DiscourseConnect (#11978) The 'Discourse SSO' protocol is being rebranded to DiscourseConnect. This should help to reduce confusion when 'SSO' is used in the generic sense. This commit aims to: - Rename `sso_` site settings. DiscourseConnect specific ones are prefixed `discourse_connect_`. Generic settings are prefixed `auth_` - Add (server-side-only) backwards compatibility for the old setting names, with deprecation notices - Copy `site_settings` database records to the new names - Rename relevant translation keys - Update relevant translations This commit does **not** aim to: - Rename any Ruby classes or methods. This might be done in a future commit - Change any URLs. This would break existing integrations - Make any changes to the protocol. This would break existing integrations - Change any functionality. Further normalization across DiscourseConnect and other auth methods will be done separately The risks are: - There is no backwards compatibility for site settings on the client-side. Accessing auth-related site settings in Javascript is fairly rare, and an error on the client side would not be security-critical. - If a plugin is monkey-patching parts of the auth process, changes to locale keys could cause broken error messages. This should also be unlikely. The old site setting names remain functional, so security-related overrides will remain working. A follow-up commit will be made with a post-deploy migration to delete the old `site_settings` rows.
2021-02-08 05:04:33 -05:00
!SiteSetting.enable_discourse_connect && SiteSetting.enable_local_logins &&
object.has_any_second_factor_methods_enabled?
end
def second_factor_enabled
true
end
end