From 07ce066d686c2e54db27a535c3c67dec4cb7544c Mon Sep 17 00:00:00 2001 From: David Roetzel Date: Wed, 6 May 2026 11:35:07 +0200 Subject: [PATCH] Move `PartialAccountSerializer` to the top-level (#38916) --- app/models/collection.rb | 1 + .../dedup_notification_group_serializer.rb | 12 +-------- .../rest/partial_account_serializer.rb | 11 ++++++++ spec/requests/api/v2/notifications_spec.rb | 2 +- .../rest/partial_account_serializer_spec.rb | 27 +++++++++++++++++++ 5 files changed, 41 insertions(+), 12 deletions(-) create mode 100644 app/serializers/rest/partial_account_serializer.rb create mode 100644 spec/serializers/rest/partial_account_serializer_spec.rb diff --git a/app/models/collection.rb b/app/models/collection.rb index c5082269e0..36131bbcf7 100644 --- a/app/models/collection.rb +++ b/app/models/collection.rb @@ -5,6 +5,7 @@ # Table name: collections # # id :bigint(8) not null, primary key +# deleted_at :datetime # description :text # description_html :text # discoverable :boolean not null diff --git a/app/serializers/rest/dedup_notification_group_serializer.rb b/app/serializers/rest/dedup_notification_group_serializer.rb index 4f02505e25..19b42e6bd5 100644 --- a/app/serializers/rest/dedup_notification_group_serializer.rb +++ b/app/serializers/rest/dedup_notification_group_serializer.rb @@ -1,18 +1,8 @@ # frozen_string_literal: true class REST::DedupNotificationGroupSerializer < ActiveModel::Serializer - class PartialAccountSerializer < REST::AccountSerializer - # This is a hack to reset ActiveModel::Serializer internals and only expose the attributes - # we care about. - self._attributes_data = {} - self._reflections = [] - self._links = [] - - attributes :id, :acct, :locked, :bot, :url, :avatar, :avatar_static - end - has_many :accounts, serializer: REST::AccountSerializer - has_many :partial_accounts, serializer: PartialAccountSerializer, if: :return_partial_accounts? + has_many :partial_accounts, serializer: REST::PartialAccountSerializer, if: :return_partial_accounts? has_many :statuses, serializer: REST::StatusSerializer has_many :notification_groups, serializer: REST::NotificationGroupSerializer diff --git a/app/serializers/rest/partial_account_serializer.rb b/app/serializers/rest/partial_account_serializer.rb new file mode 100644 index 0000000000..4ff3b9cbb1 --- /dev/null +++ b/app/serializers/rest/partial_account_serializer.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class REST::PartialAccountSerializer < REST::AccountSerializer + # This is a hack to reset ActiveModel::Serializer internals and only expose the attributes + # we care about. + self._attributes_data = {} + self._reflections = [] + self._links = [] + + attributes :id, :acct, :locked, :bot, :url, :avatar, :avatar_static, :avatar_description +end diff --git a/spec/requests/api/v2/notifications_spec.rb b/spec/requests/api/v2/notifications_spec.rb index 4b4aa1b475..182733a8fc 100644 --- a/spec/requests/api/v2/notifications_spec.rb +++ b/spec/requests/api/v2/notifications_spec.rb @@ -322,7 +322,7 @@ RSpec.describe 'Notifications' do expect(response.content_type) .to start_with('application/json') expect(response.parsed_body[:partial_accounts].size).to be > 0 - expect(response.parsed_body[:partial_accounts][0].keys.map(&:to_sym)).to contain_exactly(:acct, :avatar, :avatar_static, :bot, :id, :locked, :url) + expect(response.parsed_body[:partial_accounts][0].keys.map(&:to_sym)).to contain_exactly(:acct, :avatar, :avatar_static, :avatar_description, :bot, :id, :locked, :url) expect(response.parsed_body[:partial_accounts].pluck(:id)).to_not include(recent_account.id.to_s) expect(response.parsed_body[:accounts].pluck(:id)).to include(recent_account.id.to_s) end diff --git a/spec/serializers/rest/partial_account_serializer_spec.rb b/spec/serializers/rest/partial_account_serializer_spec.rb new file mode 100644 index 0000000000..dc98850ba4 --- /dev/null +++ b/spec/serializers/rest/partial_account_serializer_spec.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe REST::PartialAccountSerializer do + subject do + serialized_record_json(account, described_class, options: { + scope: nil, + scope_name: :current_user, + }) + end + + let(:account) { Fabricate(:account, avatar_description: 'image') } + + it 'includes the expected attributes' do + expect(subject).to include({ + 'id' => account.id.to_s, + 'acct' => account.pretty_acct, + 'locked' => false, + 'bot' => false, + 'url' => ActivityPub::TagManager.instance.url_for(account), + 'avatar' => include(account.avatar_original_url), + 'avatar_static' => include(account.avatar_static_url), + 'avatar_description' => 'image', + }) + end +end