Class: UserSerializer
Instance Attribute Summary
#topic_post_count
Instance Method Summary
collapse
#display_sidebar_tags, #include_display_sidebar_tags?, #include_sidebar_tags?, #sidebar_category_ids, #sidebar_tags
#serialize_tags
#muted_tags, #regular_tags, #tag_user_notification_levels, #tags_with_notification_level, #tracked_tags, #watched_tags, #watching_first_post_tags
#bio_excerpt, #can_ignore_user, #can_mute_user, #can_send_private_message_to_user, #can_send_private_messages, #card_background_upload_url, #custom_fields, #featured_topic, #flair_bg_color, #flair_color, #flair_name, #flair_url, #ignored, #include_email?, #include_pending_posts_count?, #include_suspend_reason?, #include_suspended_till?, #include_timezone?, #include_topic_post_count?, #include_user_fields?, #initialize, #location, #muted, #primary_group_name, private_attributes, #recent_time_read, staff_attributes, #time_read, #timezone, untrusted_attributes, #user_fields, #website, #website_name
#include_status?, included, #status
#avatar_template, #categories_with_notification_level, #category_user_notification_levels, #include_name?, #name, #user, #user_is_current_user
expire_cache_fragment!, fragment_cache
#include!
Instance Method Details
#allowed_pm_usernames ⇒ Object
279
280
281
|
# File 'app/serializers/user_serializer.rb', line 279
def allowed_pm_usernames
AllowedPmUser.where(user_id: object.id).joins(:allowed_pm_user).pluck(:username)
end
|
#bio_cooked ⇒ Object
196
197
198
|
# File 'app/serializers/user_serializer.rb', line 196
def bio_cooked
object.user_profile.bio_processed
end
|
#bio_raw ⇒ Object
192
193
194
|
# File 'app/serializers/user_serializer.rb', line 192
def bio_raw
object.user_profile.bio_raw
end
|
#can_be_deleted ⇒ Object
232
233
234
|
# File 'app/serializers/user_serializer.rb', line 232
def can_be_deleted
scope.can_delete_user?(object)
end
|
#can_change_bio ⇒ Object
136
137
138
|
# File 'app/serializers/user_serializer.rb', line 136
def can_change_bio
!(SiteSetting.enable_discourse_connect && SiteSetting.discourse_connect_overrides_bio)
end
|
#can_change_location ⇒ Object
140
141
142
|
# File 'app/serializers/user_serializer.rb', line 140
def can_change_location
!(SiteSetting.enable_discourse_connect && SiteSetting.discourse_connect_overrides_location)
end
|
#can_change_tracking_preferences ⇒ Object
148
149
150
|
# File 'app/serializers/user_serializer.rb', line 148
def can_change_tracking_preferences
scope.can_change_tracking_preferences?(object)
end
|
#can_change_website ⇒ Object
144
145
146
|
# File 'app/serializers/user_serializer.rb', line 144
def can_change_website
!(SiteSetting.enable_discourse_connect && SiteSetting.discourse_connect_overrides_website)
end
|
#can_delete_all_posts ⇒ Object
236
237
238
|
# File 'app/serializers/user_serializer.rb', line 236
def can_delete_all_posts
scope.can_delete_all_posts?(object)
end
|
#can_edit ⇒ Object
200
201
202
|
# File 'app/serializers/user_serializer.rb', line 200
def can_edit
scope.can_edit?(object)
end
|
#can_edit_email ⇒ Object
208
209
210
|
# File 'app/serializers/user_serializer.rb', line 208
def can_edit_email
scope.can_edit_email?(object)
end
|
#can_edit_name ⇒ Object
212
213
214
|
# File 'app/serializers/user_serializer.rb', line 212
def can_edit_name
scope.can_edit_name?(object)
end
|
#can_edit_username ⇒ Object
204
205
206
|
# File 'app/serializers/user_serializer.rb', line 204
def can_edit_username
scope.can_edit_username?(object)
end
|
#can_ignore_users ⇒ Object
275
276
277
|
# File 'app/serializers/user_serializer.rb', line 275
def can_ignore_users
scope.can_ignore_users?
end
|
#can_mute_users ⇒ Object
267
268
269
|
# File 'app/serializers/user_serializer.rb', line 267
def can_mute_users
scope.can_mute_users?
end
|
#can_pick_theme_with_custom_homepage ⇒ Object
216
217
218
|
# File 'app/serializers/user_serializer.rb', line 216
def
scope.(object)
end
|
#can_upload_user_card_background ⇒ Object
220
221
222
|
# File 'app/serializers/user_serializer.rb', line 220
def can_upload_user_card_background
scope.can_upload_user_card_background?(object)
end
|
#custom_avatar_template ⇒ Object
319
320
321
|
# File 'app/serializers/user_serializer.rb', line 319
def custom_avatar_template
User.avatar_template(object.username, object.user_avatar.custom_upload_id)
end
|
#custom_avatar_upload_id ⇒ Object
311
312
313
|
# File 'app/serializers/user_serializer.rb', line 311
def custom_avatar_upload_id
object.user_avatar.custom_upload_id
end
|
#gravatar_avatar_template ⇒ Object
303
304
305
|
# File 'app/serializers/user_serializer.rb', line 303
def gravatar_avatar_template
User.avatar_template(object.username, object.user_avatar.gravatar_upload_id)
end
|
#gravatar_avatar_upload_id ⇒ Object
295
296
297
|
# File 'app/serializers/user_serializer.rb', line 295
def gravatar_avatar_upload_id
object.user_avatar.gravatar_upload_id
end
|
#group_users ⇒ Object
100
101
102
|
# File 'app/serializers/user_serializer.rb', line 100
def group_users
object.group_users.order(:group_id)
end
|
#groups ⇒ Object
92
93
94
95
96
97
98
|
# File 'app/serializers/user_serializer.rb', line 92
def groups
if scope.user == object
object.groups.order(:id).visible_groups(scope.user)
else
object.groups.order(:id).visible_groups(scope.user).members_visible_groups(scope.user)
end
end
|
#has_title_badges ⇒ Object
323
324
325
|
# File 'app/serializers/user_serializer.rb', line 323
def has_title_badges
object.badges.where(allow_title: true).exists?
end
|
#ignored_usernames ⇒ Object
271
272
273
|
# File 'app/serializers/user_serializer.rb', line 271
def ignored_usernames
IgnoredUser.where(user_id: object.id).joins(:ignored_user).pluck(:username)
end
|
#include_associated_accounts? ⇒ Boolean
108
109
110
|
# File 'app/serializers/user_serializer.rb', line 108
def include_associated_accounts?
user_is_current_user
end
|
#include_custom_avatar_template? ⇒ Boolean
315
316
317
|
# File 'app/serializers/user_serializer.rb', line 315
def include_custom_avatar_template?
include_custom_avatar_upload_id?
end
|
#include_custom_avatar_upload_id? ⇒ Boolean
307
308
309
|
# File 'app/serializers/user_serializer.rb', line 307
def include_custom_avatar_upload_id?
object.user_avatar&.custom_upload_id
end
|
#include_gravatar_avatar_template? ⇒ Boolean
299
300
301
|
# File 'app/serializers/user_serializer.rb', line 299
def include_gravatar_avatar_template?
include_gravatar_avatar_upload_id?
end
|
#include_gravatar_avatar_upload_id? ⇒ Boolean
291
292
293
|
# File 'app/serializers/user_serializer.rb', line 291
def include_gravatar_avatar_upload_id?
object.user_avatar&.gravatar_upload_id
end
|
#include_group_users? ⇒ Boolean
104
105
106
|
# File 'app/serializers/user_serializer.rb', line 104
def include_group_users?
user_is_current_user || scope.is_admin?
end
|
#include_second_factor_backup_enabled? ⇒ Boolean
120
121
122
|
# File 'app/serializers/user_serializer.rb', line 120
def include_second_factor_backup_enabled?
user_is_current_user
end
|
#include_second_factor_enabled? ⇒ Boolean
112
113
114
|
# File 'app/serializers/user_serializer.rb', line 112
def include_second_factor_enabled?
user_is_current_user || scope.is_admin?
end
|
#include_second_factor_remaining_backup_codes? ⇒ Boolean
128
129
130
|
# File 'app/serializers/user_serializer.rb', line 128
def include_second_factor_remaining_backup_codes?
user_is_current_user && object.backup_codes_enabled?
end
|
#include_user_option? ⇒ Boolean
30
31
32
|
# File 'app/serializers/user_serializer.rb', line 30
def include_user_option?
can_edit
end
|
#include_user_passkeys? ⇒ Boolean
188
189
190
|
# File 'app/serializers/user_serializer.rb', line 188
def include_user_passkeys?
SiteSetting.enable_passkeys? && user_is_current_user
end
|
#mailing_list_posts_per_day ⇒ Object
#muted_category_ids ⇒ Object
243
244
245
|
# File 'app/serializers/user_serializer.rb', line 243
def muted_category_ids
categories_with_notification_level(:muted)
end
|
#muted_usernames ⇒ Object
263
264
265
|
# File 'app/serializers/user_serializer.rb', line 263
def muted_usernames
MutedUser.where(user_id: object.id).joins(:muted_user).pluck(:username)
end
|
#pending_count ⇒ Object
327
328
329
|
# File 'app/serializers/user_serializer.rb', line 327
def pending_count
0
end
|
#post_count ⇒ Object
228
229
230
|
# File 'app/serializers/user_serializer.rb', line 228
def post_count
object.user_stat.try(:post_count)
end
|
#profile_background_upload_url ⇒ Object
335
336
337
|
# File 'app/serializers/user_serializer.rb', line 335
def profile_background_upload_url
object.profile_background_upload&.url
end
|
#profile_view_count ⇒ Object
331
332
333
|
# File 'app/serializers/user_serializer.rb', line 331
def profile_view_count
object.user_profile.views
end
|
#regular_category_ids ⇒ Object
247
248
249
|
# File 'app/serializers/user_serializer.rb', line 247
def regular_category_ids
categories_with_notification_level(:regular)
end
|
#second_factor_backup_enabled ⇒ Object
124
125
126
|
# File 'app/serializers/user_serializer.rb', line 124
def second_factor_backup_enabled
object.backup_codes_enabled?
end
|
#second_factor_enabled ⇒ Object
116
117
118
|
# File 'app/serializers/user_serializer.rb', line 116
def second_factor_enabled
object.totp_enabled? || object.security_keys_enabled?
end
|
#second_factor_remaining_backup_codes ⇒ Object
132
133
134
|
# File 'app/serializers/user_serializer.rb', line 132
def second_factor_remaining_backup_codes
object.remaining_backup_codes
end
|
#system_avatar_template ⇒ Object
287
288
289
|
# File 'app/serializers/user_serializer.rb', line 287
def system_avatar_template
User.system_avatar_template(object.username)
end
|
#system_avatar_upload_id ⇒ Object
283
284
285
|
# File 'app/serializers/user_serializer.rb', line 283
def system_avatar_upload_id
end
|
#tracked_category_ids ⇒ Object
251
252
253
|
# File 'app/serializers/user_serializer.rb', line 251
def tracked_category_ids
categories_with_notification_level(:tracking)
end
|
#use_logo_small_as_avatar ⇒ Object
339
340
341
342
|
# File 'app/serializers/user_serializer.rb', line 339
def use_logo_small_as_avatar
object.is_system_user? && SiteSetting.logo_small &&
SiteSetting.use_site_small_logo_as_system_avatar
end
|
#user_api_keys ⇒ Object
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
# File 'app/serializers/user_serializer.rb', line 152
def user_api_keys
keys =
object
.user_api_keys
.where(revoked_at: nil)
.map do |k|
{
id: k.id,
application_name: k.client.application_name,
scopes: k.scopes.map { |s| I18n.t("user_api_key.scopes.#{s.name}") },
created_at: k.created_at,
last_used_at: k.last_used_at,
}
end
keys.sort! { |a, b| a[:last_used_at].to_time <=> b[:last_used_at].to_time }
keys.length > 0 ? keys : nil
end
|
#user_auth_tokens ⇒ Object
171
172
173
174
175
176
177
|
# File 'app/serializers/user_serializer.rb', line 171
def user_auth_tokens
ActiveModel::ArraySerializer.new(
object.user_auth_tokens,
each_serializer: UserAuthTokenSerializer,
scope: scope,
)
end
|
#user_notification_schedule ⇒ Object
#user_passkeys ⇒ Object
179
180
181
182
183
184
185
186
|
# File 'app/serializers/user_serializer.rb', line 179
def user_passkeys
UserSecurityKey
.where(user_id: object.id, factor_type: UserSecurityKey.factor_types[:first_factor])
.order("created_at ASC")
.map do |usk|
{ id: usk.id, name: usk.name, last_used: usk.last_used, created_at: usk.created_at }
end
end
|
#watched_category_ids ⇒ Object
255
256
257
|
# File 'app/serializers/user_serializer.rb', line 255
def watched_category_ids
categories_with_notification_level(:watching)
end
|
#watched_first_post_category_ids ⇒ Object
259
260
261
|
# File 'app/serializers/user_serializer.rb', line 259
def watched_first_post_category_ids
categories_with_notification_level(:watching_first_post)
end
|