mirror of
https://github.com/discourse/discourse.git
synced 2024-12-21 09:03:49 +08:00
641e94fc3c
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.
23 lines
507 B
Ruby
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
|