FEATURE: enable_public_channels site setting (#22565)

`SiteSetting.enable_public_channels` allows site admin to decide if public channels are available at all. There's no distinction between admins or not as we expect admins to create private category channels if they want to limit usage.
This commit is contained in:
Joffrey JAFFEUX
2023-07-13 10:00:25 +02:00
committed by GitHub
parent 9c9058d0c3
commit c996e5502f
23 changed files with 326 additions and 153 deletions
@@ -201,6 +201,12 @@ describe Chat::ChannelFetcher do
).to match_array([category_channel.id])
end
it "returns an empty array when public channels are disabled" do
SiteSetting.enable_public_channels = false
expect(described_class.secured_public_channels(guardian, following: nil)).to be_empty
end
it "can filter by channel name, or category name" do
expect(
described_class.secured_public_channels(
@@ -79,6 +79,11 @@ 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
@@ -144,6 +149,11 @@ 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
@@ -172,6 +182,11 @@ 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
@@ -16,6 +16,14 @@ RSpec.describe Chat::CreateCategoryChannel do
let(:guardian) { Guardian.new(current_user) }
let(:params) { { guardian: guardian, category_id: category_id, name: "cool channel" } }
context "when public channels are disabled" do
fab!(:current_user) { Fabricate(:user) }
before { SiteSetting.enable_public_channels = false }
it { is_expected.to fail_a_policy(:public_channels_enabled) }
end
context "when the current user cannot make a channel" do
fab!(:current_user) { Fabricate(:user) }
@@ -52,6 +52,14 @@ RSpec.describe Chat::SearchChatable do
expect(result.category_channels).to_not include(private_channel_1)
end
end
context "when public channels are disabled" do
it "does not return category channels" do
SiteSetting.enable_public_channels = false
expect(described_class.call(params).category_channels).to be_blank
end
end
end
context "when term is prefixed with #" do
@@ -20,6 +20,15 @@ RSpec.describe "Browse page", type: :system do
end
end
context "when public channels are disabled" do
before { SiteSetting.enable_public_channels = false }
it "redirects to homepage" do
visit("/chat/browse") # no page object here as we actually don't load it
expect(page).to have_current_path("/latest")
end
end
context "when user has chat enabled" do
context "when visiting browse page" do
it "defaults to open filer" do
@@ -20,6 +20,47 @@ RSpec.describe "New message", type: :system do
expect(chat_page.message_creator).to be_opened
end
context "when public channels are disabled" do
fab!(:channel_1) { Fabricate(:chat_channel) }
before do
SiteSetting.enable_public_channels = false
channel_1.add(current_user)
end
it "doesnt list public channels" do
visit("/")
chat_page.open_new_message
expect(chat_page.message_creator).to be_not_listing(channel_1)
end
it "has a correct placeholder" do
visit("/")
chat_page.open_new_message
expect(chat_page.message_creator.input["placeholder"]).to eq(
I18n.t("js.chat.new_message_modal.default_user_search_placeholder"),
)
end
end
context "when public channels are disabled and user can't create direct message" do
fab!(:current_user) { Fabricate(:user) }
before do
SiteSetting.enable_public_channels = false
SiteSetting.direct_message_enabled_groups = Group::AUTO_GROUPS[:staff]
end
it "doesnt list public channels" do
visit("/")
chat_page.open_new_message(ensure_open: false)
expect(chat_page.message_creator).to be_closed
end
end
context "when the the content is not filtered" do
fab!(:channel_1) { Fabricate(:chat_channel) }
fab!(:channel_2) { Fabricate(:chat_channel) }
@@ -29,9 +29,9 @@ module PageObjects
visit("/chat")
end
def open_new_message
def open_new_message(ensure_open: true)
send_keys([PLATFORM_KEY_MODIFIER, "k"])
find(".chat-modal-new-message")
find(".chat-modal-new-message") if ensure_open
end
def has_drawer?(channel_id: nil, expanded: true)
@@ -24,6 +24,10 @@ module PageObjects
page.has_css?(SELECTOR)
end
def closed?
page.has_no_css?(SELECTOR)
end
def enter_shortcut
input.send_keys(:enter)
end
@@ -3,19 +3,27 @@
module PageObjects
module Pages
class Sidebar < PageObjects::Pages::Base
PUBLIC_CHANNELS_SECTION_SELECTOR = ".sidebar-section[data-section-name='chat-channels']"
DM_CHANNELS_SECTION_SELECTOR = ".sidebar-section[data-section-name='chat-dms']"
def has_no_public_channels_section?
has_no_css?(PUBLIC_CHANNELS_SECTION_SELECTOR)
end
def channels_section
find(".sidebar-section[data-section-name='chat-channels']")
find(PUBLIC_CHANNELS_SECTION_SELECTOR)
end
def channels_section
find(PUBLIC_CHANNELS_SECTION_SELECTOR)
end
def dms_section
find(".sidebar-section[data-section-name='chat-dms']")
find(DM_CHANNELS_SECTION_SELECTOR)
end
def open_browse
find(
".sidebar-section[data-section-name='chat-channels'] .sidebar-section-header-button",
visible: false,
).click
channels_section.find(".sidebar-section-header-button", visible: false).click
end
def open_channel(channel)
+11
View File
@@ -8,6 +8,7 @@ RSpec.describe "Navigation", type: :system do
fab!(:category_channel) { Fabricate(:category_channel) }
fab!(:category_channel_2) { Fabricate(:category_channel) }
let(:chat_page) { PageObjects::Pages::Chat.new }
let(:sidebar_page) { PageObjects::Pages::Sidebar.new }
before do
chat_system_bootstrap(user, [category_channel, category_channel_2])
@@ -40,6 +41,16 @@ RSpec.describe "Navigation", type: :system do
expect(page).to have_no_css("#d-sidebar")
end
end
context "when public channels are disabled" do
before { SiteSetting.enable_public_channels = false }
it "has public channels section" do
visit("/")
expect(sidebar_page).to have_no_public_channels_section
end
end
end
context "when visiting on mobile" do