From ee1d8ee8cd08b8c19f75e66d8d325102d71441fb Mon Sep 17 00:00:00 2001 From: Mateusz Kwasniewski Date: Wed, 21 Aug 2024 10:34:13 +0200 Subject: [PATCH] fix: misc fixes for project archive (#7948) --- .../ArchiveProject/ProjectArchived.tsx | 2 +- .../EditProject/ArchiveProjectForm.tsx | 2 +- .../ReviveProjectDialog.tsx | 3 ++ .../project/project-service.limit.test.ts | 35 ++++++++++++++++++- src/lib/features/project/project-service.ts | 2 ++ 5 files changed, 41 insertions(+), 3 deletions(-) diff --git a/frontend/src/component/project/Project/ArchiveProject/ProjectArchived.tsx b/frontend/src/component/project/Project/ArchiveProject/ProjectArchived.tsx index 4f3fd9d9d321..879859e9d3fd 100644 --- a/frontend/src/component/project/Project/ArchiveProject/ProjectArchived.tsx +++ b/frontend/src/component/project/Project/ArchiveProject/ProjectArchived.tsx @@ -6,7 +6,7 @@ export const ProjectArchived: FC<{ name: string }> = ({ name }) => {

The project {name} has been archived. You can find it on the{' '} - projects archive page. + archive page for projects.

); }; diff --git a/frontend/src/component/project/Project/ProjectSettings/Settings/EditProject/ArchiveProjectForm.tsx b/frontend/src/component/project/Project/ProjectSettings/Settings/EditProject/ArchiveProjectForm.tsx index 6cf9116547f9..4ea77b471c2e 100644 --- a/frontend/src/component/project/Project/ProjectSettings/Settings/EditProject/ArchiveProjectForm.tsx +++ b/frontend/src/component/project/Project/ProjectSettings/Settings/EditProject/ArchiveProjectForm.tsx @@ -18,7 +18,7 @@ export const ArchiveProjectForm = ({ featureCount }: IDeleteProjectForm) => { const { uiConfig } = useUiConfig(); const { loading } = useProjectApi(); const formatProjectArchiveApiCode = () => { - return `curl --location --request DELETE '${uiConfig.unleashUrl}/api/admin/projects/${id}/archive' \\ + return `curl --location --request POST '${uiConfig.unleashUrl}/api/admin/projects/archive/${id}' \\ --header 'Authorization: INSERT_API_KEY' '`; }; diff --git a/frontend/src/component/project/ProjectList/ReviveProjectDialog/ReviveProjectDialog.tsx b/frontend/src/component/project/ProjectList/ReviveProjectDialog/ReviveProjectDialog.tsx index ae59733a3721..1889d846a72e 100644 --- a/frontend/src/component/project/ProjectList/ReviveProjectDialog/ReviveProjectDialog.tsx +++ b/frontend/src/component/project/ProjectList/ReviveProjectDialog/ReviveProjectDialog.tsx @@ -5,6 +5,7 @@ import useProjectApi from 'hooks/api/actions/useProjectApi/useProjectApi'; import useProjects from 'hooks/api/getters/useProjects/useProjects'; import useToast from 'hooks/useToast'; import { formatUnknownError } from 'utils/formatUnknownError'; +import { useNavigate } from 'react-router-dom'; type ReviveProjectDialogProps = { name: string; @@ -27,6 +28,7 @@ export const ReviveProjectDialog = ({ const { refetch: refetchProjects } = useProjects(); const { refetch: refetchProjectArchive } = useProjects({ archived: true }); const { setToastData, setToastApiError } = useToast(); + const navigate = useNavigate(); const onClick = async (e: React.SyntheticEvent) => { e.preventDefault(); @@ -35,6 +37,7 @@ export const ReviveProjectDialog = ({ await reviveProject(id); refetchProjects(); refetchProjectArchive(); + navigate(`/projects/${id}`); setToastData({ title: 'Revive project', type: 'success', diff --git a/src/lib/features/project/project-service.limit.test.ts b/src/lib/features/project/project-service.limit.test.ts index 8bdc82f529e3..a28accf90107 100644 --- a/src/lib/features/project/project-service.limit.test.ts +++ b/src/lib/features/project/project-service.limit.test.ts @@ -9,7 +9,7 @@ const alwaysOnFlagResolver = { }, } as unknown as IFlagResolver; -test('Should not allow to exceed project limit', async () => { +test('Should not allow to exceed project limit on create', async () => { const LIMIT = 1; const projectService = createFakeProjectService({ ...createTestConfig(), @@ -31,3 +31,36 @@ test('Should not allow to exceed project limit', async () => { "Failed to create project. You can't create more than the established limit of 1.", ); }); + +test('Should not allow to exceed project limit on revive', async () => { + const LIMIT = 1; + const projectService = createFakeProjectService({ + ...createTestConfig(), + flagResolver: alwaysOnFlagResolver, + resourceLimits: { + projects: LIMIT, + }, + eventBus: { + emit: () => {}, + }, + } as unknown as IUnleashConfig); + + const createProject = (name: string) => + projectService.createProject( + { name, id: name }, + {} as IUser, + {} as IAuditUser, + ); + const archiveProject = (id: string) => + projectService.archiveProject(id, {} as IAuditUser); + const reviveProject = (id: string) => + projectService.reviveProject(id, {} as IAuditUser); + + await createProject('projectA'); + await archiveProject('projectA'); + await createProject('projectB'); + + await expect(() => reviveProject('projectA')).rejects.toThrow( + "Failed to create project. You can't create more than the established limit of 1.", + ); +}); diff --git a/src/lib/features/project/project-service.ts b/src/lib/features/project/project-service.ts index 081aba318dad..c5363418bcc6 100644 --- a/src/lib/features/project/project-service.ts +++ b/src/lib/features/project/project-service.ts @@ -634,6 +634,8 @@ export default class ProjectService { } async reviveProject(id: string, auditUser: IAuditUser): Promise { + await this.validateProjectLimit(); + await this.projectStore.revive(id); await this.eventService.storeEvent(