mirror of
https://github.com/mastodon/mastodon.git
synced 2025-11-27 18:10:58 +00:00
Fix permalink redirects continuing to work for suspended accounts (#36453)
This commit is contained in:
parent
254fff93ca
commit
33f739da44
|
|
@ -12,15 +12,15 @@ class PermalinkRedirector
|
||||||
@object ||= begin
|
@object ||= begin
|
||||||
if at_username_status_request? || statuses_status_request?
|
if at_username_status_request? || statuses_status_request?
|
||||||
status = Status.find_by(id: second_segment)
|
status = Status.find_by(id: second_segment)
|
||||||
status if status&.distributable? && !status&.local?
|
status if status&.distributable? && !status&.local? && !status&.account&.suspended?
|
||||||
elsif at_username_request?
|
elsif at_username_request?
|
||||||
username, domain = first_segment.delete_prefix('@').split('@')
|
username, domain = first_segment.delete_prefix('@').split('@')
|
||||||
domain = nil if TagManager.instance.local_domain?(domain)
|
domain = nil if TagManager.instance.local_domain?(domain)
|
||||||
account = Account.find_remote(username, domain)
|
account = Account.find_remote(username, domain)
|
||||||
account unless account&.local?
|
account if !account&.local? && !account&.suspended?
|
||||||
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 unless account&.local?
|
account if !account&.local? && !account&.suspended?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -10,39 +10,77 @@ RSpec.describe PermalinkRedirector do
|
||||||
Fabricate(:status, account: remote_account, id: 123, url: 'https://example.com/status-123')
|
Fabricate(:status, account: remote_account, id: 123, url: 'https://example.com/status-123')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns path for legacy account links' do
|
|
||||||
redirector = described_class.new('accounts/2')
|
|
||||||
expect(redirector.redirect_path).to eq 'https://example.com/@alice'
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns path for legacy status links' do
|
|
||||||
redirector = described_class.new('statuses/123')
|
|
||||||
expect(redirector.redirect_path).to eq 'https://example.com/status-123'
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns path for pretty account links' do
|
|
||||||
redirector = described_class.new('@alice@example.com')
|
|
||||||
expect(redirector.redirect_path).to eq 'https://example.com/@alice'
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns path for pretty status links' do
|
|
||||||
redirector = described_class.new('@alice/123')
|
|
||||||
expect(redirector.redirect_path).to eq 'https://example.com/status-123'
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns path for legacy status links with a query param' do
|
|
||||||
redirector = described_class.new('statuses/123?foo=bar')
|
|
||||||
expect(redirector.redirect_path).to eq 'https://example.com/status-123'
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns path for pretty status links with a query param' 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 deck URLs with query params' do
|
it 'returns path for deck URLs with query params' do
|
||||||
redirector = described_class.new('/deck/directory?local=true')
|
redirector = described_class.new('/deck/directory?local=true')
|
||||||
expect(redirector.redirect_path).to eq '/directory?local=true'
|
expect(redirector.redirect_path).to eq '/directory?local=true'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when account is not suspended' do
|
||||||
|
it 'returns path for legacy account links' do
|
||||||
|
redirector = described_class.new('accounts/2')
|
||||||
|
expect(redirector.redirect_path).to eq 'https://example.com/@alice'
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns path for legacy status links' do
|
||||||
|
redirector = described_class.new('statuses/123')
|
||||||
|
expect(redirector.redirect_path).to eq 'https://example.com/status-123'
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns path for pretty account links' do
|
||||||
|
redirector = described_class.new('@alice@example.com')
|
||||||
|
expect(redirector.redirect_path).to eq 'https://example.com/@alice'
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns path for pretty status links' do
|
||||||
|
redirector = described_class.new('@alice/123')
|
||||||
|
expect(redirector.redirect_path).to eq 'https://example.com/status-123'
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns path for legacy status links with a query param' do
|
||||||
|
redirector = described_class.new('statuses/123?foo=bar')
|
||||||
|
expect(redirector.redirect_path).to eq 'https://example.com/status-123'
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns path for pretty status links with a query param' do
|
||||||
|
redirector = described_class.new('@alice/123?foo=bar')
|
||||||
|
expect(redirector.redirect_path).to eq 'https://example.com/status-123'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when account is suspended' do
|
||||||
|
before do
|
||||||
|
remote_account.suspend!
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns nil for legacy account links' do
|
||||||
|
redirector = described_class.new('accounts/2')
|
||||||
|
expect(redirector.redirect_path).to be_nil
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns nil for legacy status links' do
|
||||||
|
redirector = described_class.new('statuses/123')
|
||||||
|
expect(redirector.redirect_path).to be_nil
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns nil for pretty account links' do
|
||||||
|
redirector = described_class.new('@alice@example.com')
|
||||||
|
expect(redirector.redirect_path).to be_nil
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns nil for pretty status links' do
|
||||||
|
redirector = described_class.new('@alice/123')
|
||||||
|
expect(redirector.redirect_path).to be_nil
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns nil for legacy status links with a query param' do
|
||||||
|
redirector = described_class.new('statuses/123?foo=bar')
|
||||||
|
expect(redirector.redirect_path).to be_nil
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns nil for pretty status links with a query param' do
|
||||||
|
redirector = described_class.new('@alice/123?foo=bar')
|
||||||
|
expect(redirector.redirect_path).to be_nil
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user