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

fix: no owners listed in personal dashboard for default project (#8373)

This PR fixes a bug where the default project would have no listed
owners. The issue was that the default project has no user owners by
default, so we didn't get a result back when looking for user owners.
Now we check whether we have any owners for that project, and if we
don't, then we return the system user as an owner instead.

This also fixes an issue for the default project where you have no roles
(because by default, you don't) by updating the schema to allow an empty
list.
This commit is contained in:
Thomas Heartman 2024-10-07 10:52:11 +02:00 committed by GitHub
parent 43a564753e
commit 2905b560bd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 15 additions and 3 deletions

View File

@ -23,7 +23,6 @@ export interface PersonalDashboardProjectDetailsSchema {
owners: PersonalDashboardProjectDetailsSchemaOwners; owners: PersonalDashboardProjectDetailsSchemaOwners;
/** /**
* The list of roles that the user has in this project. * The list of roles that the user has in this project.
* @minItems 1
*/ */
roles: PersonalDashboardProjectDetailsSchemaRolesItem[]; roles: PersonalDashboardProjectDetailsSchemaRolesItem[];
} }

View File

@ -389,3 +389,17 @@ test('should return Unleash admins', async () => {
}, },
]); ]);
}); });
test('should return System owner for default project if nothing else is set', async () => {
await loginUser('new_user@test.com');
const { body } = await app.request.get(
`/api/admin/personal-dashboard/default`,
);
expect(body.owners).toMatchObject([
{
ownerType: 'system',
},
]);
});

View File

@ -161,6 +161,6 @@ export class ProjectOwnersReadModel implements IProjectOwnersReadModel {
async getProjectOwners(projectId: string): Promise<ProjectOwners> { async getProjectOwners(projectId: string): Promise<ProjectOwners> {
const owners = await this.getProjectOwnersDictionary(); const owners = await this.getProjectOwnersDictionary();
return owners[projectId] ?? []; return owners[projectId] ?? [{ ownerType: 'system' }];
} }
} }

View File

@ -119,7 +119,6 @@ export const personalDashboardProjectDetailsSchema = {
roles: { roles: {
type: 'array', type: 'array',
description: 'The list of roles that the user has in this project.', description: 'The list of roles that the user has in this project.',
minItems: 1,
items: { items: {
type: 'object', type: 'object',
description: 'An Unleash role.', description: 'An Unleash role.',