Add serializers for Accept+Reject of feature requests (#38177)

This commit is contained in:
David Roetzel
2026-03-12 16:46:36 +01:00
committed by GitHub
parent 7511357ec6
commit 377952703c
4 changed files with 127 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
# frozen_string_literal: true
class ActivityPub::AcceptFeatureRequestSerializer < ActivityPub::Serializer
include RoutingHelper
attributes :id, :type, :actor, :to, :result
has_one :virtual_object, key: :object
def id
[ActivityPub::TagManager.instance.uri_for(object.account), '#accepts/feature_requests/', object.id].join
end
def type
'Accept'
end
def actor
ActivityPub::TagManager.instance.uri_for(object.account)
end
def to
ActivityPub::TagManager.instance.uri_for(object.collection.account)
end
def virtual_object
object.activity_uri
end
def result
ap_account_feature_authorization_url(object.account_id, object)
end
end

View File

@@ -0,0 +1,29 @@
# frozen_string_literal: true
class ActivityPub::RejectFeatureRequestSerializer < ActivityPub::Serializer
include RoutingHelper
attributes :id, :type, :actor, :to
has_one :virtual_object, key: :object
def id
[ActivityPub::TagManager.instance.uri_for(object.account), '#rejects/feature_requests/', object.id].join
end
def type
'Reject'
end
def actor
ActivityPub::TagManager.instance.uri_for(object.account)
end
def to
ActivityPub::TagManager.instance.uri_for(object.collection.account)
end
def virtual_object
object.activity_uri
end
end

View File

@@ -0,0 +1,33 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe ActivityPub::AcceptFeatureRequestSerializer do
include RoutingHelper
subject { serialized_record_json(record, described_class, adapter: ActivityPub::Adapter) }
describe 'serializing an object' do
let(:collection) { Fabricate(:remote_collection) }
let(:record) do
Fabricate(:collection_item,
collection:,
uri: 'https://example.com/featured_items/1',
activity_uri: 'https://example.com/feature_requests/1',
state: :accepted)
end
let(:tag_manager) { ActivityPub::TagManager.instance }
it 'returns expected attributes' do
expect(subject)
.to include(
'id' => match("#accepts/feature_requests/#{record.id}"),
'type' => 'Accept',
'actor' => tag_manager.uri_for(record.account),
'to' => tag_manager.uri_for(collection.account),
'object' => 'https://example.com/feature_requests/1',
'result' => ap_account_feature_authorization_url(record.account_id, record)
)
end
end
end

View File

@@ -0,0 +1,32 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe ActivityPub::RejectFeatureRequestSerializer do
include RoutingHelper
subject { serialized_record_json(record, described_class, adapter: ActivityPub::Adapter) }
describe 'serializing an object' do
let(:collection) { Fabricate(:remote_collection) }
let(:record) do
Fabricate(:collection_item,
collection:,
uri: 'https://example.com/featured_items/1',
activity_uri: 'https://example.com/feature_requests/1',
state: :rejected)
end
let(:tag_manager) { ActivityPub::TagManager.instance }
it 'returns expected attributes' do
expect(subject)
.to include(
'id' => match("#rejects/feature_requests/#{record.id}"),
'type' => 'Reject',
'actor' => tag_manager.uri_for(record.account),
'to' => tag_manager.uri_for(collection.account),
'object' => 'https://example.com/feature_requests/1'
)
end
end
end