mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 07:53:49 +08:00
FIX: if we have not target available do not redirect
This commit is contained in:
@ -222,7 +222,9 @@ class ApplicationController < ActionController::Base
|
|||||||
url = opts[:original_path] || request.fullpath
|
url = opts[:original_path] || request.fullpath
|
||||||
permalink = Permalink.find_by_url(url)
|
permalink = Permalink.find_by_url(url)
|
||||||
|
|
||||||
if permalink.present?
|
# there are some cases where we have a permalink but no url
|
||||||
|
# cause category / topic was deleted
|
||||||
|
if permalink.present? && permalink.target_url
|
||||||
# permalink present, redirect to that URL
|
# permalink present, redirect to that URL
|
||||||
redirect_with_client_support permalink.target_url, status: :moved_permanently
|
redirect_with_client_support permalink.target_url, status: :moved_permanently
|
||||||
return
|
return
|
||||||
|
@ -8,9 +8,7 @@ class PermalinksController < ApplicationController
|
|||||||
|
|
||||||
raise Discourse::NotFound unless permalink
|
raise Discourse::NotFound unless permalink
|
||||||
|
|
||||||
if permalink.external_url
|
if permalink.target_url
|
||||||
redirect_to permalink.external_url, status: :moved_permanently
|
|
||||||
elsif permalink.target_url
|
|
||||||
redirect_to permalink.target_url, status: :moved_permanently
|
redirect_to permalink.target_url, status: :moved_permanently
|
||||||
else
|
else
|
||||||
raise Discourse::NotFound
|
raise Discourse::NotFound
|
||||||
|
@ -18,6 +18,14 @@ RSpec.describe ApplicationController do
|
|||||||
describe 'build_not_found_page' do
|
describe 'build_not_found_page' do
|
||||||
describe 'topic not found' do
|
describe 'topic not found' do
|
||||||
|
|
||||||
|
it 'should not redirect to permalink if topic/category does not exist' do
|
||||||
|
topic = create_post.topic
|
||||||
|
Permalink.create!(url: topic.relative_url, topic_id: topic.id + 1)
|
||||||
|
topic.trash!
|
||||||
|
get topic.relative_url
|
||||||
|
expect(response.status).to eq(410)
|
||||||
|
end
|
||||||
|
|
||||||
it 'should return permalink for deleted topics' do
|
it 'should return permalink for deleted topics' do
|
||||||
topic = create_post.topic
|
topic = create_post.topic
|
||||||
external_url = 'https://somewhere.over.rainbow'
|
external_url = 'https://somewhere.over.rainbow'
|
||||||
|
Reference in New Issue
Block a user