mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01:00 
			
		
		
		
	fix: projects needs at least one owner
This commit is contained in:
		
							parent
							
								
									0ffd01f54b
								
							
						
					
					
						commit
						f9ef945404
					
				@ -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');
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -23,5 +23,6 @@ unleash.start(
 | 
			
		||||
        versionCheck: {
 | 
			
		||||
            enable: false,
 | 
			
		||||
        },
 | 
			
		||||
        secureHeaders: true,
 | 
			
		||||
    }),
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
@ -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',
 | 
			
		||||
        },
 | 
			
		||||
    );
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user