monkey-front-core 0.0.349 → 0.0.350
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 +12 -87
- package/fesm2015/monkey-front-core.mjs +11 -85
- package/fesm2015/monkey-front-core.mjs.map +1 -1
- package/fesm2020/monkey-front-core.mjs +11 -82
- package/fesm2020/monkey-front-core.mjs.map +1 -1
- package/lib/core/services/auth/monkeyecx-auth-guard-role.service.d.ts +7 -0
- package/monkey-front-core-0.0.350.tgz +0 -0
- package/package.json +1 -1
- package/monkey-front-core-0.0.349.tgz +0 -0
|
@@ -1,94 +1,19 @@
|
|
|
1
|
-
import { __decorate } from "tslib";
|
|
2
1
|
import { Injectable } from '@angular/core';
|
|
3
2
|
import * as i0 from "@angular/core";
|
|
4
|
-
|
|
5
|
-
import * as i2 from "@angular/router";
|
|
6
|
-
let MonkeyEcxAuthGuardByRole = class MonkeyEcxAuthGuardByRole {
|
|
3
|
+
export class MonkeyEcxAuthGuardByRole {
|
|
7
4
|
constructor() {
|
|
8
5
|
// not to do
|
|
9
6
|
}
|
|
10
7
|
static forRoles(roles, companyType, byExclusion) {
|
|
11
|
-
|
|
12
|
-
constructor(monkeyecxAuthenticationService, router) {
|
|
13
|
-
this.monkeyecxAuthenticationService = monkeyecxAuthenticationService;
|
|
14
|
-
this.router = router;
|
|
15
|
-
this.tokenCredentials = null;
|
|
16
|
-
// not to do
|
|
17
|
-
}
|
|
18
|
-
navigateToErrorPage() {
|
|
19
|
-
let path = '/app/pages/forbidden';
|
|
20
|
-
if (companyType) {
|
|
21
|
-
path = `/app/${companyType}/pages/forbidden`;
|
|
22
|
-
}
|
|
23
|
-
this.router?.navigate([path.toLowerCase()]);
|
|
24
|
-
}
|
|
25
|
-
getRole() {
|
|
26
|
-
const { tokenCredentials } = this;
|
|
27
|
-
if (!tokenCredentials)
|
|
28
|
-
return '';
|
|
29
|
-
if (tokenCredentials?.programAdmin === 'true') {
|
|
30
|
-
return 'PROGRAM_ADMIN';
|
|
31
|
-
}
|
|
32
|
-
if (tokenCredentials?.programAdmin === true) {
|
|
33
|
-
return 'PROGRAM_ADMIN';
|
|
34
|
-
}
|
|
35
|
-
return tokenCredentials?.role || '';
|
|
36
|
-
}
|
|
37
|
-
allowedSecurityAccess(roles) {
|
|
38
|
-
if (!roles?.length)
|
|
39
|
-
return true;
|
|
40
|
-
const found = roles?.indexOf(this.getRole());
|
|
41
|
-
let ret = false;
|
|
42
|
-
if (byExclusion) {
|
|
43
|
-
ret = true;
|
|
44
|
-
if (found > -1) {
|
|
45
|
-
ret = false;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
ret = false;
|
|
50
|
-
if (found > -1) {
|
|
51
|
-
ret = true;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
if (!roles || roles.length === 0 || this.getRole() === 'PROGRAM_ADMIN') {
|
|
55
|
-
ret = true;
|
|
56
|
-
}
|
|
57
|
-
return ret;
|
|
58
|
-
}
|
|
59
|
-
async canActivate() {
|
|
60
|
-
console.log('roles');
|
|
61
|
-
console.log(roles);
|
|
62
|
-
if (!this.tokenCredentials) {
|
|
63
|
-
this.tokenCredentials = await this.monkeyecxAuthenticationService.getToken();
|
|
64
|
-
}
|
|
65
|
-
console.log('this.tokenCredentials');
|
|
66
|
-
console.log(this.tokenCredentials);
|
|
67
|
-
console.log('checando');
|
|
68
|
-
if (!this.allowedSecurityAccess(roles)) {
|
|
69
|
-
console.log('checou erro');
|
|
70
|
-
this.navigateToErrorPage();
|
|
71
|
-
return false;
|
|
72
|
-
}
|
|
73
|
-
console.log('checou ok');
|
|
74
|
-
return true;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
RoleCheck.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: RoleCheck, deps: [{ token: i1.MonkeyEcxAuthenticationService }, { token: i2.Router }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
78
|
-
RoleCheck.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: RoleCheck, providedIn: 'root' });
|
|
79
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: RoleCheck, decorators: [{
|
|
80
|
-
type: Injectable,
|
|
81
|
-
args: [{
|
|
82
|
-
providedIn: 'root'
|
|
83
|
-
}]
|
|
84
|
-
}], ctorParameters: function () { return [{ type: i1.MonkeyEcxAuthenticationService }, { type: i2.Router }]; } });
|
|
85
|
-
return RoleCheck;
|
|
8
|
+
return 'oi';
|
|
86
9
|
}
|
|
87
|
-
}
|
|
88
|
-
MonkeyEcxAuthGuardByRole =
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
10
|
+
}
|
|
11
|
+
MonkeyEcxAuthGuardByRole.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: MonkeyEcxAuthGuardByRole, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
12
|
+
MonkeyEcxAuthGuardByRole.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: MonkeyEcxAuthGuardByRole, providedIn: 'root' });
|
|
13
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: MonkeyEcxAuthGuardByRole, decorators: [{
|
|
14
|
+
type: Injectable,
|
|
15
|
+
args: [{
|
|
16
|
+
providedIn: 'root'
|
|
17
|
+
}]
|
|
18
|
+
}], ctorParameters: function () { return []; } });
|
|
19
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibW9ua2V5ZWN4LWF1dGgtZ3VhcmQtcm9sZS5zZXJ2aWNlLmpz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1vbmtleWVjeEF1dGhlbnRpY2F0aW9uU2VydmljZS5nZXRUb2tlbigpO1xuICAgICAgICB9XG4gICAgICAgIGNvbnNvbGUubG9nKCd0aGlzLnRva2VuQ3JlZGVudGlhbHMnKTtcbiAgICAgICAgY29uc29sZS5sb2codGhpcy50b2tlbkNyZWRlbnRpYWxzKTtcbiAgICAgICAgY29uc29sZS5sb2coJ2NoZWNhbmRvJyk7XG4gICAgICAgIGlmICghdGhpcy5hbGxvd2VkU2VjdXJpdHlBY2Nlc3Mocm9sZXMpKSB7XG4gICAgICAgICAgY29uc29sZS5sb2coJ2NoZWNvdSBlcnJvJyk7XG4gICAgICAgICAgdGhpcy5uYXZpZ2F0ZVRvRXJyb3JQYWdlKCk7XG4gICAgICAgICAgcmV0dXJuIGZhbHNlO1xuICAgICAgICB9XG4gICAgICAgIGNvbnNvbGUubG9nKCdjaGVjb3Ugb2snKTtcblxuICAgICAgICByZXR1cm4gdHJ1ZTtcbiAgICAgIH1cbiAgICB9XG5cbiAgICByZXR1cm4gUm9sZUNoZWNrO1xuKi9cbiJdfQ==
|
|
@@ -4116,96 +4116,22 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImpor
|
|
|
4116
4116
|
args: [{ providedIn: 'root' }]
|
|
4117
4117
|
}], ctorParameters: function () { return [{ type: MonkeyEcxAuthenticationService }]; } });
|
|
4118
4118
|
|
|
4119
|
-
|
|
4119
|
+
class MonkeyEcxAuthGuardByRole {
|
|
4120
4120
|
constructor() {
|
|
4121
4121
|
// not to do
|
|
4122
4122
|
}
|
|
4123
4123
|
static forRoles(roles, companyType, byExclusion) {
|
|
4124
|
-
|
|
4125
|
-
constructor(monkeyecxAuthenticationService, router) {
|
|
4126
|
-
this.monkeyecxAuthenticationService = monkeyecxAuthenticationService;
|
|
4127
|
-
this.router = router;
|
|
4128
|
-
this.tokenCredentials = null;
|
|
4129
|
-
// not to do
|
|
4130
|
-
}
|
|
4131
|
-
navigateToErrorPage() {
|
|
4132
|
-
var _a;
|
|
4133
|
-
let path = '/app/pages/forbidden';
|
|
4134
|
-
if (companyType) {
|
|
4135
|
-
path = `/app/${companyType}/pages/forbidden`;
|
|
4136
|
-
}
|
|
4137
|
-
(_a = this.router) === null || _a === void 0 ? void 0 : _a.navigate([path.toLowerCase()]);
|
|
4138
|
-
}
|
|
4139
|
-
getRole() {
|
|
4140
|
-
const { tokenCredentials } = this;
|
|
4141
|
-
if (!tokenCredentials)
|
|
4142
|
-
return '';
|
|
4143
|
-
if ((tokenCredentials === null || tokenCredentials === void 0 ? void 0 : tokenCredentials.programAdmin) === 'true') {
|
|
4144
|
-
return 'PROGRAM_ADMIN';
|
|
4145
|
-
}
|
|
4146
|
-
if ((tokenCredentials === null || tokenCredentials === void 0 ? void 0 : tokenCredentials.programAdmin) === true) {
|
|
4147
|
-
return 'PROGRAM_ADMIN';
|
|
4148
|
-
}
|
|
4149
|
-
return (tokenCredentials === null || tokenCredentials === void 0 ? void 0 : tokenCredentials.role) || '';
|
|
4150
|
-
}
|
|
4151
|
-
allowedSecurityAccess(roles) {
|
|
4152
|
-
if (!(roles === null || roles === void 0 ? void 0 : roles.length))
|
|
4153
|
-
return true;
|
|
4154
|
-
const found = roles === null || roles === void 0 ? void 0 : 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
|
-
canActivate() {
|
|
4174
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
4175
|
-
console.log('roles');
|
|
4176
|
-
console.log(roles);
|
|
4177
|
-
if (!this.tokenCredentials) {
|
|
4178
|
-
this.tokenCredentials = yield this.monkeyecxAuthenticationService.getToken();
|
|
4179
|
-
}
|
|
4180
|
-
console.log('this.tokenCredentials');
|
|
4181
|
-
console.log(this.tokenCredentials);
|
|
4182
|
-
console.log('checando');
|
|
4183
|
-
if (!this.allowedSecurityAccess(roles)) {
|
|
4184
|
-
console.log('checou erro');
|
|
4185
|
-
this.navigateToErrorPage();
|
|
4186
|
-
return false;
|
|
4187
|
-
}
|
|
4188
|
-
console.log('checou ok');
|
|
4189
|
-
return true;
|
|
4190
|
-
});
|
|
4191
|
-
}
|
|
4192
|
-
}
|
|
4193
|
-
RoleCheck.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: RoleCheck, deps: [{ token: MonkeyEcxAuthenticationService }, { token: i2$2.Router }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
4194
|
-
RoleCheck.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: RoleCheck, providedIn: 'root' });
|
|
4195
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: RoleCheck, decorators: [{
|
|
4196
|
-
type: Injectable,
|
|
4197
|
-
args: [{
|
|
4198
|
-
providedIn: 'root'
|
|
4199
|
-
}]
|
|
4200
|
-
}], ctorParameters: function () { return [{ type: MonkeyEcxAuthenticationService }, { type: i2$2.Router }]; } });
|
|
4201
|
-
return RoleCheck;
|
|
4124
|
+
return 'oi';
|
|
4202
4125
|
}
|
|
4203
|
-
}
|
|
4204
|
-
MonkeyEcxAuthGuardByRole =
|
|
4205
|
-
|
|
4206
|
-
|
|
4207
|
-
|
|
4208
|
-
|
|
4126
|
+
}
|
|
4127
|
+
MonkeyEcxAuthGuardByRole.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: MonkeyEcxAuthGuardByRole, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
4128
|
+
MonkeyEcxAuthGuardByRole.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: MonkeyEcxAuthGuardByRole, providedIn: 'root' });
|
|
4129
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: MonkeyEcxAuthGuardByRole, decorators: [{
|
|
4130
|
+
type: Injectable,
|
|
4131
|
+
args: [{
|
|
4132
|
+
providedIn: 'root'
|
|
4133
|
+
}]
|
|
4134
|
+
}], ctorParameters: function () { return []; } });
|
|
4209
4135
|
|
|
4210
4136
|
class MonkeyEcxAuthGuard {
|
|
4211
4137
|
constructor(monkeyecxAuthenticationService) {
|