Redirect with interstitial when trying to view a remote collection while logged out (#38941)
This commit is contained in:
parent
496d41cdce
commit
b2aa476abb
10
app/controllers/redirect/collections_controller.rb
Normal file
10
app/controllers/redirect/collections_controller.rb
Normal 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
|
||||||
@ -21,6 +21,9 @@ class PermalinkRedirector
|
|||||||
elsif accounts_request? && record_integer_id_request?
|
elsif accounts_request? && record_integer_id_request?
|
||||||
account = Account.find_by(id: second_segment)
|
account = Account.find_by(id: second_segment)
|
||||||
account if !account&.local? && !account&.suspended?
|
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
|
end
|
||||||
end
|
end
|
||||||
@ -43,6 +46,8 @@ class PermalinkRedirector
|
|||||||
redirect_account_path(object.id)
|
redirect_account_path(object.id)
|
||||||
when 'Status'
|
when 'Status'
|
||||||
redirect_status_path(object.id)
|
redirect_status_path(object.id)
|
||||||
|
when 'Collection'
|
||||||
|
redirect_collection_path(object.id)
|
||||||
else
|
else
|
||||||
@path.delete_prefix('/deck') if @path.start_with?('/deck')
|
@path.delete_prefix('/deck') if @path.start_with?('/deck')
|
||||||
end
|
end
|
||||||
@ -70,6 +75,10 @@ class PermalinkRedirector
|
|||||||
first_segment == 'accounts'
|
first_segment == 'accounts'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def collections_request?
|
||||||
|
first_segment == 'collections'
|
||||||
|
end
|
||||||
|
|
||||||
def record_integer_id_request?
|
def record_integer_id_request?
|
||||||
second_segment =~ /\d/
|
second_segment =~ /\d/
|
||||||
end
|
end
|
||||||
|
|||||||
@ -189,6 +189,7 @@ Rails.application.routes.draw do
|
|||||||
namespace :redirect do
|
namespace :redirect do
|
||||||
resources :accounts, only: :show
|
resources :accounts, only: :show
|
||||||
resources :statuses, only: :show
|
resources :statuses, only: :show
|
||||||
|
resources :collections, only: :show
|
||||||
end
|
end
|
||||||
|
|
||||||
namespace :email_subscriptions do
|
namespace :email_subscriptions do
|
||||||
|
|||||||
@ -45,6 +45,12 @@ RSpec.describe PermalinkRedirector do
|
|||||||
redirector = described_class.new('@alice/123?foo=bar')
|
redirector = described_class.new('@alice/123?foo=bar')
|
||||||
expect(redirector.redirect_path).to eq 'https://example.com/status-123'
|
expect(redirector.redirect_path).to eq 'https://example.com/status-123'
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
context 'when account is suspended' do
|
context 'when account is suspended' do
|
||||||
@ -81,6 +87,12 @@ RSpec.describe PermalinkRedirector do
|
|||||||
redirector = described_class.new('@alice/123?foo=bar')
|
redirector = described_class.new('@alice/123?foo=bar')
|
||||||
expect(redirector.redirect_path).to be_nil
|
expect(redirector.redirect_path).to be_nil
|
||||||
end
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user