REFACTOR: Handle no_subcategories option during routing

This commit is contained in:
Daniel Waterworth 2019-11-03 14:47:06 +00:00
parent d43e7354ec
commit f3f04f1643
2 changed files with 9 additions and 12 deletions

View File

@ -296,21 +296,16 @@ class TagsController < ::ApplicationController
slug_or_id = params[:category] slug_or_id = params[:category]
return true if slug_or_id.nil? return true if slug_or_id.nil?
if slug_or_id == 'none' && params[:parent_category] parent_slug_or_id = 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 parent_category_id = nil
if parent_slug_or_id.present? if parent_slug_or_id.present?
parent_category_id = Category.query_parent_category(parent_slug_or_id) parent_category_id = Category.query_parent_category(parent_slug_or_id)
category_redirect_or_not_found && (return) if parent_category_id.blank? category_redirect_or_not_found && (return) if parent_category_id.blank?
end
@filter_on_category = Category.query_category(slug_or_id, parent_category_id)
end end
@filter_on_category = Category.query_category(slug_or_id, parent_category_id)
category_redirect_or_not_found && (return) if !@filter_on_category category_redirect_or_not_found && (return) if !@filter_on_category
guardian.ensure_can_see!(@filter_on_category) guardian.ensure_can_see!(@filter_on_category)

View File

@ -839,6 +839,7 @@ Discourse::Application.routes.draw do
get '/:tag_id.rss' => 'tags#tag_feed' get '/:tag_id.rss' => 'tags#tag_feed'
get '/:tag_id' => 'tags#show', as: 'tag_show' get '/:tag_id' => 'tags#show', as: 'tag_show'
get '/c/:category/:tag_id' => 'tags#show', as: 'tag_category_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 '/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 '/intersection/:tag_id/*additional_tag_ids' => 'tags#show', as: 'tag_intersection'
get '/:tag_id/notifications' => 'tags#notifications' get '/:tag_id/notifications' => 'tags#notifications'
@ -849,6 +850,7 @@ Discourse::Application.routes.draw do
Discourse.filters.each do |filter| Discourse.filters.each do |filter|
get "/:tag_id/l/#{filter}" => "tags#show_#{filter}", as: "tag_show_#{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/: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}" get "/c/:parent_category/:category/:tag_id/l/#{filter}" => "tags#show_#{filter}", as: "tag_parent_category_category_show_#{filter}"
end end
end end