Redirect with interstitial when trying to view a remote collection while logged out (#38941)
Some checks failed
Check i18n / check-i18n (push) Waiting to run
Chromatic / Check for relevant changes (push) Waiting to run
Chromatic / Run Chromatic (push) Blocked by required conditions
CodeQL / Analyze (actions) (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
CodeQL / Analyze (ruby) (push) Waiting to run
Check formatting / lint (push) Waiting to run
JavaScript Linting / lint (push) Waiting to run
JavaScript Testing / test (push) Waiting to run
Ruby Testing / build (production) (push) Waiting to run
Ruby Testing / build (test) (push) Waiting to run
Ruby Testing / test (.ruby-version) (push) Blocked by required conditions
Ruby Testing / test (3.3) (push) Blocked by required conditions
Ruby Testing / test (3.4) (push) Blocked by required conditions
Ruby Testing / End to End testing (.ruby-version) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.3) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.4) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.19.2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.3, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.4, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Blocked by required conditions
Haml Linting / lint (push) Has been cancelled
Ruby Linting / lint (push) Has been cancelled
Historical data migration test / test (14-alpine) (push) Has been cancelled
Historical data migration test / test (15-alpine) (push) Has been cancelled
Historical data migration test / test (16-alpine) (push) Has been cancelled
Historical data migration test / test (17-alpine) (push) Has been cancelled
Build nightly container image / compute-suffix (push) Has been cancelled
Build nightly container image / build-image (push) Has been cancelled
Build nightly container image / build-image-streaming (push) Has been cancelled

This commit is contained in:
Claire 2026-05-07 18:04:26 +02:00 committed by GitHub
parent 496d41cdce
commit b2aa476abb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 32 additions and 0 deletions

View File

@ -0,0 +1,10 @@
# frozen_string_literal: true
class Redirect::CollectionsController < Redirect::BaseController
private
def set_resource
@resource = Collection.find(params[:id])
not_found if @resource.local? || @resource&.account&.suspended?
end
end

View File

@ -21,6 +21,9 @@ class PermalinkRedirector
elsif accounts_request? && record_integer_id_request?
account = Account.find_by(id: second_segment)
account if !account&.local? && !account&.suspended?
elsif collections_request? && record_integer_id_request?
collection = Collection.find_by(id: second_segment)
collection if !collection&.local? && !collection&.account&.suspended?
end
end
end
@ -43,6 +46,8 @@ class PermalinkRedirector
redirect_account_path(object.id)
when 'Status'
redirect_status_path(object.id)
when 'Collection'
redirect_collection_path(object.id)
else
@path.delete_prefix('/deck') if @path.start_with?('/deck')
end
@ -70,6 +75,10 @@ class PermalinkRedirector
first_segment == 'accounts'
end
def collections_request?
first_segment == 'collections'
end
def record_integer_id_request?
second_segment =~ /\d/
end

View File

@ -189,6 +189,7 @@ Rails.application.routes.draw do
namespace :redirect do
resources :accounts, only: :show
resources :statuses, only: :show
resources :collections, only: :show
end
namespace :email_subscriptions do

View File

@ -45,6 +45,12 @@ RSpec.describe PermalinkRedirector do
redirector = described_class.new('@alice/123?foo=bar')
expect(redirector.redirect_path).to eq 'https://example.com/status-123'
end
it 'returns path for collections link' do
collection = Fabricate(:remote_collection, account: remote_account)
redirector = described_class.new("collections/#{collection.id}")
expect(redirector.redirect_path).to eq(ActivityPub::TagManager.instance.url_for(collection) || ActivityPub::TagManager.instance.uri_for(collection))
end
end
context 'when account is suspended' do
@ -81,6 +87,12 @@ RSpec.describe PermalinkRedirector do
redirector = described_class.new('@alice/123?foo=bar')
expect(redirector.redirect_path).to be_nil
end
it 'returns nil for collections link' do
collection = Fabricate(:remote_collection, account: remote_account)
redirector = described_class.new("collections/#{collection.id}")
expect(redirector.redirect_path).to be_nil
end
end
end
end