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

feat: filter out archived projects from the main project list (#7803)

This commit is contained in:
Mateusz Kwasniewski 2024-08-08 13:22:44 +02:00 committed by GitHub
parent 3fe385e127
commit fffed5d8dc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 35 additions and 14 deletions

View File

@ -79,7 +79,10 @@ beforeAll(async () => {
email: 'test@example.com', email: 'test@example.com',
}); });
await stores.accessStore.addUserToRole(opsUser.id, 1, ''); await stores.accessStore.addUserToRole(opsUser.id, 1, '');
const config = createTestConfig({ getLogger }); const config = createTestConfig({
getLogger,
experimental: { flags: { archiveProjects: true } },
});
eventService = new EventService(stores, config); eventService = new EventService(stores, config);
accessService = createAccessService(db.rawDatabase, config); accessService = createAccessService(db.rawDatabase, config);
@ -299,6 +302,10 @@ test('should archive project', async () => {
type: 'project-archived', type: 'project-archived',
createdBy: TEST_AUDIT_USER.username, createdBy: TEST_AUDIT_USER.username,
}); });
const projects = await projectService.getProjects();
expect(projects.find((p) => p.id === project.id)).toBeUndefined();
expect(projects.length).not.toBe(0);
}); });
test('should not be able to archive project with flags', async () => { test('should not be able to archive project with flags', async () => {

View File

@ -140,6 +140,9 @@ class ProjectStore implements IProjectStore {
) )
.leftJoin('project_stats', 'project_stats.project', 'projects.id') .leftJoin('project_stats', 'project_stats.project', 'projects.id')
.orderBy('projects.name', 'asc'); .orderBy('projects.name', 'asc');
if (this.flagResolver.isEnabled('archiveProjects')) {
projects = projects.where('projects.archived_at', null);
}
if (query) { if (query) {
projects = projects.where(query); projects = projects.where(query);

View File

@ -19,8 +19,10 @@ import type {
ProjectEnvironment, ProjectEnvironment,
} from '../../lib/features/project/project-store-type'; } from '../../lib/features/project/project-store-type';
type ArchivableProject = IProject & { archivedAt: null | Date };
export default class FakeProjectStore implements IProjectStore { export default class FakeProjectStore implements IProjectStore {
projects: IProject[] = []; projects: ArchivableProject[] = [];
projectEnvironment: Map<string, Set<string>> = new Map(); projectEnvironment: Map<string, Set<string>> = new Map();
@ -47,7 +49,9 @@ export default class FakeProjectStore implements IProjectStore {
} }
async getProjectsWithCounts(): Promise<IProjectWithCount[]> { async getProjectsWithCounts(): Promise<IProjectWithCount[]> {
return this.projects.map((project) => { return this.projects
.filter((project) => project.archivedAt !== null)
.map((project) => {
return { return {
...project, ...project,
memberCount: 0, memberCount: 0,
@ -60,12 +64,13 @@ export default class FakeProjectStore implements IProjectStore {
} }
private createInternal(project: IProjectInsert): IProject { private createInternal(project: IProjectInsert): IProject {
const newProj: IProject = { const newProj: ArchivableProject = {
...project, ...project,
health: 100, health: 100,
createdAt: new Date(), createdAt: new Date(),
mode: 'open', mode: 'open',
defaultStickiness: 'default', defaultStickiness: 'default',
archivedAt: null,
}; };
this.projects.push(newProj); this.projects.push(newProj);
return newProj; return newProj;
@ -215,5 +220,11 @@ export default class FakeProjectStore implements IProjectStore {
throw new Error('Method not implemented.'); throw new Error('Method not implemented.');
} }
async archive(id: string): Promise<void> {} async archive(id: string): Promise<void> {
this.projects = this.projects.map((project) =>
project.id === id
? { ...project, archivedAt: new Date() }
: project,
);
}
} }