FEATURE: Allow changing slug on create channel (#19928)

This commit allows us to set the channel slug when creating new chat
channels. As well as this, it introduces a new `SlugsController` which can
generate a slug using `Slug.for` and a name string for input. We call this
after the user finishes typing the channel name (debounced) and fill in
the autogenerated slug in the background, and update the slug input
placeholder.

This autogenerated slug is used by default, but if the user writes anything
else in the input it will be used instead.
This commit is contained in:
Martin Brennan
2023-01-23 14:48:33 +10:00
committed by GitHub
parent ae20ce8654
commit 641e94fc3c
14 changed files with 322 additions and 48 deletions

View File

@ -57,7 +57,7 @@ class Chat::Api::ChatChannelsController < Chat::Api
def create
channel_params =
params.require(:channel).permit(:chatable_id, :name, :description, :auto_join_users)
params.require(:channel).permit(:chatable_id, :name, :slug, :description, :auto_join_users)
guardian.ensure_can_create_chat_channel!
if channel_params[:name].length > SiteSetting.max_topic_title_length
@ -81,6 +81,7 @@ class Chat::Api::ChatChannelsController < Chat::Api
channel =
chatable.create_chat_channel!(
name: channel_params[:name],
slug: channel_params[:slug],
description: channel_params[:description],
user_count: 1,
auto_join_users: auto_join_users,