Skip to content

A platform for community discussion. Free, open, simple.

FIX: disable "Open channel" button on archived and read-only chat channels (#38053)

Régis Hanolfcccb3ac825e
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/routes/channel-info-settings.gjs b/plugins/chat/assets/javascripts/discourse/components/chat/routes/channel-info-settings.gjs
index 5313ce65f7d..3098900f621 100644
--- a/plugins/chat/assets/javascripts/discourse/components/chat/routes/channel-info-settings.gjs
+++ b/plugins/chat/assets/javascripts/discourse/components/chat/routes/channel-info-settings.gjs
@@ -6,6 +6,7 @@ import { LinkTo } from "@ember/routing";
import { service } from "@ember/service";
import DButton from "discourse/components/d-button";
import DToggleSwitch from "discourse/components/d-toggle-switch";
+import DTooltip from "discourse/float-kit/components/d-tooltip";
import categoryBadge from "discourse/helpers/category-badge";
import icon from "discourse/helpers/d-icon";
import replaceEmoji from "discourse/helpers/replace-emoji";
@@ -90,6 +91,17 @@ export default class ChatRouteChannelInfoSettings extends Component {
return this.chatGuardian.canArchiveChannel(this.args.channel);
}
+ get canToggleChannelState() {
+ return this.args.channel.isClosed;
+ }
+
+ get openChannelDisabledReason() {
+ if (this.args.channel.isArchived) {
+ return i18n("chat.channel_settings.open_channel_disabled_archived");
+ }
+ return i18n("chat.channel_settings.open_channel_disabled_read_only");
+ }
+
get toggleChannelWideMentionsAvailable() {
return this.args.channel.isCategoryChannel && this.args.channel.isOpen;
}
@@ -549,13 +561,30 @@ export default class ChatRouteChannelInfoSettings extends Component {
@icon="lock"
class="close-btn chat-form__btn btn-transparent"
/>
- {{else}}
+ {{else if this.canToggleChannelState}}
<DButton
@action={{this.onToggleChannelState}}
@label="chat.channel_settings.open_channel"
@icon="unlock"
class="open-btn chat-form__btn btn-transparent"
/>
+ {{else}}
+ <DTooltip
+ @identifier="channel-open-disabled"
+ @placement="left"
+ >
+ <:trigger>
+ <DButton
+ @label="chat.channel_settings.open_channel"
+ @icon="unlock"
+ @disabled={{true}}
+ class="open-btn chat-form__btn btn-transparent"
+ />
+ </:trigger>
+ <:content>
+ {{this.openChannelDisabledReason}}
+ </:content>
+ </DTooltip>
{{/if}}
</:action>
</section.row>
diff --git a/plugins/chat/config/locales/client.en.yml b/plugins/chat/config/locales/client.en.yml
index e2832762d10..b80d1f5a813 100644
--- a/plugins/chat/config/locales/client.en.yml
+++ b/plugins/chat/config/locales/client.en.yml
@@ -95,6 +95,8 @@ en:
unstar_channel: "Unstar channel"
close_channel: "Close channel"
open_channel: "Open channel"
+ open_channel_disabled_archived: "Archived channels cannot be reopened."
+ open_channel_disabled_read_only: "Read-only channels cannot be reopened."
archive_channel: "Archive channel"
delete_channel: "Delete channel"
join_channel: "Join channel"
diff --git a/plugins/chat/spec/system/archived_channel_settings_spec.rb b/plugins/chat/spec/system/archived_channel_settings_spec.rb
new file mode 100644
index 00000000000..b9f3dc71eff
--- /dev/null
+++ b/plugins/chat/spec/system/archived_channel_settings_spec.rb
@@ -0,0 +1,54 @@
+# frozen_string_literal: true
+
+RSpec.describe "Archived channel settings", type: :system do
+ fab!(:channel_1, :chat_channel)
+ fab!(:current_user, :admin)
+
+ let(:chat) { PageObjects::Pages::Chat.new }
+ let(:channel_settings) { PageObjects::Pages::ChatChannelSettings.new }
+
+ before do
+ chat_system_bootstrap
+ SiteSetting.chat_allow_archiving_channels = true
+ channel_1.add(current_user)
+ sign_in(current_user)
+ end
+
+ context "when channel is archived" do
+ before { channel_1.update!(status: :archived) }
+
+ it "shows a disabled open channel button with a tooltip" do
+ chat.visit_channel_settings(channel_1)
+
+ expect(channel_settings).to have_open_button(disabled: true)
+ expect(channel_settings).to have_no_close_button
+
+ channel_settings.hover_open_button
+ expect(page).to have_content(
+ I18n.t("js.chat.channel_settings.open_channel_disabled_archived"),
+ )
+ end
+
+ it "does not show the archive channel button" do
+ chat.visit_channel_settings(channel_1)
+
+ expect(page).to have_no_content(I18n.t("js.chat.channel_settings.archive_channel"))
+ end
+ end
+
+ context "when channel is read-only" do
+ before { channel_1.update!(status: :read_only) }
+
+ it "shows a disabled open channel button with a tooltip" do
+ chat.visit_channel_settings(channel_1)
+
+ expect(channel_settings).to have_open_button(disabled: true)
+ expect(channel_settings).to have_no_close_button
+
+ channel_settings.hover_open_button
+ expect(page).to have_content(
+ I18n.t("js.chat.channel_settings.open_channel_disabled_read_only"),
+ )
+ end
+ end
+end
diff --git a/plugins/chat/spec/system/page_objects/chat/chat_channel_settings.rb b/plugins/chat/spec/system/page_objects/chat/chat_channel_settings.rb
index 7d0373cb5e5..fbfa58f9d23 100644
--- a/plugins/chat/spec/system/page_objects/chat/chat_channel_settings.rb
+++ b/plugins/chat/spec/system/page_objects/chat/chat_channel_settings.rb
@@ -18,6 +18,31 @@ module PageObjects
def has_name?(name)
page.has_css?(".c-channel-settings__name", text: name)
end
+
+ def has_open_button?(disabled: false)
+ if disabled
+ page.has_css?(".open-btn[disabled]")
+ else
+ page.has_css?(".open-btn:not([disabled])")
+ end
+ end
+
+ def has_no_open_button?
+ page.has_no_css?(".open-btn")
+ end
+
+ def has_close_button?
+ page.has_css?(".close-btn")
+ end
+
+ def has_no_close_button?
+ page.has_no_css?(".close-btn")
+ end
+
+ def hover_open_button
+ find(".open-btn").hover
+ self
+ end
end
end
end