mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-23 00:22:19 +01:00
fix: user projects should exclude archived ones (#8118)
This commit is contained in:
parent
028cf06f6c
commit
47753b90b2
@ -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',
|
||||
|
@ -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');
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user