mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Support excluding categories with the category: filter (#21432)
This commit adds support for excluding categories when using the `category:` filter with the `-` prefix. For example, `-category:category-slug` will exclude all topics that belong to the category with slug "category-slug" and all of its sub-categories. To only exclude a particular category and not all of its sub-categories, the `-` prefix can be used with the `=` prefix. For example, `-=category:category-slug` will only exclude topics that belong to the category with slug "category-slug". Topics in the sub-categories of "category-slug" will still be included.
This commit is contained in:
committed by
GitHub
parent
be1cbc7082
commit
963bb3406e
@@ -1130,10 +1130,10 @@ RSpec.describe ListController do
|
||||
end
|
||||
|
||||
describe "#filter" do
|
||||
fab!(:category) { Fabricate(:category) }
|
||||
fab!(:category) { Fabricate(:category, slug: "category-slug") }
|
||||
fab!(:tag) { Fabricate(:tag, name: "tag1") }
|
||||
fab!(:group) { Fabricate(:group) }
|
||||
fab!(:private_category) { Fabricate(:private_category, group: Fabricate(:group)) }
|
||||
fab!(:private_category) { Fabricate(:private_category, group:, slug: "private-category-slug") }
|
||||
fab!(:private_message_topic) { Fabricate(:private_message_topic) }
|
||||
fab!(:topic_in_private_category) { Fabricate(:topic, category: private_category) }
|
||||
|
||||
@@ -1262,6 +1262,33 @@ RSpec.describe ListController do
|
||||
end
|
||||
end
|
||||
|
||||
describe "when filtering with the `category:<category_slug>` filter" do
|
||||
fab!(:topic_in_category) { Fabricate(:topic, category:) }
|
||||
|
||||
it "does not return any topics when `q` query param is `category:private-category-slug` and user is not allowed to see category" do
|
||||
sign_in(user)
|
||||
|
||||
get "/filter.json", params: { q: "category:private-category-slug" }
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
expect(response.parsed_body["topic_list"]["topics"].map { |topic| topic["id"] }).to eq([])
|
||||
end
|
||||
|
||||
it "returns only topics in the category when `q` query param is `category:private-category-slug` and user can see category" do
|
||||
group.add(user)
|
||||
|
||||
sign_in(user)
|
||||
|
||||
get "/filter.json", params: { q: "category:private-category-slug" }
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
|
||||
expect(
|
||||
response.parsed_body["topic_list"]["topics"].map { |topic| topic["id"] },
|
||||
).to contain_exactly(topic_in_private_category.id)
|
||||
end
|
||||
end
|
||||
|
||||
describe "when filtering with the `in:<topic_notification_level>` filter" do
|
||||
fab!(:user_muted_topic) do
|
||||
Fabricate(:topic).tap do |topic|
|
||||
|
||||
Reference in New Issue
Block a user