mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Handle sub-sub-category paths without an id
This commit is contained in:
@@ -319,9 +319,7 @@ class ListController < ApplicationController
|
|||||||
if id.present?
|
if id.present?
|
||||||
@category = Category.find_by_id(id)
|
@category = Category.find_by_id(id)
|
||||||
elsif slug_path.present?
|
elsif slug_path.present?
|
||||||
if (1..2).include?(slug_path.size)
|
@category = Category.find_by_slug_path(slug_path)
|
||||||
@category = Category.find_by_slug(*slug_path.reverse)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Legacy paths
|
# Legacy paths
|
||||||
if @category.nil? && parts.last =~ /\A\d+-category/
|
if @category.nil? && parts.last =~ /\A\d+-category/
|
||||||
|
|||||||
@@ -359,9 +359,7 @@ class TagsController < ::ApplicationController
|
|||||||
if id.present?
|
if id.present?
|
||||||
@filter_on_category = Category.find_by_id(id)
|
@filter_on_category = Category.find_by_id(id)
|
||||||
elsif slug_path.present?
|
elsif slug_path.present?
|
||||||
if (1..2).include?(slug_path.size)
|
@filter_on_category = Category.find_by_slug_path(slug_path)
|
||||||
@filter_on_category = Category.find_by_slug(*slug_path.reverse)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Legacy paths
|
# Legacy paths
|
||||||
if @filter_on_category.nil? && parts.last =~ /\A\d+-category/
|
if @filter_on_category.nil? && parts.last =~ /\A\d+-category/
|
||||||
|
|||||||
@@ -777,22 +777,29 @@ class Category < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.find_by_slug(category_slug, parent_category_slug = nil)
|
def self.find_by_slug_path(slug_path)
|
||||||
|
return nil if slug_path.empty?
|
||||||
return nil if category_slug.nil?
|
return nil if slug_path.size > SiteSetting.max_category_nesting
|
||||||
|
|
||||||
if SiteSetting.slug_generation_method == "encoded"
|
if SiteSetting.slug_generation_method == "encoded"
|
||||||
parent_category_slug = CGI.escape(parent_category_slug) unless parent_category_slug.nil?
|
slug_path.map! { |slug| CGI.escape(slug) }
|
||||||
category_slug = CGI.escape(category_slug)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if parent_category_slug
|
query =
|
||||||
parent_category_id = self.where(slug: parent_category_slug, parent_category_id: nil).select(:id)
|
slug_path.inject(nil) do |parent_id, slug|
|
||||||
|
Category.where(
|
||||||
|
slug: slug,
|
||||||
|
parent_category_id: parent_id,
|
||||||
|
).select(:id)
|
||||||
|
end
|
||||||
|
|
||||||
self.where(slug: category_slug, parent_category_id: parent_category_id).first
|
Category.find_by_id(query)
|
||||||
else
|
end
|
||||||
self.where(slug: category_slug, parent_category_id: nil).first
|
|
||||||
end
|
def self.find_by_slug(category_slug, parent_category_slug = nil)
|
||||||
|
return nil if category_slug.nil?
|
||||||
|
|
||||||
|
find_by_slug_path([parent_category_slug, category_slug].compact)
|
||||||
end
|
end
|
||||||
|
|
||||||
def subcategory_list_includes_topics?
|
def subcategory_list_includes_topics?
|
||||||
|
|||||||
Reference in New Issue
Block a user