From fc1ba93cdc01538c9862810273a82e112a66ec1c Mon Sep 17 00:00:00 2001 From: Claire Date: Thu, 16 Apr 2026 18:00:13 +0200 Subject: [PATCH] Refactor featured collections URL code (#38709) --- app/lib/activitypub/tag_manager.rb | 2 ++ .../activitypub/featured_collection_serializer.rb | 5 +---- app/serializers/rest/collection_serializer.rb | 8 +------- spec/serializers/rest/collection_serializer_spec.rb | 4 +--- 4 files changed, 5 insertions(+), 14 deletions(-) diff --git a/app/lib/activitypub/tag_manager.rb b/app/lib/activitypub/tag_manager.rb index 9036811217..37c45d68f1 100644 --- a/app/lib/activitypub/tag_manager.rb +++ b/app/lib/activitypub/tag_manager.rb @@ -31,6 +31,8 @@ class ActivityPub::TagManager short_account_status_url(target.account, target) when :flag target.uri + when :featured_collection + account_collection_url(target.account, target) end end diff --git a/app/serializers/activitypub/featured_collection_serializer.rb b/app/serializers/activitypub/featured_collection_serializer.rb index 60b4d8459c..b83e0bf9ea 100644 --- a/app/serializers/activitypub/featured_collection_serializer.rb +++ b/app/serializers/activitypub/featured_collection_serializer.rb @@ -1,9 +1,6 @@ # frozen_string_literal: true class ActivityPub::FeaturedCollectionSerializer < ActivityPub::Serializer - # include Rails.application.routes.url_helpers - include RoutingHelper - attributes :id, :type, :total_items, :name, :attributed_to, :url, :sensitive, :discoverable, :published, :updated @@ -35,7 +32,7 @@ class ActivityPub::FeaturedCollectionSerializer < ActivityPub::Serializer end def url - account_collection_url(object.account, object) + ActivityPub::TagManager.instance.url_for(object) end def total_items diff --git a/app/serializers/rest/collection_serializer.rb b/app/serializers/rest/collection_serializer.rb index 98dbabb949..c9696b9aef 100644 --- a/app/serializers/rest/collection_serializer.rb +++ b/app/serializers/rest/collection_serializer.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true class REST::CollectionSerializer < ActiveModel::Serializer - include RoutingHelper - attributes :id, :uri, :name, :description, :language, :account_id, :local, :sensitive, :discoverable, :url, :item_count, :created_at, :updated_at @@ -20,7 +18,7 @@ class REST::CollectionSerializer < ActiveModel::Serializer end def url - object.local? ? account_collection_url(object.account, object) : object.url + ActivityPub::TagManager.instance.url_for(object) end def description @@ -37,8 +35,4 @@ class REST::CollectionSerializer < ActiveModel::Serializer def account_id object.account_id.to_s end - - def tag - object.tag - end end diff --git a/spec/serializers/rest/collection_serializer_spec.rb b/spec/serializers/rest/collection_serializer_spec.rb index 0ff98c4cb1..dbb9803753 100644 --- a/spec/serializers/rest/collection_serializer_spec.rb +++ b/spec/serializers/rest/collection_serializer_spec.rb @@ -3,8 +3,6 @@ require 'rails_helper' RSpec.describe REST::CollectionSerializer do - include RoutingHelper - subject do serialized_record_json(collection, described_class, options: { scope: current_user, @@ -39,7 +37,7 @@ RSpec.describe REST::CollectionSerializer do 'local' => true, 'sensitive' => true, 'discoverable' => false, - 'url' => account_collection_url(collection.account, collection), + 'url' => ActivityPub::TagManager.instance.url_for(collection), 'tag' => a_hash_including('name' => 'discovery'), 'created_at' => match_api_datetime_format, 'updated_at' => match_api_datetime_format,