Skip to content

Commit

Permalink
Merge pull request #728 from rocket-admin/backend_development
Browse files Browse the repository at this point in the history
refactor: Prevent removing the last user from a company
  • Loading branch information
Artuomka authored Jul 9, 2024
2 parents bfa740c + 6972085 commit e38ebee
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ export class RemoveUserFromCompanyUseCase
HttpStatus.NOT_FOUND,
);
}
if (foundCompanyWithUsers.users.length === 1) {
throw new HttpException(
{
message: Messages.CANT_REMOVE_LAST_USER_FROM_COMPANY,
},
HttpStatus.BAD_REQUEST,
);
}
const foundUser = foundCompanyWithUsers.users.find((user) => user.id === userId);
if (!foundUser) {
throw new HttpException(
Expand Down
1 change: 1 addition & 0 deletions backend/src/exceptions/text/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const Messages = {
CANT_CREATE_PERMISSION_TYPE_GROUP: 'You can not create more than one permission of type "Group" for the same group',
CANT_DELETE_ADMIN_GROUP: 'You can not delete Admin group from connection',
CANT_DELETE_LAST_USER: 'You can not delete the last user from the Admin group',
CANT_REMOVE_LAST_USER_FROM_COMPANY: 'You can not remove the last user from the company.',
CANT_DELETE_PERMISSION_ADMIN_GROUP: `You can not delete editing permission for Connection from Admin group`,
CANT_CONNECT_AUTOADMIN_WS: `Connection to autoadmin websocket server failed.`,
CANT_INSERT_DUPLICATE_KEY: 'You can not insert duplicate Key values into database',
Expand Down

0 comments on commit e38ebee

Please sign in to comment.