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

fix: projects needs at least one owner

This commit is contained in:
Ivar Conradi Østhus 2021-05-25 19:28:29 +02:00
parent 0ffd01f54b
commit f9ef945404
No known key found for this signature in database
GPG Key ID: 31AC596886B0BD09
3 changed files with 25 additions and 2 deletions

View File

@ -190,10 +190,10 @@ export default class ProjectService {
);
}
if (role.name === RoleName.ADMIN) {
if (role.name === RoleName.OWNER) {
const users = await this.accessService.getUsersForRole(role.id);
if (users.length < 2) {
throw new Error('A project must have at least one admin');
throw new Error('A project must have at least one owner');
}
}

View File

@ -23,5 +23,6 @@ unleash.start(
versionCheck: {
enable: false,
},
secureHeaders: true,
}),
);

View File

@ -377,3 +377,25 @@ test.serial('should remove user from the project', async t => {
t.is(memberUsers.length, 0);
});
test.serial('should not remove user from the project', async t => {
const project = {
id: 'remove-users-not-allowed',
name: 'New project',
description: 'Blah',
};
await projectService.createProject(project, user);
const roles = await stores.accessStore.getRolesForProject(project.id);
const ownerRole = roles.find(r => r.name === RoleName.OWNER);
await t.throwsAsync(
async () => {
await projectService.removeUser(project.id, ownerRole.id, user.id);
},
{
instanceOf: Error,
message: 'A project must have at least one owner',
},
);
});