DEV: Remove legacy tag and category routes (#10338)

* DEV: Remove client-side legacy tag and category routes

* DEV: Remove server-side legacy tag routes

* DEV: Refactor ListController#set_category

* FIX: Remove reference to discovery.parentCategory

* FIX: Refactor TagsController#set_category_from_params

* FIX: Build correct canonical URL for tags and categories

* DEV: Fix deprecation notice in Ruby 2.7

* DEV: Replace use of removed legacy tag route

* DEV: Add deprecation notices for old routes and controllers
This commit is contained in:
Dan Ungureanu
2020-11-03 16:57:58 +02:00
committed by GitHub
parent 5140ec9acf
commit 3c51647872
15 changed files with 79 additions and 156 deletions

View File

@@ -336,25 +336,14 @@ class ListController < ApplicationController
end
def set_category
parts = params.require(:category_slug_path_with_id).split('/')
category_slug_path_with_id = params.require(:category_slug_path_with_id)
if !parts.empty? && parts.last =~ /\A\d+\Z/
id = parts.pop.to_i
end
slug_path = parts unless parts.empty?
if id.present?
@category = Category.find_by_id(id)
elsif slug_path.present?
@category = Category.find_by_slug_path(slug_path)
# Legacy paths
if @category.nil? && parts.last =~ /\A\d+-category/
@category = Category.find_by_id(parts.last.to_i)
end
@category = Category.find_by_slug_path_with_id(category_slug_path_with_id)
if @category.nil?
raise Discourse::NotFound.new("category not found", check_permalinks: true)
end
raise Discourse::NotFound.new("category not found", check_permalinks: true) if @category.nil?
params[:category] = @category.id.to_s
if !guardian.can_see?(@category)
if SiteSetting.detailed_404
@@ -364,13 +353,13 @@ class ListController < ApplicationController
end
end
current_slug = params.require(:category_slug_path_with_id)
real_slug = @category.full_slug("/")
# Check if the category slug is incorrect and redirect to a link containing
# the correct one.
current_slug = category_slug_path_with_id
if SiteSetting.slug_generation_method == "encoded"
current_slug = current_slug.split("/").map { |slug| CGI.escape(slug) }.join("/")
end
real_slug = @category.full_slug("/")
if current_slug != real_slug
url = request.fullpath.gsub(current_slug, real_slug)
if ActionController::Base.config.relative_url_root
@@ -380,14 +369,13 @@ class ListController < ApplicationController
return redirect_to path(url), status: 301
end
params[:category] = @category.id.to_s
@description_meta = if @category.uncategorized?
I18n.t('category.uncategorized_description', locale: SiteSetting.default_locale)
else
I18n.t("category.uncategorized_description", locale: SiteSetting.default_locale)
elsif @category.description_text.present?
@category.description_text
else
SiteSetting.site_description
end
@description_meta = SiteSetting.site_description if @description_meta.blank?
if use_crawler_layout?
@subcategories = @category.subcategories.select { |c| guardian.can_see?(c) }