monkey-front-core 0.0.350 → 0.0.351
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm2020/lib/core/services/auth/monkeyecx-auth-guard-role.service.mjs +68 -2
- package/fesm2015/monkey-front-core.mjs +70 -1
- package/fesm2015/monkey-front-core.mjs.map +1 -1
- package/fesm2020/monkey-front-core.mjs +67 -1
- package/fesm2020/monkey-front-core.mjs.map +1 -1
- package/monkey-front-core-0.0.351.tgz +0 -0
- package/package.json +1 -1
- package/lib/core/services/auth/monkeyecx-auth-guard-role.service.d.ts +0 -7
- package/monkey-front-core-0.0.350.tgz +0 -0
|
@@ -4122,7 +4122,73 @@ class MonkeyEcxAuthGuardByRole {
|
|
|
4122
4122
|
// not to do
|
|
4123
4123
|
}
|
|
4124
4124
|
static forRoles(roles, companyType, byExclusion) {
|
|
4125
|
-
|
|
4125
|
+
class RoleCheck {
|
|
4126
|
+
constructor(monkeyecxAuthenticationService, router) {
|
|
4127
|
+
this.monkeyecxAuthenticationService = monkeyecxAuthenticationService;
|
|
4128
|
+
this.router = router;
|
|
4129
|
+
this.tokenCredentials = null;
|
|
4130
|
+
// not to do
|
|
4131
|
+
}
|
|
4132
|
+
navigateToErrorPage() {
|
|
4133
|
+
let path = '/app/pages/forbidden';
|
|
4134
|
+
if (companyType) {
|
|
4135
|
+
path = `/app/${companyType}/pages/forbidden`;
|
|
4136
|
+
}
|
|
4137
|
+
this.router?.navigate([path.toLowerCase()]);
|
|
4138
|
+
}
|
|
4139
|
+
getRole() {
|
|
4140
|
+
const { tokenCredentials } = this;
|
|
4141
|
+
if (!tokenCredentials)
|
|
4142
|
+
return '';
|
|
4143
|
+
if (tokenCredentials?.programAdmin === 'true') {
|
|
4144
|
+
return 'PROGRAM_ADMIN';
|
|
4145
|
+
}
|
|
4146
|
+
if (tokenCredentials?.programAdmin === true) {
|
|
4147
|
+
return 'PROGRAM_ADMIN';
|
|
4148
|
+
}
|
|
4149
|
+
return tokenCredentials?.role || '';
|
|
4150
|
+
}
|
|
4151
|
+
allowedSecurityAccess(roles) {
|
|
4152
|
+
if (!roles?.length)
|
|
4153
|
+
return true;
|
|
4154
|
+
const found = roles?.indexOf(this.getRole());
|
|
4155
|
+
let ret = false;
|
|
4156
|
+
if (byExclusion) {
|
|
4157
|
+
ret = true;
|
|
4158
|
+
if (found > -1) {
|
|
4159
|
+
ret = false;
|
|
4160
|
+
}
|
|
4161
|
+
}
|
|
4162
|
+
else {
|
|
4163
|
+
ret = false;
|
|
4164
|
+
if (found > -1) {
|
|
4165
|
+
ret = true;
|
|
4166
|
+
}
|
|
4167
|
+
}
|
|
4168
|
+
if (!roles || roles.length === 0 || this.getRole() === 'PROGRAM_ADMIN') {
|
|
4169
|
+
ret = true;
|
|
4170
|
+
}
|
|
4171
|
+
return ret;
|
|
4172
|
+
}
|
|
4173
|
+
async canActivate() {
|
|
4174
|
+
console.log('roles');
|
|
4175
|
+
console.log(roles);
|
|
4176
|
+
if (!this.tokenCredentials) {
|
|
4177
|
+
this.tokenCredentials = await this.monkeyecxAuthenticationService.getToken();
|
|
4178
|
+
}
|
|
4179
|
+
console.log('this.tokenCredentials');
|
|
4180
|
+
console.log(this.tokenCredentials);
|
|
4181
|
+
console.log('checando');
|
|
4182
|
+
if (!this.allowedSecurityAccess(roles)) {
|
|
4183
|
+
console.log('checou erro');
|
|
4184
|
+
this.navigateToErrorPage();
|
|
4185
|
+
return false;
|
|
4186
|
+
}
|
|
4187
|
+
console.log('checou ok');
|
|
4188
|
+
return true;
|
|
4189
|
+
}
|
|
4190
|
+
}
|
|
4191
|
+
return RoleCheck;
|
|
4126
4192
|
}
|
|
4127
4193
|
}
|
|
4128
4194
|
MonkeyEcxAuthGuardByRole.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: MonkeyEcxAuthGuardByRole, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|