Skip to content

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

FIX: ensures user can DM to show start new dm button (#35440)

Joffrey JAFFEUXc33c0f6019d3
diff --git a/plugins/chat/assets/javascripts/discourse/initializers/chat-sidebar.js b/plugins/chat/assets/javascripts/discourse/initializers/chat-sidebar.js
index 56c4bf29492..ce5117c81ce 100644
--- a/plugins/chat/assets/javascripts/discourse/initializers/chat-sidebar.js
+++ b/plugins/chat/assets/javascripts/discourse/initializers/chat-sidebar.js
@@ -501,7 +501,7 @@ export default {
currentUser: this.currentUser,
})
);
- } else {
+ } else if (this.currentUser.can_direct_message) {
return [new SidebarChatNewDirectMessagesSectionLink()];
}
}
@@ -545,7 +545,7 @@ export default {
get displaySection() {
return (
this.chatStateManager.hasPreloadedChannels &&
- (this.sectionLinks.length > 0 || this.userCanDirectMessage)
+ (this.sectionLinks?.length > 0 || this.userCanDirectMessage)
);
}
};
diff --git a/plugins/chat/spec/system/list_channels/sidebar_spec.rb b/plugins/chat/spec/system/list_channels/sidebar_spec.rb
index 109c43102da..08fc154ee94 100644
--- a/plugins/chat/spec/system/list_channels/sidebar_spec.rb
+++ b/plugins/chat/spec/system/list_channels/sidebar_spec.rb
@@ -5,6 +5,7 @@ RSpec.describe "List channels | sidebar", type: :system do
let(:chat) { PageObjects::Pages::Chat.new }
let(:drawer_page) { PageObjects::Pages::ChatDrawer.new }
+ let(:chat_sidebar) { PageObjects::Components::Chat::Sidebar.new }
before do
chat_system_bootstrap
@@ -134,17 +135,23 @@ RSpec.describe "List channels | sidebar", type: :system do
end
context "when no direct message channels" do
- before { visit("/") }
-
it "shows the start new dm button" do
- selector =
- ".sidebar-section[data-section-name='chat-dms'] .sidebar-section-link[data-link-name='new-chat-dm']"
+ visit("/")
+ chat_sidebar.click_start_new_dm
- expect(page).to have_selector(selector)
+ expect(page).to have_selector(".chat-modal-new-message")
+ end
- find(selector).click
+ context "when user can't dm" do
+ fab!(:group)
- expect(page).to have_selector(".chat-modal-new-message")
+ before { SiteSetting.direct_message_enabled_groups = group.id }
+
+ it "doesn't show the start new dm button" do
+ visit("/")
+
+ expect(chat_sidebar).to have_no_start_new_dm
+ end
end
end
diff --git a/plugins/chat/spec/system/page_objects/chat/components/sidebar.rb b/plugins/chat/spec/system/page_objects/chat/components/sidebar.rb
index 95984bfbbe4..3f86b80656f 100644
--- a/plugins/chat/spec/system/page_objects/chat/components/sidebar.rb
+++ b/plugins/chat/spec/system/page_objects/chat/components/sidebar.rb
@@ -37,6 +37,20 @@ module PageObjects
selector += " .sidebar-section-link.channel-#{channel.id}"
selector
end
+
+ NEW_START_DM_SELECTOR = ".sidebar-section-link[data-link-name='new-chat-dm']"
+
+ def has_no_start_new_dm?
+ has_no_selector?(NEW_START_DM_SELECTOR)
+ end
+
+ def has_start_new_dm?
+ has_selector?(NEW_START_DM_SELECTOR)
+ end
+
+ def click_start_new_dm
+ find(NEW_START_DM_SELECTOR).click
+ end
end
end
end