mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-25 00:07:47 +01:00
feat: prevent move feature to archived project (#7839)
This commit is contained in:
parent
67fa28f05a
commit
9b781b781a
@ -962,7 +962,7 @@ test('should not change project if feature flag project does not match current p
|
||||
}
|
||||
});
|
||||
|
||||
test('should return 404 if no project is found with the project id', async () => {
|
||||
test('should return 404 if no active project is found with the project id', async () => {
|
||||
const project = {
|
||||
id: 'test-change-project-2',
|
||||
name: 'New project',
|
||||
@ -985,7 +985,32 @@ test('should return 404 if no project is found with the project id', async () =>
|
||||
auditUser,
|
||||
);
|
||||
} catch (err) {
|
||||
expect(err.message).toBe(`No project found`);
|
||||
expect(err.message).toBe(
|
||||
`Active project with id newProject does not exist`,
|
||||
);
|
||||
}
|
||||
|
||||
const newProject = {
|
||||
id: 'newProject',
|
||||
name: 'New project',
|
||||
description: 'Blah',
|
||||
mode: 'open' as const,
|
||||
defaultStickiness: 'clientId',
|
||||
};
|
||||
await projectService.createProject(newProject, user, auditUser);
|
||||
await projectService.archiveProject(newProject.id, TEST_AUDIT_USER);
|
||||
try {
|
||||
await projectService.changeProject(
|
||||
'newProject',
|
||||
flag.name,
|
||||
user,
|
||||
project.id,
|
||||
auditUser,
|
||||
);
|
||||
} catch (err) {
|
||||
expect(err.message).toBe(
|
||||
`Active project with id newProject does not exist`,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -486,6 +486,18 @@ export default class ProjectService {
|
||||
await this.projectStore.addEnvironmentToProject(project, environment);
|
||||
}
|
||||
|
||||
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 changeProject(
|
||||
newProjectId: string,
|
||||
featureName: string,
|
||||
@ -498,11 +510,8 @@ export default class ProjectService {
|
||||
if (feature.project !== currentProjectId) {
|
||||
throw new PermissionError(MOVE_FEATURE_TOGGLE);
|
||||
}
|
||||
const project = await this.getProject(newProjectId);
|
||||
|
||||
if (!project) {
|
||||
throw new NotFoundError(`Project ${newProjectId} not found`);
|
||||
}
|
||||
await this.validateActiveProject(newProjectId);
|
||||
|
||||
const authorized = await this.accessService.hasPermission(
|
||||
user,
|
||||
|
Loading…
Reference in New Issue
Block a user