Skip to content

Commit

Permalink
fix: Prevent slug regenerating for server content storage (#2288)
Browse files Browse the repository at this point in the history
  • Loading branch information
JanCizmar authored Apr 29, 2024
1 parent b157214 commit 0a8372f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,28 @@ class ContentDeliveryConfigControllerTest : ProjectAuthControllerTest("/v2/proje
}
}

@Test
@ProjectJWTAuthTestMethod
fun `does not regenerate slug when not using custom storage`() {
val slug = testData.defaultServerContentDeliveryConfig.self.slug
performProjectAuthPut(
"content-delivery-configs/${testData.defaultServerContentDeliveryConfig.self.id}",
mapOf("name" to "S3 new"),
).andIsOk.andAssertThatJson {
node("slug").isEqualTo(slug)
}
}

@Test
@ProjectJWTAuthTestMethod
fun `throws when custom slug is used with default storage`() {
val slug = testData.defaultServerContentDeliveryConfig.self.slug
performProjectAuthPut(
"content-delivery-configs/${testData.defaultServerContentDeliveryConfig.self.id}",
mapOf("name" to "S3 new", "slug" to "hello"),
).andIsBadRequest
}

private fun createWithCustomSlug() =
performProjectAuthPost(
"content-delivery-configs",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ class ContentDeliveryConfigService(
val wasCustomStorage = config.contentStorage != null
val nowCustomStorage = dto.contentStorageId != null

if (!wasCustomStorage && !nowCustomStorage && desiredSlug == null) {
return
}

if (desiredSlug == null) {
config.slug = generateSlug()
config.customSlug = false
Expand Down

0 comments on commit 0a8372f

Please sign in to comment.