Class: CurrentUserSerializer
Instance Method Summary
collapse
#display_sidebar_tags, #include_display_sidebar_tags?, #include_sidebar_category_ids?, #include_sidebar_sections?, #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
#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
#associated_account_ids ⇒ Object
240
241
242
243
244
245
246
247
248
|
# File 'app/serializers/current_user_serializer.rb', line 240
def associated_account_ids
values = {}
object.user_associated_accounts.map do |user_associated_account|
values[user_associated_account.provider_name] = user_associated_account.provider_uid
end
values
end
|
#can_create_group ⇒ Object
107
108
109
|
# File 'app/serializers/current_user_serializer.rb', line 107
def can_create_group
scope.can_create_group?
end
|
#can_create_topic ⇒ Object
103
104
105
|
# File 'app/serializers/current_user_serializer.rb', line 103
def can_create_topic
scope.can_create_topic?(nil)
end
|
#can_delete_account ⇒ Object
147
148
149
|
# File 'app/serializers/current_user_serializer.rb', line 147
def can_delete_account
true
end
|
#can_edit ⇒ Object
123
124
125
|
# File 'app/serializers/current_user_serializer.rb', line 123
def can_edit
true
end
|
#can_invite_to_forum ⇒ Object
127
128
129
|
# File 'app/serializers/current_user_serializer.rb', line 127
def can_invite_to_forum
scope.can_invite_to_forum?
end
|
#can_review ⇒ Object
224
225
226
|
# File 'app/serializers/current_user_serializer.rb', line 224
def can_review
scope.can_see_review_queue?
end
|
#can_send_private_email_messages ⇒ Object
115
116
117
|
# File 'app/serializers/current_user_serializer.rb', line 115
def can_send_private_email_messages
scope.can_send_private_messages_to_email?
end
|
#can_send_private_messages ⇒ Object
119
120
121
|
# File 'app/serializers/current_user_serializer.rb', line 119
def can_send_private_messages
scope.can_send_private_messages?
end
|
#custom_fields ⇒ Object
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
# File 'app/serializers/current_user_serializer.rb', line 151
def custom_fields
fields = nil
if SiteSetting.public_user_custom_fields.present?
fields = SiteSetting.public_user_custom_fields.split("|")
end
DiscoursePluginRegistry.serialized_current_user_fields.each do |f|
fields ||= []
fields << f
end
if fields.present?
User.custom_fields_for_ids([object.id], fields)[object.id] || {}
else
{}
end
end
|
#dismissed_banner_key ⇒ Object
216
217
218
|
# File 'app/serializers/current_user_serializer.rb', line 216
def dismissed_banner_key
object.user_profile.dismissed_banner_key
end
|
#external_id ⇒ Object
232
233
234
|
# File 'app/serializers/current_user_serializer.rb', line 232
def external_id
object&.single_sign_on_record&.external_id
end
|
#featured_topic ⇒ Object
258
259
260
|
# File 'app/serializers/current_user_serializer.rb', line 258
def featured_topic
object.user_profile.featured_topic
end
|
#groups ⇒ Object
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'app/serializers/current_user_serializer.rb', line 86
def groups
owned_group_ids = GroupUser.where(user_id: id, owner: true).pluck(:group_id).to_set
object
.visible_groups
.pluck(:id, :name, :has_messages)
.map do |id, name, has_messages|
group = { id: id, name: name, has_messages: has_messages }
group[:owner] = true if owned_group_ids.include?(id)
group
end
end
|
#has_topic_draft ⇒ Object
262
263
264
|
# File 'app/serializers/current_user_serializer.rb', line 262
def has_topic_draft
true
end
|
#ignored_users ⇒ Object
192
193
194
|
# File 'app/serializers/current_user_serializer.rb', line 192
def ignored_users
IgnoredUser.where(user: object.id).joins(:ignored_user).pluck(:username)
end
|
#include_associated_account_ids? ⇒ Boolean
250
251
252
|
# File 'app/serializers/current_user_serializer.rb', line 250
def include_associated_account_ids?
SiteSetting.include_associated_account_ids
end
|
#include_can_create_group? ⇒ Boolean
111
112
113
|
# File 'app/serializers/current_user_serializer.rb', line 111
def include_can_create_group?
scope.can_create_group?
end
|
#include_can_delete_account? ⇒ Boolean
143
144
145
|
# File 'app/serializers/current_user_serializer.rb', line 143
def include_can_delete_account?
scope.can_delete_user?(object)
end
|
#include_can_invite_to_forum? ⇒ Boolean
131
132
133
|
# File 'app/serializers/current_user_serializer.rb', line 131
def include_can_invite_to_forum?
scope.can_invite_to_forum?
end
|
#include_external_id? ⇒ Boolean
236
237
238
|
# File 'app/serializers/current_user_serializer.rb', line 236
def include_external_id?
SiteSetting.enable_discourse_connect
end
|
#include_has_topic_draft? ⇒ Boolean
266
267
268
|
# File 'app/serializers/current_user_serializer.rb', line 266
def include_has_topic_draft?
Draft.has_topic_draft(object)
end
|
#include_no_password? ⇒ Boolean
139
140
141
|
# File 'app/serializers/current_user_serializer.rb', line 139
def include_no_password?
!object.has_password?
end
|
#include_primary_group_id? ⇒ Boolean
228
229
230
|
# File 'app/serializers/current_user_serializer.rb', line 228
def include_primary_group_id?
object.primary_group_id.present?
end
|
#include_status? ⇒ Boolean
270
271
272
|
# File 'app/serializers/current_user_serializer.rb', line 270
def include_status?
SiteSetting.enable_user_status && object.has_status?
end
|
#indirectly_muted_category_ids ⇒ Object
#is_anonymous ⇒ Object
220
221
222
|
# File 'app/serializers/current_user_serializer.rb', line 220
def is_anonymous
object.anonymous?
end
|
#link_posting_access ⇒ Object
99
100
101
|
# File 'app/serializers/current_user_serializer.rb', line 99
def link_posting_access
scope.link_posting_access
end
|
#muted_category_ids ⇒ Object
168
169
170
|
# File 'app/serializers/current_user_serializer.rb', line 168
def muted_category_ids
categories_with_notification_level(:muted)
end
|
#no_password ⇒ Object
135
136
137
|
# File 'app/serializers/current_user_serializer.rb', line 135
def no_password
true
end
|
#regular_category_ids ⇒ Object
176
177
178
|
# File 'app/serializers/current_user_serializer.rb', line 176
def regular_category_ids
categories_with_notification_level(:regular)
end
|
#second_factor_enabled ⇒ Object
254
255
256
|
# File 'app/serializers/current_user_serializer.rb', line 254
def second_factor_enabled
object.totp_enabled? || object.security_keys_enabled?
end
|
77
78
79
80
81
82
83
84
|
# File 'app/serializers/current_user_serializer.rb', line 77
def
SidebarSection
.public_sections
.or(SidebarSection.where(user_id: object.id))
.includes(:sidebar_urls)
.order("(section_type IS NOT NULL) DESC, (public IS TRUE) DESC")
.map { |section| SidebarSectionSerializer.new(section, root: false) }
end
|
#status ⇒ Object
274
275
276
|
# File 'app/serializers/current_user_serializer.rb', line 274
def status
UserStatusSerializer.new(object.user_status, root: false)
end
|
#top_category_ids ⇒ Object
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
# File 'app/serializers/current_user_serializer.rb', line 196
def top_category_ids
omitted_notification_levels = [
CategoryUser.notification_levels[:muted],
CategoryUser.notification_levels[:regular],
]
CategoryUser
.where(user_id: object.id)
.where.not(notification_level: omitted_notification_levels)
.order(
"
CASE
WHEN notification_level = 3 THEN 1
WHEN notification_level = 2 THEN 2
WHEN notification_level = 4 THEN 3
END",
)
.pluck(:category_id)
.slice(0, SiteSetting.)
end
|
#tracked_category_ids ⇒ Object
180
181
182
|
# File 'app/serializers/current_user_serializer.rb', line 180
def tracked_category_ids
categories_with_notification_level(:tracking)
end
|
#unseen_reviewable_count ⇒ Object
#watched_category_ids ⇒ Object
184
185
186
|
# File 'app/serializers/current_user_serializer.rb', line 184
def watched_category_ids
categories_with_notification_level(:watching)
end
|
#watched_first_post_category_ids ⇒ Object
188
189
190
|
# File 'app/serializers/current_user_serializer.rb', line 188
def watched_first_post_category_ids
categories_with_notification_level(:watching_first_post)
end
|