Skip to content

Commit

Permalink
feat(core): Ensure SuperAdmin role has all permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbromley committed Sep 25, 2019
1 parent b727327 commit ab866c1
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions packages/core/src/service/services/role.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,25 @@ export class RoleService {
});
}

/**
* Ensure that the SuperAdmin role exists and that it has all possible Permissions.
*/
private async ensureSuperAdminRoleExists() {
const allPermissions = Object.values(Permission).filter(p => p !== Permission.Owner);
try {
await this.getSuperAdminRole();
const superAdminRole = await this.getSuperAdminRole();
const hasAllPermissions = allPermissions.every(permission =>
superAdminRole.permissions.includes(permission),
);
if (!hasAllPermissions) {
superAdminRole.permissions = allPermissions;
await this.connection.getRepository(Role).save(superAdminRole);
}
} catch (err) {
await this.create({
code: SUPER_ADMIN_ROLE_CODE,
description: SUPER_ADMIN_ROLE_DESCRIPTION,
permissions: Object.values(Permission).filter(p => p !== Permission.Owner),
permissions: allPermissions,
});
}
}
Expand Down

0 comments on commit ab866c1

Please sign in to comment.