FIX: Redirect user to the URL with the correct category slug (#10167)

This commit implements a category redirect similar to the one for topic
URLs with wrong slug.
This commit is contained in:
Dan Ungureanu
2020-07-07 15:25:36 +03:00
committed by GitHub
parent f92116d695
commit 333d4f9a98
3 changed files with 58 additions and 30 deletions

View File

@ -338,6 +338,21 @@ class ListController < ApplicationController
raise Discourse::NotFound.new("category not found", check_permalinks: true) if @category.nil?
if !guardian.can_see?(@category)
if SiteSetting.detailed_404
raise Discourse::InvalidAccess
else
raise Discourse::NotFound
end
end
current_slug = params.require(:category_slug_path_with_id)
real_slug = @category.full_slug("/")
if current_slug != real_slug
url = request.fullpath.gsub(current_slug, real_slug)
return redirect_to path(url), status: 301
end
params[:category] = @category.id.to_s
@description_meta = if @category.uncategorized?
@ -347,14 +362,6 @@ class ListController < ApplicationController
end
@description_meta = SiteSetting.site_description if @description_meta.blank?
if !guardian.can_see?(@category)
if SiteSetting.detailed_404
raise Discourse::InvalidAccess
else
raise Discourse::NotFound
end
end
if use_crawler_layout?
@subcategories = @category.subcategories.select { |c| guardian.can_see?(c) }
end