-
-
Notifications
You must be signed in to change notification settings - Fork 728
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add your projects (with roles) to personal dashboard api (#8236)
This PR adds some of the necessary project data to the personal dashboard API: project names and ids, and the roles that the user has in each of these projects. I have not added project owners yet, as that would increase the complexity a bit and I'd rather focus on that in a separate PR. I have also not added projects you are part of through a group, though I have added a placeholder test for that. I will address this in a follow-up.
- Loading branch information
1 parent
f92f2d9
commit 4fe80ff
Showing
7 changed files
with
193 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import { | |
setupAppWithAuth, | ||
} from '../../../test/e2e/helpers/test-helper'; | ||
import getLogger from '../../../test/fixtures/no-logger'; | ||
import type { IUser } from '../../types'; | ||
|
||
let app: IUnleashTest; | ||
let db: ITestDb; | ||
|
@@ -53,11 +54,87 @@ test('should return personal dashboard with own flags and favorited flags', asyn | |
const { body } = await app.request.get(`/api/admin/personal-dashboard`); | ||
|
||
expect(body).toMatchObject({ | ||
projects: [], | ||
flags: [ | ||
{ name: 'my_feature_d', type: 'release', project: 'default' }, | ||
{ name: 'my_feature_c', type: 'release', project: 'default' }, | ||
{ name: 'other_feature_b', type: 'release', project: 'default' }, | ||
], | ||
}); | ||
}); | ||
|
||
const createProject = async (name: string, user: IUser) => { | ||
const auditUser = { | ||
id: 1, | ||
username: 'audit user', | ||
ip: '127.0.0.1', | ||
}; | ||
const project = await app.services.projectService.createProject( | ||
{ | ||
name, | ||
}, | ||
user, | ||
auditUser, | ||
); | ||
return project; | ||
}; | ||
|
||
test('should return personal dashboard with membered projects', async () => { | ||
const { body: user1 } = await loginUser('[email protected]'); | ||
const projectA = await createProject('Project A', user1); | ||
await createProject('Project B', user1); | ||
|
||
const { body: user2 } = await loginUser('[email protected]'); | ||
const projectC = await createProject('Project C', user2); | ||
|
||
await app.services.projectService.addAccess( | ||
projectA.id, | ||
[5], // member role | ||
[], | ||
[user2.id], | ||
user1, | ||
); | ||
|
||
const { body } = await app.request.get(`/api/admin/personal-dashboard`); | ||
|
||
expect(body).toMatchObject({ | ||
projects: [ | ||
{ | ||
name: 'Default', | ||
id: 'default', | ||
roles: [ | ||
{ | ||
name: 'Editor', | ||
id: 2, | ||
type: 'root', | ||
}, | ||
], | ||
}, | ||
{ | ||
name: projectA.name, | ||
id: projectA.id, | ||
roles: [ | ||
{ | ||
name: 'Member', | ||
id: 5, | ||
type: 'project', | ||
}, | ||
], | ||
}, | ||
{ | ||
name: projectC.name, | ||
id: projectC.id, | ||
roles: [ | ||
{ | ||
name: 'Owner', | ||
id: 4, | ||
type: 'project', | ||
}, | ||
], | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
test('should return projects where users are part of a group', () => { | ||
// TODO | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/lib/features/personal-dashboard/personal-dashboard-read-model-type.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,15 @@ | ||
export type PersonalFeature = { name: string; type: string; project: string }; | ||
export type PersonalProject = { | ||
name: string; | ||
id: string; | ||
roles: { | ||
name: string; | ||
id: number; | ||
type: 'custom' | 'project' | 'root' | 'custom-root'; | ||
}[]; | ||
}; | ||
|
||
export interface IPersonalDashboardReadModel { | ||
getPersonalFeatures(userId: number): Promise<PersonalFeature[]>; | ||
getPersonalProjects(userId: number): Promise<PersonalProject[]>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters