mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
FEATURE: after category name is changed, URLs with old category slug and tag filter will redirect to new category slug
This commit is contained in:
parent
547abda6d6
commit
2293fca012
1 changed files with 15 additions and 2 deletions
|
@ -167,11 +167,11 @@ class TagsController < ::ApplicationController
|
|||
parent_category_id = nil
|
||||
if parent_slug_or_id.present?
|
||||
parent_category_id = Category.query_parent_category(parent_slug_or_id)
|
||||
raise Discourse::NotFound if parent_category_id.blank?
|
||||
redirect_or_not_found and return if parent_category_id.blank?
|
||||
end
|
||||
|
||||
@filter_on_category = Category.query_category(slug_or_id, parent_category_id)
|
||||
raise Discourse::NotFound if !@filter_on_category
|
||||
redirect_or_not_found and return if !@filter_on_category
|
||||
|
||||
guardian.ensure_can_see!(@filter_on_category)
|
||||
end
|
||||
|
@ -197,4 +197,17 @@ class TagsController < ::ApplicationController
|
|||
|
||||
options
|
||||
end
|
||||
|
||||
def redirect_or_not_found
|
||||
# automatic redirects for renamed categories
|
||||
url = params[:parent_category] ? "c/#{params[:parent_category]}/#{params[:category]}" : "c/#{params[:category]}"
|
||||
permalink = Permalink.find_by_url(url)
|
||||
|
||||
if permalink.present? && permalink.category_id
|
||||
redirect_to "#{Discourse::base_uri}/tags#{permalink.target_url}/#{params[:tag_id]}", status: :moved_permanently
|
||||
else
|
||||
# redirect to 404
|
||||
raise Discourse::NotFound
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue