A platform for community discussion. Free, open, simple.
FEATURE: enable_public_channels site setting (#22565)
Joffrey JAFFEUXc996e5502f6c
diff --git a/plugins/chat/app/services/chat/create_category_channel.rb b/plugins/chat/app/services/chat/create_category_channel.rbindex e13a35fb449..a9cf36d5c8b 100644--- a/plugins/chat/app/services/chat/create_category_channel.rb+++ b/plugins/chat/app/services/chat/create_category_channel.rb@@ -27,6 +27,7 @@ module Chat# @option params_to_create [Boolean] threading_enabled# @return [Service::Base::Context]+ policy :public_channels_enabledpolicy :can_create_channelcontractmodel :category, :fetch_category@@ -57,6 +58,10 @@ module Chatprivate+ def public_channels_enabled+ SiteSetting.enable_public_channels+ end+def can_create_channel(guardian:, **)guardian.can_create_chat_channel?enddiff --git a/plugins/chat/app/services/chat/search_chatable.rb b/plugins/chat/app/services/chat/search_chatable.rbindex 6382d1b48b1..d0edb6435dd 100644--- a/plugins/chat/app/services/chat/search_chatable.rb+++ b/plugins/chat/app/services/chat/search_chatable.rb@@ -56,6 +56,7 @@ module Chatdef fetch_category_channels(guardian:, **)return if context.mode == :user+ return if !SiteSetting.enable_public_channelscontext.category_channels =::Chat::ChannelFetcher.secured_public_channel_search(diff --git a/plugins/chat/assets/javascripts/discourse/components/channels-list.js b/plugins/chat/assets/javascripts/discourse/components/channels-list.jsindex 9f6e96e87c0..b7011cfbae8 100644--- a/plugins/chat/assets/javascripts/discourse/components/channels-list.js+++ b/plugins/chat/assets/javascripts/discourse/components/channels-list.js@@ -12,6 +12,7 @@ export default class ChannelsList extends Component {@service chatStateManager;@service chatChannelsManager;@service site;+ @service siteSettings;@service session;@service currentUser;@service modal;@@ -71,6 +72,10 @@ export default class ChannelsList extends Component {}get displayPublicChannels() {+ if (!this.siteSettings.enable_public_channels) {+ return false;+ }+if (this.publicMessageChannelsEmpty) {return (this.currentUser?.staff ||diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/message-creator.js b/plugins/chat/assets/javascripts/discourse/components/chat/message-creator.jsindex 28a81bd9750..292b78098d1 100644--- a/plugins/chat/assets/javascripts/discourse/components/chat/message-creator.js+++ b/plugins/chat/assets/javascripts/discourse/components/chat/message-creator.js@@ -113,6 +113,7 @@ export default class ChatMessageCreator extends Component {@service site;@service router;@service currentUser;+ @service siteSettings;@tracked selection = new TrackedArray();@tracked activeSelection = new TrackedArray();@@ -124,10 +125,25 @@ export default class ChatMessageCreator extends Component {@tracked _activeResultIdentifier = null;get placeholder() {- if (this.hasSelectedUsers) {- return I18n.t("chat.new_message_modal.user_search_placeholder");- } else {- return I18n.t("chat.new_message_modal.default_search_placeholder");+ if (+ this.siteSettings.enable_public_channels &&+ this.chat.userCanDirectMessage+ ) {+ if (this.hasSelectedUsers) {+ return I18n.t("chat.new_message_modal.user_search_placeholder");+ } else {+ return I18n.t("chat.new_message_modal.default_search_placeholder");+ }+ } else if (this.siteSettings.enable_public_channels) {+ return I18n.t(+ "chat.new_message_modal.default_channel_search_placeholder"+ );+ } else if (this.chat.userCanDirectMessage) {+ if (this.hasSelectedUsers) {+ return I18n.t("chat.new_message_modal.user_search_placeholder");+ } else {+ return I18n.t("chat.new_message_modal.default_user_search_placeholder");+ }}}diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/modal/new-message.hbs b/plugins/chat/assets/javascripts/discourse/components/chat/modal/new-message.hbsindex 05b535f5e6c..883cf9903b2 100644--- a/plugins/chat/assets/javascripts/discourse/components/chat/modal/new-message.hbs+++ b/plugins/chat/assets/javascripts/discourse/components/chat/modal/new-message.hbs@@ -1,8 +1,10 @@-<DModal- @closeModal={{@closeModal}}- class="chat-modal-new-message"- @title="chat.new_message_modal.title"- @inline={{@inline}}->- <Chat::MessageCreator @onClose={{@closeModal}} />-</DModal>\ No newline at end of file+{{#if this.shouldRender}}+ <DModal+ @closeModal={{@closeModal}}+ class="chat-modal-new-message"+ @title="chat.new_message_modal.title"+ @inline={{@inline}}+ >+ <Chat::MessageCreator @onClose={{@closeModal}} />+ </DModal>+{{/if}}\ No newline at end of filediff --git a/plugins/chat/assets/javascripts/discourse/components/chat/modal/new-message.js b/plugins/chat/assets/javascripts/discourse/components/chat/modal/new-message.jsnew file mode 100644index 00000000000..14bf3e405e0--- /dev/null+++ b/plugins/chat/assets/javascripts/discourse/components/chat/modal/new-message.js@@ -0,0 +1,14 @@+import Component from "@glimmer/component";++import { inject as service } from "@ember/service";++export default class ChatModalNewMessage extends Component {+ @service chat;+ @service siteSettings;++ get shouldRender() {+ return (+ this.siteSettings.enable_public_channels || this.chat.userCanDirectMessage+ );+ }+}diff --git a/plugins/chat/assets/javascripts/discourse/initializers/chat-sidebar.js b/plugins/chat/assets/javascripts/discourse/initializers/chat-sidebar.jsindex 7462a216b71..acb1bd1c225 100644--- a/plugins/chat/assets/javascripts/discourse/initializers/chat-sidebar.js+++ b/plugins/chat/assets/javascripts/discourse/initializers/chat-sidebar.js@@ -21,155 +21,159 @@ export default {return;}- withPluginApi("1.3.0", (api) => {- api.addSidebarSection(- (BaseCustomSidebarSection, BaseCustomSidebarSectionLink) => {- const SidebarChatChannelsSectionLink = class extends BaseCustomSidebarSectionLink {- constructor({ channel, chatService }) {- super(...arguments);- this.channel = channel;- this.chatService = chatService;- }-- get name() {- return dasherize(this.channel.slugifiedTitle);- }-- get classNames() {- const classes = [];+ this.siteSettings = container.lookup("service:site-settings");- if (this.channel.currentUserMembership.muted) {- classes.push("sidebar-section-link--muted");+ withPluginApi("1.3.0", (api) => {+ if (this.siteSettings.enable_public_channels) {+ api.addSidebarSection(+ (BaseCustomSidebarSection, BaseCustomSidebarSectionLink) => {+ const SidebarChatChannelsSectionLink = class extends BaseCustomSidebarSectionLink {+ constructor({ channel, chatService }) {+ super(...arguments);+ this.channel = channel;+ this.chatService = chatService;}- if (this.channel.id === this.chatService.activeChannel?.id) {- classes.push("sidebar-section-link--active");+ get name() {+ return dasherize(this.channel.slugifiedTitle);}- classes.push(`channel-${this.channel.id}`);+ get classNames() {+ const classes = [];- return classes.join(" ");- }+ if (this.channel.currentUserMembership.muted) {+ classes.push("sidebar-section-link--muted");+ }- get route() {- return "chat.channel";- }+ if (this.channel.id === this.chatService.activeChannel?.id) {+ classes.push("sidebar-section-link--active");+ }- get models() {- return this.channel.routeModels;- }+ classes.push(`channel-${this.channel.id}`);- get text() {- return htmlSafe(emojiUnescape(this.channel.escapedTitle));- }+ return classes.join(" ");+ }- get prefixType() {- return "icon";- }+ get route() {+ return "chat.channel";+ }- get prefixValue() {- return "d-chat";- }+ get models() {+ return this.channel.routeModels;+ }- get prefixColor() {- return this.channel.chatable.color;- }+ get text() {+ return htmlSafe(emojiUnescape(this.channel.escapedTitle));+ }- get title() {- return this.channel.escapedDescription- ? htmlSafe(this.channel.escapedDescription)- : `${this.channel.escapedTitle} ${I18n.t("chat.title")}`;- }+ get prefixType() {+ return "icon";+ }- get prefixBadge() {- return this.channel.chatable.read_restricted ? "lock" : "";- }+ get prefixValue() {+ return "d-chat";+ }- get suffixType() {- return "icon";- }+ get prefixColor() {+ return this.channel.chatable.color;+ }- get suffixValue() {- return this.channel.tracking.unreadCount > 0 ? "circle" : "";- }+ get title() {+ return this.channel.escapedDescription+ ? htmlSafe(this.channel.escapedDescription)+ : `${this.channel.escapedTitle} ${I18n.t("chat.title")}`;+ }- get suffixCSSClass() {- return this.channel.tracking.mentionCount > 0- ? "urgent"- : "unread";- }- };+ get prefixBadge() {+ return this.channel.chatable.read_restricted ? "lock" : "";+ }- const SidebarChatChannelsSection = class extends BaseCustomSidebarSection {- @tracked currentUserCanJoinPublicChannels =- this.sidebar.currentUser &&- (this.sidebar.currentUser.staff ||- this.sidebar.currentUser.has_joinable_public_channels);+ get suffixType() {+ return "icon";+ }- constructor() {- super(...arguments);+ get suffixValue() {+ return this.channel.tracking.unreadCount > 0 ? "circle" : "";+ }- if (container.isDestroyed) {- return;+ get suffixCSSClass() {+ return this.channel.tracking.mentionCount > 0+ ? "urgent"+ : "unread";+ }+ };++ const SidebarChatChannelsSection = class extends BaseCustomSidebarSection {+ @tracked currentUserCanJoinPublicChannels =+ this.sidebar.currentUser &&+ (this.sidebar.currentUser.staff ||+ this.sidebar.currentUser.has_joinable_public_channels);++ constructor() {+ super(...arguments);++ if (container.isDestroyed) {+ return;+ }+ this.chatService = container.lookup("service:chat");+ this.chatChannelsManager = container.lookup(+ "service:chat-channels-manager"+ );+ this.router = container.lookup("service:router");}- this.chatService = container.lookup("service:chat");- this.chatChannelsManager = container.lookup(- "service:chat-channels-manager"- );- this.router = container.lookup("service:router");- }- get sectionLinks() {- return this.chatChannelsManager.publicMessageChannels.map(- (channel) =>- new SidebarChatChannelsSectionLink({- channel,- chatService: this.chatService,- })- );- }+ get sectionLinks() {+ return this.chatChannelsManager.publicMessageChannels.map(+ (channel) =>+ new SidebarChatChannelsSectionLink({+ channel,+ chatService: this.chatService,+ })+ );+ }- get name() {- return "chat-channels";- }+ get name() {+ return "chat-channels";+ }- get title() {- return I18n.t("chat.chat_channels");- }+ get title() {+ return I18n.t("chat.chat_channels");+ }- get text() {- return I18n.t("chat.chat_channels");- }+ get text() {+ return I18n.t("chat.chat_channels");+ }- get actions() {- return [- {- id: "browseChannels",- title: I18n.t("chat.channels_list_popup.browse"),- action: () => this.router.transitionTo("chat.browse.open"),- },- ];- }+ get actions() {+ return [+ {+ id: "browseChannels",+ title: I18n.t("chat.channels_list_popup.browse"),+ action: () => this.router.transitionTo("chat.browse.open"),+ },+ ];+ }- get actionsIcon() {- return "pencil-alt";- }+ get actionsIcon() {+ return "pencil-alt";+ }- get links() {- return this.sectionLinks;- }+ get links() {+ return this.sectionLinks;+ }- get displaySection() {- return (- this.sectionLinks.length > 0 ||- this.currentUserCanJoinPublicChannels- );- }- };+ get displaySection() {+ return (+ this.sectionLinks.length > 0 ||+ this.currentUserCanJoinPublicChannels+ );+ }+ };- return SidebarChatChannelsSection;- }- );+ return SidebarChatChannelsSection;+ }+ );+ }api.addSidebarSection((BaseCustomSidebarSection, BaseCustomSidebarSectionLink) => {diff --git a/plugins/chat/assets/javascripts/discourse/routes/chat-browse-index.js b/plugins/chat/assets/javascripts/discourse/routes/chat-browse-index.jsindex 12fd2d14672..927e5ed122e 100644--- a/plugins/chat/assets/javascripts/discourse/routes/chat-browse-index.js+++ b/plugins/chat/assets/javascripts/discourse/routes/chat-browse-index.js@@ -1,8 +1,16 @@import DiscourseRoute from "discourse/routes/discourse";import { inject as service } from "@ember/service";+import { defaultHomepage } from "discourse/lib/utilities";export default class ChatBrowseIndexRoute extends DiscourseRoute {@service chat;+ @service siteSettings;++ beforeModel() {+ if (!this.siteSettings.enable_public_channels) {+ return this.transitionTo(`discovery.${defaultHomepage()}`);+ }+ }activate() {this.chat.activeChannel = null;diff --git a/plugins/chat/config/locales/client.en.yml b/plugins/chat/config/locales/client.en.ymlindex ade698a41d9..5a4d15c0e3f 100644--- a/plugins/chat/config/locales/client.en.yml+++ b/plugins/chat/config/locales/client.en.yml@@ -330,6 +330,8 @@ en:add_user_short: <span>Add user</span>open_channel: <span>Open channel</span>default_search_placeholder: "#a-channel, @somebody or anything"+ default_channel_search_placeholder: "#a-channel"+ default_user_search_placeholder: "@somebody"user_search_placeholder: "...add more users"disabled_user: "has disabled chat"no_items: "No items"diff --git a/plugins/chat/config/locales/server.en.yml b/plugins/chat/config/locales/server.en.ymlindex 8e4cbabb7c1..afc1fcc06b4 100644--- a/plugins/chat/config/locales/server.en.yml+++ b/plugins/chat/config/locales/server.en.yml@@ -1,6 +1,7 @@en:site_settings:chat_enabled: "Enable the chat plugin."+ enable_public_channels: "Enable public channels based on categories."chat_allowed_groups: "Users in these groups can chat. Note that staff can always access chat."chat_channel_retention_days: "Chat messages in regular channels will be retained for this many days. Set to '0' to retain messages forever."chat_dm_retention_days: "Chat messages in personal chat channels will be retained for this many days. Set to '0' to retain messages forever."diff --git a/plugins/chat/config/settings.yml b/plugins/chat/config/settings.ymlindex 27b29a5a8a3..97e8575ddb0 100644--- a/plugins/chat/config/settings.yml+++ b/plugins/chat/config/settings.yml@@ -2,6 +2,9 @@ chat:chat_enabled:default: trueclient: true+ enable_public_channels:+ default: true+ client: truechat_allowed_groups:client: truetype: group_listdiff --git a/plugins/chat/lib/chat/channel_fetcher.rb b/plugins/chat/lib/chat/channel_fetcher.rbindex 4a9c1f87854..9cef651fa23 100644--- a/plugins/chat/lib/chat/channel_fetcher.rb+++ b/plugins/chat/lib/chat/channel_fetcher.rb@@ -86,6 +86,8 @@ module Chatenddef self.secured_public_channel_search(guardian, options = {})+ return ::Chat::Channel.none if !SiteSetting.enable_public_channels+allowed_channel_ids = generate_allowed_channel_ids_sql(guardian, exclude_dm_channels: true)channels = Chat::Channel.includes(:last_message, chatable: [:topic_only_relative_url])diff --git a/plugins/chat/lib/chat/channel_hashtag_data_source.rb b/plugins/chat/lib/chat/channel_hashtag_data_source.rbindex e31e96d0b22..538e5566f50 100644--- a/plugins/chat/lib/chat/channel_hashtag_data_source.rb+++ b/plugins/chat/lib/chat/channel_hashtag_data_source.rb@@ -23,7 +23,7 @@ module Chatenddef self.lookup(guardian, slugs)- if SiteSetting.enable_experimental_hashtag_autocomplete+ if SiteSetting.enable_experimental_hashtag_autocomplete && SiteSetting.enable_public_channelsreturn [] if !guardian.can_chat?Chat::ChannelFetcher.secured_public_channel_slug_lookup(guardian, slugs)@@ -39,7 +39,7 @@ module Chatlimit,condition = HashtagAutocompleteService.search_conditions[:contains])- if SiteSetting.enable_experimental_hashtag_autocomplete+ if SiteSetting.enable_experimental_hashtag_autocomplete && SiteSetting.enable_public_channelsreturn [] if !guardian.can_chat?Chat::ChannelFetcher.secured_public_channel_search(@@ -61,7 +61,7 @@ module Chatenddef self.search_without_term(guardian, limit)- if SiteSetting.enable_experimental_hashtag_autocomplete+ if SiteSetting.enable_experimental_hashtag_autocomplete && SiteSetting.enable_public_channelsreturn [] if !guardian.can_chat?allowed_channel_ids_sql =Chat::ChannelFetcher.generate_allowed_channel_ids_sql(guardian, exclude_dm_channels: true)diff --git a/plugins/chat/spec/lib/chat/channel_fetcher_spec.rb b/plugins/chat/spec/lib/chat/channel_fetcher_spec.rbindex 65f02b4bd39..6d0a31f3e9d 100644--- a/plugins/chat/spec/lib/chat/channel_fetcher_spec.rb+++ b/plugins/chat/spec/lib/chat/channel_fetcher_spec.rb@@ -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" doexpect(described_class.secured_public_channels(diff --git a/plugins/chat/spec/lib/chat/channel_hashtag_data_source_spec.rb b/plugins/chat/spec/lib/chat/channel_hashtag_data_source_spec.rbindex 4aff20fb3f4..f6f9a46e87d 100644--- a/plugins/chat/spec/lib/chat/channel_hashtag_data_source_spec.rb+++ b/plugins/chat/spec/lib/chat/channel_hashtag_data_source_spec.rb@@ -79,6 +79,11 @@ RSpec.describe Chat::ChannelHashtagDataSource doGroup.refresh_automatic_groups!expect(described_class.lookup(Guardian.new(user), ["random"])).to be_emptyend++ it "returns an empty array if public channels are disabled" do+ SiteSetting.enable_public_channels = false+ expect(described_class.lookup(guardian, ["random"])).to eq([])+ endenddescribe "#search" do@@ -144,6 +149,11 @@ RSpec.describe Chat::ChannelHashtagDataSource doGroup.refresh_automatic_groups!expect(described_class.search(Guardian.new(user), "rand", 10)).to be_emptyend++ 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([])+ endenddescribe "#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" doexpect(described_class.search_without_term(guardian, 5).map(&:slug)).not_to include("secret")enddiff --git a/plugins/chat/spec/services/chat/create_category_channel_spec.rb b/plugins/chat/spec/services/chat/create_category_channel_spec.rbindex 0ad01dfe3b1..ef4742a9c70 100644--- a/plugins/chat/spec/services/chat/create_category_channel_spec.rb+++ b/plugins/chat/spec/services/chat/create_category_channel_spec.rb@@ -16,6 +16,14 @@ RSpec.describe Chat::CreateCategoryChannel dolet(: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" dofab!(:current_user) { Fabricate(:user) }diff --git a/plugins/chat/spec/services/chat/search_chatable_spec.rb b/plugins/chat/spec/services/chat/search_chatable_spec.rbindex 46da6e84fc1..831032a7f58 100644--- a/plugins/chat/spec/services/chat/search_chatable_spec.rb+++ b/plugins/chat/spec/services/chat/search_chatable_spec.rb@@ -52,6 +52,14 @@ RSpec.describe Chat::SearchChatable doexpect(result.category_channels).to_not include(private_channel_1)endend++ 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+ endendcontext "when term is prefixed with #" dodiff --git a/plugins/chat/spec/system/browse_page_spec.rb b/plugins/chat/spec/system/browse_page_spec.rbindex 30d7905884b..2568a04c801 100644--- a/plugins/chat/spec/system/browse_page_spec.rb+++ b/plugins/chat/spec/system/browse_page_spec.rb@@ -20,6 +20,15 @@ RSpec.describe "Browse page", type: :system doendend+ 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" docontext "when visiting browse page" doit "defaults to open filer" dodiff --git a/plugins/chat/spec/system/new_message_spec.rb b/plugins/chat/spec/system/new_message_spec.rbindex 8a1877a53f0..f82e4951e69 100644--- a/plugins/chat/spec/system/new_message_spec.rb+++ b/plugins/chat/spec/system/new_message_spec.rb@@ -20,6 +20,47 @@ RSpec.describe "New message", type: :system doexpect(chat_page.message_creator).to be_openedend+ 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 "doesn’t 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 "doesn’t 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" dofab!(:channel_1) { Fabricate(:chat_channel) }fab!(:channel_2) { Fabricate(:chat_channel) }diff --git a/plugins/chat/spec/system/page_objects/chat/chat.rb b/plugins/chat/spec/system/page_objects/chat/chat.rbindex 9c2289a1dc5..fe58d03c73a 100644--- a/plugins/chat/spec/system/page_objects/chat/chat.rb+++ b/plugins/chat/spec/system/page_objects/chat/chat.rb@@ -29,9 +29,9 @@ module PageObjectsvisit("/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_openenddef has_drawer?(channel_id: nil, expanded: true)diff --git a/plugins/chat/spec/system/page_objects/chat/components/message_creator.rb b/plugins/chat/spec/system/page_objects/chat/components/message_creator.rbindex 896c3b27776..d6e8c692eb9 100644--- a/plugins/chat/spec/system/page_objects/chat/components/message_creator.rb+++ b/plugins/chat/spec/system/page_objects/chat/components/message_creator.rb@@ -24,6 +24,10 @@ module PageObjectspage.has_css?(SELECTOR)end+ def closed?+ page.has_no_css?(SELECTOR)+ end+def enter_shortcutinput.send_keys(:enter)enddiff --git a/plugins/chat/spec/system/page_objects/sidebar/sidebar.rb b/plugins/chat/spec/system/page_objects/sidebar/sidebar.rbindex a7e88361d45..70de387e958 100644--- a/plugins/chat/spec/system/page_objects/sidebar/sidebar.rb+++ b/plugins/chat/spec/system/page_objects/sidebar/sidebar.rb@@ -3,19 +3,27 @@module PageObjectsmodule Pagesclass 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(PUBLIC_CHANNELS_SECTION_SELECTOR)+ end+def channels_section- find(".sidebar-section[data-section-name='chat-channels']")+ find(PUBLIC_CHANNELS_SECTION_SELECTOR)enddef dms_section- find(".sidebar-section[data-section-name='chat-dms']")+ find(DM_CHANNELS_SECTION_SELECTOR)enddef 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).clickenddef open_channel(channel)diff --git a/plugins/chat/spec/system/sidebars_spec.rb b/plugins/chat/spec/system/sidebars_spec.rbindex 2fa654ce373..d1df0415164 100644--- a/plugins/chat/spec/system/sidebars_spec.rb+++ b/plugins/chat/spec/system/sidebars_spec.rb@@ -8,6 +8,7 @@ RSpec.describe "Navigation", type: :system dofab!(: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 dochat_system_bootstrap(user, [category_channel, category_channel_2])@@ -40,6 +41,16 @@ RSpec.describe "Navigation", type: :system doexpect(page).to have_no_css("#d-sidebar")endend++ 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+ endendcontext "when visiting on mobile" do