about summary refs log tree commit diff
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2023-01-26 20:16:31 +0100
committerGitHub <noreply@github.com>2023-01-26 20:16:31 +0100
commitcfa92c4ec025609c24c24d73114033ecf150a438 (patch)
treeaf42722e4bdef8f4fcc4a43268e8ef033bf38a81
parent20abef6590505d12aca81ed1c386804d75b8b552 (diff)
parentfad6633156cae8ab2a7bad0c9802cf7918964ef4 (diff)
Merge pull request #2095 from ClearlyClaire/glitch-soc/merge-upstream
Merge upstream changes
-rw-r--r--app/models/status.rb4
-rw-r--r--app/serializers/rest/account_serializer.rb18
-rw-r--r--spec/fabricators/user_role_fabricator.rb6
3 files changed, 23 insertions, 5 deletions
diff --git a/app/models/status.rb b/app/models/status.rb
index 14b7a39fe..4e4d960a4 100644
--- a/app/models/status.rb
+++ b/app/models/status.rb
@@ -122,7 +122,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,
@@ -132,7 +132,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 6152d54f7..c4e281b80 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
 
@@ -118,6 +128,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
diff --git a/spec/fabricators/user_role_fabricator.rb b/spec/fabricators/user_role_fabricator.rb
index 28f76c8c4..ed0a7dc1f 100644
--- a/spec/fabricators/user_role_fabricator.rb
+++ b/spec/fabricators/user_role_fabricator.rb
@@ -1,5 +1,5 @@
 Fabricator(:user_role) do
   name        "MyString"
-  color       "MyString"
-  permissions ""
-end
\ No newline at end of file
+  color       ""
+  permissions 0
+end