FIX: generates automatic slug for trashed channels (#19908)

Prior to this fix trashed channels would still prevent a channel with the same slug to be created. This commit generates a new slug on trash and frees the slug for future usage.

The format used for the slug is: `YYYYMMDD-HHMM-OLD_SLUG-deleted` truncated to the max length of a channel name.
This commit is contained in:
Joffrey JAFFEUX 2023-01-23 15:05:47 +01:00 committed by GitHub
parent b26e0dcf35
commit 34d158c4aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 0 deletions

View File

@ -38,6 +38,13 @@ class Chat::Api::ChatChannelsController < Chat::Api
begin
ChatChannel.transaction do
channel_from_params.update!(
slug:
"#{Time.now.strftime("%Y%m%d-%H%M")}-#{channel_from_params.slug}-deleted".truncate(
SiteSetting.max_topic_title_length,
omission: "",
),
)
channel_from_params.trash!(current_user)
StaffActionLogger.new(current_user).log_custom(
"chat_channel_delete",

View File

@ -236,6 +236,27 @@ RSpec.describe Chat::Api::ChatChannelsController do
),
).to eq(true)
end
it "generates a valid new slug to prevent collisions" do
SiteSetting.max_topic_title_length = 15
freeze_time(DateTime.parse("2022-07-08 09:30:00"))
old_slug = channel_1.slug
delete "/chat/api/channels/#{channel_1.id}",
params: {
channel: {
name_confirmation: channel_1.title(current_user),
},
}
expect(response.status).to eq(200)
expect(channel_1.reload.slug).to eq(
"20220708-0930-#{old_slug}-deleted".truncate(
SiteSetting.max_topic_title_length,
omission: "",
),
)
end
end
end
end