2019-05-02 17:17:27 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-02-05 13:16:51 -06:00
|
|
|
class AdminDetailedUserSerializer < AdminUserSerializer
|
|
|
|
attributes :moderator,
|
2013-02-07 09:45:24 -06:00
|
|
|
:can_grant_admin,
|
2013-02-05 13:16:51 -06:00
|
|
|
:can_revoke_admin,
|
2013-02-12 16:58:08 -06:00
|
|
|
:can_grant_moderation,
|
|
|
|
:can_revoke_moderation,
|
|
|
|
:can_impersonate,
|
2013-02-05 13:16:51 -06:00
|
|
|
:like_count,
|
2014-08-22 14:23:10 -05:00
|
|
|
:like_given_count,
|
2013-02-05 13:16:51 -06:00
|
|
|
:post_count,
|
2013-07-26 14:40:08 -05:00
|
|
|
:topic_count,
|
2021-08-02 09:15:53 -05:00
|
|
|
:post_edits_count,
|
2013-02-05 13:16:51 -06:00
|
|
|
:flags_given_count,
|
|
|
|
:flags_received_count,
|
2013-02-07 01:11:56 -06:00
|
|
|
:private_topics_count,
|
2013-07-26 14:40:08 -05:00
|
|
|
:can_delete_all_posts,
|
2013-11-01 09:47:03 -05:00
|
|
|
:can_be_deleted,
|
2015-03-06 15:44:54 -06:00
|
|
|
:can_be_anonymized,
|
2020-04-22 07:12:09 -05:00
|
|
|
:can_be_merged,
|
2017-12-07 12:20:42 -06:00
|
|
|
:full_suspend_reason,
|
2017-09-13 15:44:47 -05:00
|
|
|
:suspended_till,
|
2017-11-13 12:41:36 -06:00
|
|
|
:silence_reason,
|
2021-07-12 13:36:56 -05:00
|
|
|
:penalty_counts,
|
|
|
|
:next_penalty,
|
2014-04-16 05:22:21 -05:00
|
|
|
:primary_group_id,
|
2014-09-08 10:11:56 -05:00
|
|
|
:badge_count,
|
2014-09-26 13:48:34 -05:00
|
|
|
:warnings_received_count,
|
2016-05-06 12:34:33 -05:00
|
|
|
:user_fields,
|
|
|
|
:bounce_score,
|
2017-02-21 06:45:30 -06:00
|
|
|
:reset_bounce_score_after,
|
2017-12-21 19:18:12 -06:00
|
|
|
:can_view_action_logs,
|
|
|
|
:second_factor_enabled,
|
2019-11-05 08:10:23 -06:00
|
|
|
:can_disable_second_factor,
|
2020-09-15 09:00:10 -05:00
|
|
|
:can_delete_sso_record,
|
2022-03-03 10:17:02 -06:00
|
|
|
:api_key_count,
|
2022-12-08 06:42:33 -06:00
|
|
|
:external_ids,
|
|
|
|
:similar_users,
|
|
|
|
:similar_users_count
|
2013-02-05 13:16:51 -06:00
|
|
|
|
|
|
|
has_one :approved_by, serializer: BasicUserSerializer, embed: :objects
|
2013-11-07 12:53:32 -06:00
|
|
|
has_one :suspended_by, serializer: BasicUserSerializer, embed: :objects
|
2017-11-13 12:41:36 -06:00
|
|
|
has_one :silenced_by, serializer: BasicUserSerializer, embed: :objects
|
2014-09-24 19:19:26 -05:00
|
|
|
has_one :tl3_requirements, serializer: TrustLevel3RequirementsSerializer, embed: :objects
|
2014-07-13 13:11:38 -05:00
|
|
|
has_many :groups, embed: :object, serializer: BasicGroupSerializer
|
2013-02-05 13:16:51 -06:00
|
|
|
|
2018-02-20 00:44:51 -06:00
|
|
|
def second_factor_enabled
|
2022-12-07 16:41:22 -06:00
|
|
|
object.totp_enabled? || object.security_keys_enabled?
|
2017-12-21 19:18:12 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_disable_second_factor
|
2020-07-07 14:19:30 -05:00
|
|
|
scope.is_admin? && (object&.id != scope.user.id)
|
2017-12-21 19:18:12 -06:00
|
|
|
end
|
|
|
|
|
2013-02-05 13:16:51 -06:00
|
|
|
def can_revoke_admin
|
|
|
|
scope.can_revoke_admin?(object)
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_grant_admin
|
|
|
|
scope.can_grant_admin?(object)
|
|
|
|
end
|
2013-02-07 09:45:24 -06:00
|
|
|
|
2013-02-12 16:58:08 -06:00
|
|
|
def can_revoke_moderation
|
|
|
|
scope.can_revoke_moderation?(object)
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_grant_moderation
|
|
|
|
scope.can_grant_moderation?(object)
|
|
|
|
end
|
|
|
|
|
2013-02-07 01:11:56 -06:00
|
|
|
def can_delete_all_posts
|
|
|
|
scope.can_delete_all_posts?(object)
|
|
|
|
end
|
2013-02-05 13:16:51 -06:00
|
|
|
|
2013-07-26 14:40:08 -05:00
|
|
|
def can_be_deleted
|
|
|
|
scope.can_delete_user?(object)
|
|
|
|
end
|
|
|
|
|
2015-03-06 15:44:54 -06:00
|
|
|
def can_be_anonymized
|
|
|
|
scope.can_anonymize_user?(object)
|
|
|
|
end
|
|
|
|
|
2020-04-22 07:12:09 -05:00
|
|
|
def can_be_merged
|
|
|
|
scope.can_merge_user?(object)
|
|
|
|
end
|
|
|
|
|
2013-07-26 14:40:08 -05:00
|
|
|
def topic_count
|
|
|
|
object.topics.count
|
|
|
|
end
|
|
|
|
|
2013-10-22 14:53:08 -05:00
|
|
|
def include_api_key?
|
2015-10-14 14:40:23 -05:00
|
|
|
scope.is_admin? && api_key.present?
|
2013-10-22 14:53:08 -05:00
|
|
|
end
|
|
|
|
|
2013-11-07 12:53:32 -06:00
|
|
|
def suspended_by
|
|
|
|
object.suspend_record.try(:acting_user)
|
2013-11-01 09:47:03 -05:00
|
|
|
end
|
|
|
|
|
2017-11-13 12:41:36 -06:00
|
|
|
def silence_reason
|
|
|
|
object.silence_reason
|
|
|
|
end
|
|
|
|
|
2021-07-12 13:36:56 -05:00
|
|
|
def penalty_counts
|
|
|
|
TrustLevel3Requirements.new(object).penalty_counts
|
|
|
|
end
|
|
|
|
|
|
|
|
def next_penalty
|
|
|
|
step_number = penalty_counts.total
|
2023-01-09 06:20:10 -06:00
|
|
|
steps = SiteSetting.penalty_step_hours.split("|")
|
2021-07-12 13:36:56 -05:00
|
|
|
step_number = [step_number, steps.length].min
|
|
|
|
penalty_hours = steps[step_number]
|
|
|
|
Integer(penalty_hours, 10).hours.from_now
|
2023-01-09 06:20:10 -06:00
|
|
|
rescue StandardError
|
2021-07-12 13:36:56 -05:00
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
2017-11-13 12:41:36 -06:00
|
|
|
def silenced_by
|
|
|
|
object.silenced_record.try(:acting_user)
|
|
|
|
end
|
|
|
|
|
2014-09-24 19:19:26 -05:00
|
|
|
def include_tl3_requirements?
|
2014-09-05 00:20:39 -05:00
|
|
|
object.has_trust_level?(TrustLevel[2])
|
2014-01-22 16:09:56 -06:00
|
|
|
end
|
|
|
|
|
2014-09-26 13:48:34 -05:00
|
|
|
def include_user_fields?
|
|
|
|
object.user_fields.present?
|
|
|
|
end
|
|
|
|
|
2016-05-06 12:34:33 -05:00
|
|
|
def bounce_score
|
|
|
|
object.user_stat.bounce_score
|
|
|
|
end
|
|
|
|
|
|
|
|
def reset_bounce_score_after
|
|
|
|
object.user_stat.reset_bounce_score_after
|
|
|
|
end
|
|
|
|
|
2017-02-21 06:45:30 -06:00
|
|
|
def can_view_action_logs
|
|
|
|
scope.can_view_action_logs?(object)
|
|
|
|
end
|
|
|
|
|
2017-03-17 16:01:45 -05:00
|
|
|
def post_count
|
|
|
|
object.posts.count
|
|
|
|
end
|
|
|
|
|
2019-11-05 08:10:23 -06:00
|
|
|
def api_key_count
|
|
|
|
object.api_keys.active.count
|
|
|
|
end
|
2020-09-15 09:00:10 -05:00
|
|
|
|
2022-03-03 10:17:02 -06:00
|
|
|
def external_ids
|
|
|
|
external_ids = {}
|
|
|
|
|
|
|
|
object.user_associated_accounts.map do |user_associated_account|
|
|
|
|
external_ids[user_associated_account.provider_name] = user_associated_account.provider_uid
|
|
|
|
end
|
|
|
|
|
|
|
|
external_ids
|
|
|
|
end
|
|
|
|
|
2022-12-08 06:42:33 -06:00
|
|
|
def similar_users
|
|
|
|
ActiveModel::ArraySerializer.new(
|
|
|
|
@options[:similar_users],
|
|
|
|
each_serializer: SimilarAdminUserSerializer,
|
|
|
|
scope: scope,
|
|
|
|
root: false,
|
|
|
|
).as_json
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_similar_users?
|
|
|
|
@options[:similar_users].present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def similar_users_count
|
|
|
|
@options[:similar_users_count]
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_similar_users_count?
|
|
|
|
@options[:similar_users].present?
|
|
|
|
end
|
|
|
|
|
2020-09-15 09:00:10 -05:00
|
|
|
def can_delete_sso_record
|
|
|
|
scope.can_delete_sso_record?(object)
|
|
|
|
end
|
2013-02-05 13:16:51 -06:00
|
|
|
end
|