Do not return undiscoverable collections (#37560)

This commit is contained in:
David Roetzel 2026-01-21 13:30:07 +01:00 committed by GitHub
parent e7c6600d83
commit 783504f36a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 28 additions and 0 deletions

View File

@ -74,6 +74,7 @@ class Api::V1Alpha::CollectionsController < Api::BaseController
.order(created_at: :desc)
.offset(offset_param)
.limit(limit_param(DEFAULT_COLLECTIONS_LIMIT))
@collections = @collections.discoverable unless @account == current_account
end
def set_collection

View File

@ -43,6 +43,7 @@ class Collection < ApplicationRecord
scope :with_items, -> { includes(:collection_items).merge(CollectionItem.with_accounts) }
scope :with_tag, -> { includes(:tag) }
scope :discoverable, -> { where(discoverable: true) }
def remote?
!local?

View File

@ -55,6 +55,32 @@ RSpec.describe 'Api::V1Alpha::Collections', feature: :collections do
)
end
end
context 'when some collections are not discoverable' do
before do
Fabricate(:collection, account:, discoverable: false)
end
context 'when requesting user is a third party' do
it 'hides the collections that are not discoverable' do
subject
expect(response).to have_http_status(200)
expect(response.parsed_body.size).to eq 3
end
end
context 'when requesting user owns the collection' do
let(:account) { user.account }
it 'returns all collections, including the ones that are not discoverable' do
subject
expect(response).to have_http_status(200)
expect(response.parsed_body.size).to eq 4
end
end
end
end
describe 'GET /api/v1_alpha/collections/:id' do