A platform for community discussion. Free, open, simple.
FIX: if we have not target available do not redirect
Samce4b12ae5973
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rbindex e3f2c36a7f2..8c66f990977 100644--- a/app/controllers/application_controller.rb+++ b/app/controllers/application_controller.rb@@ -222,7 +222,9 @@ class ApplicationController < ActionController::Baseurl = opts[:original_path] || request.fullpathpermalink = 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 URLredirect_with_client_support permalink.target_url, status: :moved_permanentlyreturndiff --git a/app/controllers/permalinks_controller.rb b/app/controllers/permalinks_controller.rbindex e88af68f5b0..65efdc7908e 100644--- a/app/controllers/permalinks_controller.rb+++ b/app/controllers/permalinks_controller.rb@@ -8,9 +8,7 @@ class PermalinksController < ApplicationControllerraise Discourse::NotFound unless permalink- if permalink.external_url- redirect_to permalink.external_url, status: :moved_permanently- elsif permalink.target_url+ if permalink.target_urlredirect_to permalink.target_url, status: :moved_permanentlyelseraise Discourse::NotFounddiff --git a/spec/requests/application_controller_spec.rb b/spec/requests/application_controller_spec.rbindex dfb32ef47b4..3b9344d0e1d 100644--- a/spec/requests/application_controller_spec.rb+++ b/spec/requests/application_controller_spec.rb@@ -18,6 +18,14 @@ RSpec.describe ApplicationController dodescribe 'build_not_found_page' dodescribe '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' dotopic = create_post.topicexternal_url = 'https://somewhere.over.rainbow'