mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-09 00:18:00 +01:00
feat: prevent revive flag/flags in archived project (#7826)
This commit is contained in:
parent
624c6ce9c3
commit
67fa28f05a
@ -1235,6 +1235,18 @@ class FeatureToggleService {
|
||||
}
|
||||
}
|
||||
|
||||
private async validateActiveProject(projectId: string) {
|
||||
if (this.flagResolver.isEnabled('archiveProjects')) {
|
||||
const hasActiveProject =
|
||||
await this.projectStore.hasActiveProject(projectId);
|
||||
if (!hasActiveProject) {
|
||||
throw new NotFoundError(
|
||||
`Active project with id ${projectId} does not exist`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async createFeatureToggle(
|
||||
projectId: string,
|
||||
value: FeatureToggleDTO,
|
||||
@ -2058,6 +2070,7 @@ class FeatureToggleService {
|
||||
projectId: string,
|
||||
auditUser: IAuditUser,
|
||||
): Promise<void> {
|
||||
await this.validateActiveProject(projectId);
|
||||
await this.validateFeaturesContext(featureNames, projectId);
|
||||
|
||||
const features =
|
||||
@ -2091,6 +2104,11 @@ class FeatureToggleService {
|
||||
featureName: string,
|
||||
auditUser: IAuditUser,
|
||||
): Promise<void> {
|
||||
const feature = await this.featureToggleStore.get(featureName);
|
||||
if (!feature) {
|
||||
throw new NotFoundError(`Feature ${featureName} does not exist`);
|
||||
}
|
||||
await this.validateActiveProject(feature.project);
|
||||
const toggle = await this.featureToggleStore.revive(featureName);
|
||||
await this.featureToggleStore.disableAllEnvironmentsForFeatures([
|
||||
featureName,
|
||||
|
@ -773,3 +773,40 @@ test('Should not allow to add flags to archived projects', async () => {
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('Should not allow to revive flags to archived projects', async () => {
|
||||
const project = await stores.projectStore.create({
|
||||
id: 'archivedProjectWithFlag',
|
||||
name: 'archivedProjectWithFlag',
|
||||
});
|
||||
const flag = await service.createFeatureToggle(
|
||||
project.id,
|
||||
{
|
||||
name: 'archiveFlag',
|
||||
},
|
||||
TEST_AUDIT_USER,
|
||||
);
|
||||
|
||||
await service.archiveToggle(
|
||||
flag.name,
|
||||
{ email: 'test@example.com' } as User,
|
||||
TEST_AUDIT_USER,
|
||||
);
|
||||
await stores.projectStore.archive(project.id);
|
||||
|
||||
await expect(
|
||||
service.reviveFeature(flag.name, TEST_AUDIT_USER),
|
||||
).rejects.toEqual(
|
||||
new NotFoundError(
|
||||
`Active project with id archivedProjectWithFlag does not exist`,
|
||||
),
|
||||
);
|
||||
|
||||
await expect(
|
||||
service.reviveFeatures([flag.name], project.id, TEST_AUDIT_USER),
|
||||
).rejects.toEqual(
|
||||
new NotFoundError(
|
||||
`Active project with id archivedProjectWithFlag does not exist`,
|
||||
),
|
||||
);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user