mirror of
https://github.com/discourse/discourse.git
synced 2025-06-02 04:08:41 +08:00
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:
@ -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
|
||||
|
Reference in New Issue
Block a user