mirror of
https://github.com/discourse/discourse.git
synced 2025-03-06 11:19:51 +00:00
FIX: TopicQuery category lookup by slug
If we are searching for categories by their slugs, it doesn't make sense to include subcategories since a slug, by itself, does not necessarily uniquely identify a subcategory. Similarly, the empty string as a slug is not a good category identifier.
This commit is contained in:
parent
437edfc415
commit
790e1b7191
@ -640,9 +640,16 @@ class TopicQuery
|
|||||||
end
|
end
|
||||||
|
|
||||||
def get_category_id(category_id_or_slug)
|
def get_category_id(category_id_or_slug)
|
||||||
return nil unless category_id_or_slug
|
return nil unless category_id_or_slug.present?
|
||||||
category_id = category_id_or_slug.to_i
|
category_id = category_id_or_slug.to_i
|
||||||
category_id = Category.where(slug: category_id_or_slug).pluck_first(:id) if category_id == 0
|
|
||||||
|
if category_id == 0
|
||||||
|
category_id =
|
||||||
|
Category
|
||||||
|
.where(slug: category_id_or_slug, parent_category_id: nil)
|
||||||
|
.pluck_first(:id)
|
||||||
|
end
|
||||||
|
|
||||||
category_id
|
category_id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user