1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-02-09 00:18:00 +01:00

fix: misc fixes for project archive (#7948)

This commit is contained in:
Mateusz Kwasniewski 2024-08-21 10:34:13 +02:00 committed by GitHub
parent 89f3f09b6e
commit ee1d8ee8cd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 41 additions and 3 deletions

View File

@ -6,7 +6,7 @@ export const ProjectArchived: FC<{ name: string }> = ({ name }) => {
<p>
The project <strong>{name}</strong> has been archived. You can find
it on the{' '}
<Link to={`/projects-archive`}>projects archive page</Link>.
<Link to={`/projects-archive`}>archive page for projects</Link>.
</p>
);
};

View File

@ -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' '`;
};

View File

@ -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',

View File

@ -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.",
);
});

View File

@ -634,6 +634,8 @@ export default class ProjectService {
}
async reviveProject(id: string, auditUser: IAuditUser): Promise<void> {
await this.validateProjectLimit();
await this.projectStore.revive(id);
await this.eventService.storeEvent(