diff options
author | Claire <claire.github-309c@sitedethib.com> | 2023-01-25 19:55:40 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-25 19:55:40 +0100 |
commit | 13a2abacc8f943e2b1d2da63551443887e1065b0 (patch) | |
tree | 71928da85c055d2cee7eb008a699c657cd25cfaf /app | |
parent | e5ae75bf6a88ff70570df43635e75db904e40a50 (diff) |
Add `roles` attribute to Account entities in REST API (#23255)
Diffstat (limited to 'app')
-rw-r--r-- | app/models/status.rb | 4 | ||||
-rw-r--r-- | app/serializers/rest/account_serializer.rb | 18 |
2 files changed, 20 insertions, 2 deletions
diff --git a/app/models/status.rb b/app/models/status.rb index fa9fb9fad..b1c49e99a 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -117,7 +117,7 @@ class Status < ApplicationRecord :tags, :preview_cards, :preloadable_poll, - account: [:account_stat, :user], + account: [:account_stat, user: :role], active_mentions: { account: :account_stat }, reblog: [ :application, @@ -127,7 +127,7 @@ class Status < ApplicationRecord :conversation, :status_stat, :preloadable_poll, - account: [:account_stat, :user], + account: [:account_stat, user: :role], active_mentions: { account: :account_stat }, ], thread: { account: :account_stat } diff --git a/app/serializers/rest/account_serializer.rb b/app/serializers/rest/account_serializer.rb index 6582b5bcf..62eac1fbd 100644 --- a/app/serializers/rest/account_serializer.rb +++ b/app/serializers/rest/account_serializer.rb @@ -26,6 +26,16 @@ class REST::AccountSerializer < ActiveModel::Serializer end end + class RoleSerializer < ActiveModel::Serializer + attributes :id, :name, :color + + def id + object.id.to_s + end + end + + has_many :roles, serializer: RoleSerializer, if: :local? + class FieldSerializer < ActiveModel::Serializer include FormattingHelper @@ -114,6 +124,14 @@ class REST::AccountSerializer < ActiveModel::Serializer object.silenced? end + def roles + if object.suspended? + [] + else + [object.user.role].compact.filter { |role| role.highlighted? } + end + end + def noindex object.user_prefers_noindex? end |