diff --git a/src/lib/features/project/project-service.e2e.test.ts b/src/lib/features/project/project-service.e2e.test.ts index cbc23e2ff605..06733b189625 100644 --- a/src/lib/features/project/project-service.e2e.test.ts +++ b/src/lib/features/project/project-service.e2e.test.ts @@ -321,6 +321,27 @@ test('should archive project', async () => { expect(archivedProject).toMatchObject({ archivedAt: expect.any(Date) }); }); +test('archive project removes it from user projects', async () => { + const project = { + id: 'test-user-archive', + name: 'New project', + description: 'Blah', + mode: 'open' as const, + defaultStickiness: 'default', + }; + await projectService.createProject(project, user, TEST_AUDIT_USER); + + const userProjectsBeforeArchive = await projectService.getProjectsByUser( + user.id, + ); + expect(userProjectsBeforeArchive).toEqual(['test-user-archive']); + + await projectService.archiveProject(project.id, TEST_AUDIT_USER); + + const userProjects = await projectService.getProjectsByUser(user.id); + expect(userProjects).toEqual([]); +}); + test('should revive project', async () => { const project = { id: 'test-revive', diff --git a/src/lib/features/project/project-store.ts b/src/lib/features/project/project-store.ts index 4dfb65e778ea..1a1bf0e174ee 100644 --- a/src/lib/features/project/project-store.ts +++ b/src/lib/features/project/project-store.ts @@ -539,20 +539,28 @@ class ProjectStore implements IProjectStore { async getProjectsByUser(userId: number): Promise { const projects = await this.db .from((db) => { - db.select('project') + db.select('role_user.project') .from('role_user') .leftJoin('roles', 'role_user.role_id', 'roles.id') + .leftJoin('projects', 'role_user.project', 'projects.id') .where('user_id', userId) + .andWhere('projects.archived_at', null) .union((queryBuilder) => { queryBuilder - .select('project') + .select('group_role.project') .from('group_role') .leftJoin( 'group_user', 'group_user.group_id', 'group_role.group_id', ) - .where('user_id', userId); + .leftJoin( + 'projects', + 'group_role.project', + 'projects.id', + ) + .where('group_user.user_id', userId) + .andWhere('projects.archived_at', null); }) .as('query'); })