Skip to content

A platform for community discussion. Free, open, simple.

REFACTOR: Handle no_subcategories option during routing

Daniel Waterworthf3f04f16436b
diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb
index a8a766e653c..9e2cfde2026 100644
--- a/app/controllers/tags_controller.rb
+++ b/app/controllers/tags_controller.rb
@@ -296,21 +296,16 @@ class TagsController < ::ApplicationController
slug_or_id = params[:category]
return true if slug_or_id.nil?
- if slug_or_id == 'none' && params[:parent_category]
- @filter_on_category = Category.query_category(params[:parent_category], nil)
- params[:no_subcategories] = 'true'
- else
- parent_slug_or_id = params[:parent_category]
-
- parent_category_id = nil
- if parent_slug_or_id.present?
- parent_category_id = Category.query_parent_category(parent_slug_or_id)
- category_redirect_or_not_found && (return) if parent_category_id.blank?
- end
+ parent_slug_or_id = params[:parent_category]
- @filter_on_category = Category.query_category(slug_or_id, parent_category_id)
+ parent_category_id = nil
+ if parent_slug_or_id.present?
+ parent_category_id = Category.query_parent_category(parent_slug_or_id)
+ category_redirect_or_not_found && (return) if parent_category_id.blank?
end
+ @filter_on_category = Category.query_category(slug_or_id, parent_category_id)
+
category_redirect_or_not_found && (return) if !@filter_on_category
guardian.ensure_can_see!(@filter_on_category)
diff --git a/config/routes.rb b/config/routes.rb
index c00041b3e04..bc66be9ecfa 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -839,6 +839,7 @@ Discourse::Application.routes.draw do
get '/:tag_id.rss' => 'tags#tag_feed'
get '/:tag_id' => 'tags#show', as: 'tag_show'
get '/c/:category/:tag_id' => 'tags#show', as: 'tag_category_show'
+ get '/c/:category/none/:tag_id' => 'tags#show', as: 'tag_category_none_show', defaults: { no_subcategories: true }
get '/c/:parent_category/:category/:tag_id' => 'tags#show', as: 'tag_parent_category_category_show'
get '/intersection/:tag_id/*additional_tag_ids' => 'tags#show', as: 'tag_intersection'
get '/:tag_id/notifications' => 'tags#notifications'
@@ -849,6 +850,7 @@ Discourse::Application.routes.draw do
Discourse.filters.each do |filter|
get "/:tag_id/l/#{filter}" => "tags#show_#{filter}", as: "tag_show_#{filter}"
get "/c/:category/:tag_id/l/#{filter}" => "tags#show_#{filter}", as: "tag_category_show_#{filter}"
+ get "/c/:category/none/:tag_id/l/#{filter}" => "tags#show_#{filter}", as: "tag_category_none_show_#{filter}", defaults: { no_subcategories: true }
get "/c/:parent_category/:category/:tag_id/l/#{filter}" => "tags#show_#{filter}", as: "tag_parent_category_category_show_#{filter}"
end
end