Skip to content

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

FIX: Allow several chat channels to have an empty slug (#25680)

Andrei Prigorshneve83d8fb3e20f
diff --git a/plugins/chat/db/migrate/20240214135517_fix_chat_channel_slug_index.rb b/plugins/chat/db/migrate/20240214135517_fix_chat_channel_slug_index.rb
new file mode 100644
index 00000000000..e797d4f97de
--- /dev/null
+++ b/plugins/chat/db/migrate/20240214135517_fix_chat_channel_slug_index.rb
@@ -0,0 +1,12 @@
+# frozen_string_literal: true
+
+class FixChatChannelSlugIndex < ActiveRecord::Migration[7.0]
+ def up
+ remove_index(:chat_channels, :slug)
+ add_index :chat_channels, :slug, unique: true, where: "slug != ''"
+ end
+
+ def down
+ raise ActiveRecord::IrreversibleMigration
+ end
+end
diff --git a/plugins/chat/spec/services/chat/create_category_channel_spec.rb b/plugins/chat/spec/services/chat/create_category_channel_spec.rb
index 10458521da0..ea0fc252a15 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,21 @@ RSpec.describe Chat::CreateCategoryChannel do
let(:guardian) { Guardian.new(current_user) }
let(:params) { { guardian: guardian, category_id: category_id, name: "cool channel" } }
+ it "can create several channels with empty slugs" do
+ SiteSetting.slug_generation_method = "none"
+ expect do
+ described_class.call(params.merge(name: "channel 1", slug: nil))
+ end.not_to raise_error
+ expect do
+ described_class.call(params.merge(name: "channel 2", slug: nil))
+ end.not_to raise_error
+ end
+
+ it "can create several channels with unicode names" do
+ expect do described_class.call(params.merge(name: "マイキ")) end.not_to raise_error
+ expect do described_class.call(params.merge(name: "境界")) end.not_to raise_error
+ end
+
context "when public channels are disabled" do
fab!(:current_user) { Fabricate(:user) }