Skip to content

Commit 61691c8

Browse files
committed
[NAE-1717] Banned roles not hiding menu entries
- corrected according to PR.
1 parent 6094cd0 commit 61691c8

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

projects/netgrif-components-core/src/lib/authorization/role/role-guard.service.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,13 @@ export class RoleGuardService implements CanActivate {
4343
const bannedRoles = this.parseRoleConstraints(view.access.bannedRole, url);
4444
const allowedRoles = this.parseRoleConstraints(view.access.role, url);
4545

46-
if (bannedRoles.length == 0 && allowedRoles.length == 0) {
46+
if (bannedRoles.some(role => this.decideAccessByRole(role))) {
4747
return false;
4848
}
4949

50-
if (bannedRoles.some(role => this.decideAccessByRole(role))) {
51-
return false;
50+
if (allowedRoles.length === 0) {
51+
this._log.warn(`View at '${url}' defines role access constraint with an empty array!`
52+
+ ` No users will be allowed to enter this view!`);
5253
}
5354
return allowedRoles.some(role => this.decideAccessByRole(role)); // user was not denied access by a banned role, they need at least one allowed role
5455
}
@@ -62,6 +63,10 @@ export class RoleGuardService implements CanActivate {
6263

6364
if (view.access.hasOwnProperty('role')) {
6465
const allowedRoles = this.parseRoleConstraints(view.access.role, url);
66+
if (allowedRoles.length === 0) {
67+
this._log.warn(`View at '${url}' defines role access constraint with an empty array!`
68+
+ ` No users will be allowed to enter this view!`);
69+
}
6570
return allowedRoles.some(constraint => {
6671
return this.decideAccessByRole(constraint);
6772
});
@@ -77,8 +82,6 @@ export class RoleGuardService implements CanActivate {
7782
}
7883
if (Array.isArray(roleConstrains)) {
7984
if (roleConstrains.length === 0) {
80-
this._log.warn(`View at '${viewUrl}' defines role access constraint with an empty array!`
81-
+ ` No users will be allowed to enter this view!`);
8285
return [];
8386
}
8487
if (typeof roleConstrains[0] === 'string') {

0 commit comments

Comments
 (0)