Skip to content

Commit

Permalink
fix: user projects should exclude archived ones (#8118)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwasniew authored Sep 6, 2024
1 parent 028cf06 commit 47753b9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
21 changes: 21 additions & 0 deletions src/lib/features/project/project-service.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
14 changes: 11 additions & 3 deletions src/lib/features/project/project-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,20 +539,28 @@ class ProjectStore implements IProjectStore {
async getProjectsByUser(userId: number): Promise<string[]> {
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');
})
Expand Down

0 comments on commit 47753b9

Please sign in to comment.