Add roles
attribute to Account entities in REST API (#23255)
This commit is contained in:
parent
e5ae75bf6a
commit
13a2abacc8
|
@ -117,7 +117,7 @@ class Status < ApplicationRecord
|
||||||
:tags,
|
:tags,
|
||||||
:preview_cards,
|
:preview_cards,
|
||||||
:preloadable_poll,
|
:preloadable_poll,
|
||||||
account: [:account_stat, :user],
|
account: [:account_stat, user: :role],
|
||||||
active_mentions: { account: :account_stat },
|
active_mentions: { account: :account_stat },
|
||||||
reblog: [
|
reblog: [
|
||||||
:application,
|
:application,
|
||||||
|
@ -127,7 +127,7 @@ class Status < ApplicationRecord
|
||||||
:conversation,
|
:conversation,
|
||||||
:status_stat,
|
:status_stat,
|
||||||
:preloadable_poll,
|
:preloadable_poll,
|
||||||
account: [:account_stat, :user],
|
account: [:account_stat, user: :role],
|
||||||
active_mentions: { account: :account_stat },
|
active_mentions: { account: :account_stat },
|
||||||
],
|
],
|
||||||
thread: { account: :account_stat }
|
thread: { account: :account_stat }
|
||||||
|
|
|
@ -26,6 +26,16 @@ class REST::AccountSerializer < ActiveModel::Serializer
|
||||||
end
|
end
|
||||||
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
|
class FieldSerializer < ActiveModel::Serializer
|
||||||
include FormattingHelper
|
include FormattingHelper
|
||||||
|
|
||||||
|
@ -114,6 +124,14 @@ class REST::AccountSerializer < ActiveModel::Serializer
|
||||||
object.silenced?
|
object.silenced?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def roles
|
||||||
|
if object.suspended?
|
||||||
|
[]
|
||||||
|
else
|
||||||
|
[object.user.role].compact.filter { |role| role.highlighted? }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def noindex
|
def noindex
|
||||||
object.user_prefers_noindex?
|
object.user_prefers_noindex?
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
Fabricator(:user_role) do
|
Fabricator(:user_role) do
|
||||||
name "MyString"
|
name "MyString"
|
||||||
color "MyString"
|
color ""
|
||||||
permissions ""
|
permissions 0
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue