Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add roles attribute to Account entities in REST API #23255

Merged
merged 1 commit into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/models/status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 }
Expand Down
18 changes: 18 additions & 0 deletions app/serializers/rest/account_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ def moved?
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

Expand Down Expand Up @@ -114,6 +124,14 @@ def silenced
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
Expand Down
6 changes: 3 additions & 3 deletions spec/fabricators/user_role_fabricator.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Fabricator(:user_role) do
name "MyString"
color "MyString"
permissions ""
end
color ""
permissions 0
end