diff --git a/plugins/chat/spec/jobs/regular/auto_join_channel_batch_spec.rb b/plugins/chat/spec/jobs/regular/auto_join_channel_batch_spec.rb index e97776b10f..76dae56ce8 100644 --- a/plugins/chat/spec/jobs/regular/auto_join_channel_batch_spec.rb +++ b/plugins/chat/spec/jobs/regular/auto_join_channel_batch_spec.rb @@ -175,6 +175,27 @@ describe Jobs::AutoJoinChannelBatch do assert_users_follows_channel(channel, [user, another_user]) end + + it "doesn't join users with read-only access to the category" do + another_user = Fabricate(:user, last_seen_at: 15.minutes.ago) + non_chatters_group = Fabricate(:group) + readonly_channel = Fabricate(:category_channel, chatable: category, auto_join_users: true) + Fabricate( + :category_group, + category: category, + group: non_chatters_group, + permission_type: CategoryGroup.permission_types[:readonly], + ) + non_chatters_group.add(another_user) + + subject.execute( + chat_channel_id: readonly_channel.id, + starts_at: another_user.id, + ends_at: another_user.id, + ) + + assert_user_skipped(readonly_channel, another_user) + end end end diff --git a/plugins/chat/spec/system/visit_channel_spec.rb b/plugins/chat/spec/system/visit_channel_spec.rb index 2a7a45fa40..1c823e912d 100644 --- a/plugins/chat/spec/system/visit_channel_spec.rb +++ b/plugins/chat/spec/system/visit_channel_spec.rb @@ -93,6 +93,37 @@ RSpec.describe "Visit channel", type: :system, js: true do end end + context "when category channel is read-only" do + fab!(:readonly_category_1) { Fabricate(:private_category, group: Fabricate(:group)) } + fab!(:readonly_group_1) { Fabricate(:group, users: [current_user]) } + fab!(:readonly_category_channel_1) do + Fabricate(:private_category_channel, group: readonly_group_1) + end + fab!(:message_1) { Fabricate(:chat_message, chat_channel: readonly_category_channel_1) } + + before do + Fabricate( + :category_group, + category: readonly_category_1, + group: readonly_group_1, + permission_type: CategoryGroup.permission_types[:readonly], + ) + end + + it "doesn't allow user to join it" do + chat.visit_channel(readonly_category_channel_1) + + expect(page).not_to have_content(I18n.t("js.chat.channel_settings.join_channel")) + end + + it "shows a preview of the channel" do + chat.visit_channel(readonly_category_channel_1) + + expect(page).to have_content(readonly_category_channel_1.name) + expect(chat).to have_message(message_1) + end + end + context "when current user is not member of the channel" do context "when category channel" do fab!(:message_1) { Fabricate(:chat_message, chat_channel: category_channel_1) }