Include collection url in API responses (#38708)
This commit is contained in:
parent
e05ac2ec04
commit
961acaf202
@ -1,8 +1,10 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class REST::CollectionSerializer < ActiveModel::Serializer
|
class REST::CollectionSerializer < ActiveModel::Serializer
|
||||||
|
include RoutingHelper
|
||||||
|
|
||||||
attributes :id, :uri, :name, :description, :language, :account_id,
|
attributes :id, :uri, :name, :description, :language, :account_id,
|
||||||
:local, :sensitive, :discoverable, :item_count,
|
:local, :sensitive, :discoverable, :url, :item_count,
|
||||||
:created_at, :updated_at
|
:created_at, :updated_at
|
||||||
|
|
||||||
belongs_to :tag, serializer: REST::ShallowTagSerializer
|
belongs_to :tag, serializer: REST::ShallowTagSerializer
|
||||||
@ -17,6 +19,10 @@ class REST::CollectionSerializer < ActiveModel::Serializer
|
|||||||
ActivityPub::TagManager.instance.uri_for(object)
|
ActivityPub::TagManager.instance.uri_for(object)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def url
|
||||||
|
object.local? ? account_collection_url(object.account, object) : object.url
|
||||||
|
end
|
||||||
|
|
||||||
def description
|
def description
|
||||||
return object.description if object.local?
|
return object.description if object.local?
|
||||||
return if object.description_html.nil?
|
return if object.description_html.nil?
|
||||||
@ -31,4 +37,8 @@ class REST::CollectionSerializer < ActiveModel::Serializer
|
|||||||
def account_id
|
def account_id
|
||||||
object.account_id.to_s
|
object.account_id.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def tag
|
||||||
|
object.tag
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -3,6 +3,8 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe REST::CollectionSerializer do
|
RSpec.describe REST::CollectionSerializer do
|
||||||
|
include RoutingHelper
|
||||||
|
|
||||||
subject do
|
subject do
|
||||||
serialized_record_json(collection, described_class, options: {
|
serialized_record_json(collection, described_class, options: {
|
||||||
scope: current_user,
|
scope: current_user,
|
||||||
@ -37,6 +39,7 @@ RSpec.describe REST::CollectionSerializer do
|
|||||||
'local' => true,
|
'local' => true,
|
||||||
'sensitive' => true,
|
'sensitive' => true,
|
||||||
'discoverable' => false,
|
'discoverable' => false,
|
||||||
|
'url' => account_collection_url(collection.account, collection),
|
||||||
'tag' => a_hash_including('name' => 'discovery'),
|
'tag' => a_hash_including('name' => 'discovery'),
|
||||||
'created_at' => match_api_datetime_format,
|
'created_at' => match_api_datetime_format,
|
||||||
'updated_at' => match_api_datetime_format,
|
'updated_at' => match_api_datetime_format,
|
||||||
@ -46,7 +49,11 @@ RSpec.describe REST::CollectionSerializer do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'when the collection is remote' do
|
context 'when the collection is remote' do
|
||||||
let(:collection) { Fabricate(:remote_collection, description_html: '<p>remote</p>') }
|
let(:collection) { Fabricate(:remote_collection, description_html: '<p>remote</p>', url: 'https://example.com/c/1') }
|
||||||
|
|
||||||
|
it 'includes the uri' do
|
||||||
|
expect(subject).to include('url' => 'https://example.com/c/1')
|
||||||
|
end
|
||||||
|
|
||||||
it 'includes the html description' do
|
it 'includes the html description' do
|
||||||
expect(subject)
|
expect(subject)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user