mirror of
https://github.com/discourse/discourse.git
synced 2025-05-30 15:28:37 +08:00
DEV: Introduce enabled? API to hashtag data sources (#22632)
We need a nice way to only return some hashtag data sources based on various site settings. This commit adds an enabled? method that every hashtag data source must implement. If this returns false the data source will not be used at all for hashtag lookups or search.
This commit is contained in:
@ -32,6 +32,18 @@ RSpec.describe Chat::ChannelHashtagDataSource do
|
||||
Group.refresh_automatic_groups!
|
||||
end
|
||||
|
||||
describe "#enabled?" do
|
||||
it "returns false if public channels are disabled" do
|
||||
SiteSetting.enable_public_channels = false
|
||||
expect(described_class.enabled?).to eq(false)
|
||||
end
|
||||
|
||||
it "returns true if public channels are disabled" do
|
||||
SiteSetting.enable_public_channels = true
|
||||
expect(described_class.enabled?).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#lookup" do
|
||||
it "finds a channel by a slug" do
|
||||
result = described_class.lookup(guardian, ["random"]).first
|
||||
@ -79,11 +91,6 @@ RSpec.describe Chat::ChannelHashtagDataSource do
|
||||
Group.refresh_automatic_groups!
|
||||
expect(described_class.lookup(Guardian.new(user), ["random"])).to be_empty
|
||||
end
|
||||
|
||||
it "returns an empty array if public channels are disabled" do
|
||||
SiteSetting.enable_public_channels = false
|
||||
expect(described_class.lookup(guardian, ["random"])).to eq([])
|
||||
end
|
||||
end
|
||||
|
||||
describe "#search" do
|
||||
@ -149,11 +156,6 @@ RSpec.describe Chat::ChannelHashtagDataSource do
|
||||
Group.refresh_automatic_groups!
|
||||
expect(described_class.search(Guardian.new(user), "rand", 10)).to be_empty
|
||||
end
|
||||
|
||||
it "returns an empty array if public channels are disabled" do
|
||||
SiteSetting.enable_public_channels = false
|
||||
expect(described_class.search(guardian, "rand", 10)).to eq([])
|
||||
end
|
||||
end
|
||||
|
||||
describe "#search_without_term" do
|
||||
@ -182,11 +184,6 @@ RSpec.describe Chat::ChannelHashtagDataSource do
|
||||
)
|
||||
end
|
||||
|
||||
it "returns an empty array if public channels are disabled" do
|
||||
SiteSetting.enable_public_channels = false
|
||||
expect(described_class.search_without_term(guardian, 5)).to eq([])
|
||||
end
|
||||
|
||||
it "does not return channels the user does not have permission to view" do
|
||||
expect(described_class.search_without_term(guardian, 5).map(&:slug)).not_to include("secret")
|
||||
end
|
||||
|
Reference in New Issue
Block a user