Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,18 @@ class ContentDeliveryConfigService(
id: Long,
dto: ContentDeliveryConfigRequest,
): ContentDeliveryConfig {
projectFeatureGuard.checkIfUsed(Feature.BRANCHING, dto.filterBranch)
checkMultipleConfigsFeature(projectService.get(projectId), maxCurrentAllowed = 1)
val config = get(projectId, id)
handleUpdateSlug(config, dto)
config.contentStorage = getStorage(projectId, dto.contentStorageId)
config.name = dto.name
config.pruneBeforePublish = dto.pruneBeforePublish
config.zip = dto.zip
config.branch = branchService.getActiveOrDefault(projectId, dto.filterBranch)
val newBranch = branchService.getActiveOrDefault(projectId, dto.filterBranch)
if (newBranch?.isDefault == false || config.branch?.isDefault == false) {
projectFeatureGuard.checkEnabled(Feature.BRANCHING)
}
config.branch = newBranch
config.copyPropsFrom(dto)
handleUpdateAutoPublish(dto, config)
return save(config)
Expand Down
19 changes: 19 additions & 0 deletions e2e/cypress/e2e/branching/contentDeliveryBranching.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,25 @@ describe('Content delivery with branching', () => {
.findDcy('branch-selector')
.should('contain', 'feature');
});

it('edits branched content delivery when branching gets disabled', () => {
// Seed data is created with BRANCHING enabled so the config has a branch
// stored on the backend. Now simulate the feature being turned off.
setFeature('BRANCHING', false);
cy.reload();
waitForGlobalLoading();

openEditDialog('Main CDN');
// Branch selector must be hidden when branching is not enabled.
gcy('content-delivery-form-branch').should('not.exist');

cy.gcy('content-delivery-form-name').find('input').clear().type('Renamed');
cy.gcy('content-delivery-form-save').click();
waitForGlobalLoading();
// Before the fix the PUT body carried the stale filterBranch which the
// backend rejected with FEATURE_NOT_ENABLED_FOR_PROJECT.
assertMessage('Content delivery successfully updated!');
});
});

function openEditDialog(name: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,36 @@ class ContentDeliveryConfigBranchingTest : ProjectAuthControllerTest("/v2/projec
).andIsBadRequest.andHasErrorMessage(Message.FEATURE_NOT_ENABLED)
}

@Test
@ProjectJWTAuthTestMethod
fun `update default-branch CDN succeeds when branching not enabled and default is echoed`() {
enabledFeaturesProvider.forceEnabled = setOf(Feature.MULTIPLE_CONTENT_DELIVERY_CONFIGS)
performProjectAuthPut(
"content-delivery-configs/${testData.mainBranchCdnConfig.self.id}",
mapOf("name" to "Renamed", "filterBranch" to "main"),
).andIsOk
}

@Test
@ProjectJWTAuthTestMethod
fun `update default-branch CDN succeeds when branching not enabled and filterBranch is null`() {
enabledFeaturesProvider.forceEnabled = setOf(Feature.MULTIPLE_CONTENT_DELIVERY_CONFIGS)
performProjectAuthPut(
"content-delivery-configs/${testData.mainBranchCdnConfig.self.id}",
mapOf("name" to "Renamed"),
).andIsOk
}

@Test
@ProjectJWTAuthTestMethod
fun `update non-default-branch CDN fails when branching not enabled even if branch is unchanged`() {
enabledFeaturesProvider.forceEnabled = setOf(Feature.MULTIPLE_CONTENT_DELIVERY_CONFIGS)
performProjectAuthPut(
"content-delivery-configs/${testData.featureBranchCdnConfig.self.id}",
mapOf("name" to "Feature CDN", "filterBranch" to "feature"),
).andIsBadRequest.andHasErrorMessage(Message.FEATURE_NOT_ENABLED)
}

@Test
@ProjectJWTAuthTestMethod
fun `CDN config filterBranch is derived from branch entity`() {
Expand Down
Loading