discourse/app/controllers/slugs_controller.rb
Martin Brennan 641e94fc3c
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.
2023-01-23 14:48:33 +10:00

23 lines
507 B
Ruby

# frozen_string_literal: true
class SlugsController < ApplicationController
requires_login
MAX_SLUG_GENERATIONS_PER_MINUTE = 20
def generate
params.require(:name)
raise Discourse::InvalidAccess if !current_user.has_trust_level_or_staff?(TrustLevel[4])
RateLimiter.new(
current_user,
"max-slug-generations-per-minute",
MAX_SLUG_GENERATIONS_PER_MINUTE,
1.minute,
).performed!
render json: success_json.merge(slug: Slug.for(params[:name], ""))
end
end