[permissions] Backfill command to prepare workspaces (#10581)

Closes https://github.com/twentyhq/core-team-issues/issues/317

---------

Co-authored-by: Weiko <corentin@twenty.com>
This commit is contained in:
Marie
2025-02-28 15:46:51 +01:00
committed by GitHub
parent fba63d9cb7
commit 122a6a7801
3 changed files with 298 additions and 4 deletions

View File

@ -35,12 +35,16 @@ export class UserRoleService {
userWorkspaceId: string;
roleId: string;
}): Promise<void> {
await this.validateAssignRoleInput({
const validationResult = await this.validateAssignRoleInput({
userWorkspaceId,
workspaceId,
roleId,
});
if (validationResult?.roleToAssignIsSameAsCurrentRole) {
return;
}
const newUserWorkspaceRole = await this.userWorkspaceRoleRepository.save({
roleId,
userWorkspaceId,
@ -209,7 +213,9 @@ export class UserRoleService {
const currentRole = roles.get(userWorkspace.id)?.[0];
if (currentRole?.id === roleId) {
return;
return {
roleToAssignIsSameAsCurrentRole: true,
};
}
if (!(currentRole?.label === ADMIN_ROLE_LABEL)) {