monkey-front-core 0.0.343 → 0.0.345

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.
@@ -4112,22 +4112,93 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImpor
4112
4112
  args: [{ providedIn: 'root' }]
4113
4113
  }], ctorParameters: function () { return [{ type: MonkeyEcxAuthenticationService }]; } });
4114
4114
 
4115
- class MonkeyEcxAuthGuardByRole {
4115
+ let MonkeyEcxAuthGuardByRole = class MonkeyEcxAuthGuardByRole {
4116
4116
  constructor() {
4117
4117
  // not to do
4118
4118
  }
4119
- async canActivate() {
4120
- return false;
4119
+ static forRoles(roles, companyType, byExclusion) {
4120
+ class RoleCheck {
4121
+ constructor(storageService, router) {
4122
+ this.storageService = storageService;
4123
+ this.router = router;
4124
+ this.tokenCredentials = null;
4125
+ // not to do
4126
+ }
4127
+ navigateToErrorPage() {
4128
+ let path = '/app/pages/forbidden';
4129
+ if (companyType) {
4130
+ path = `/app/${companyType}/pages/forbidden`;
4131
+ }
4132
+ this.router?.navigate([path.toLowerCase()]);
4133
+ }
4134
+ getRole() {
4135
+ const { tokenCredentials } = this;
4136
+ if (!tokenCredentials)
4137
+ return '';
4138
+ if (tokenCredentials?.programAdmin === 'true') {
4139
+ return 'PROGRAM_ADMIN';
4140
+ }
4141
+ if (tokenCredentials?.programAdmin === true) {
4142
+ return 'PROGRAM_ADMIN';
4143
+ }
4144
+ return tokenCredentials?.role || '';
4145
+ }
4146
+ allowedSecurityAccess(roles) {
4147
+ if (!roles?.length)
4148
+ return true;
4149
+ const found = roles?.indexOf(this.getRole());
4150
+ let ret = false;
4151
+ if (byExclusion) {
4152
+ ret = true;
4153
+ if (found > -1) {
4154
+ ret = false;
4155
+ }
4156
+ }
4157
+ else {
4158
+ ret = false;
4159
+ if (found > -1) {
4160
+ ret = true;
4161
+ }
4162
+ }
4163
+ if (!roles || roles.length === 0 || this.getRole() === 'PROGRAM_ADMIN') {
4164
+ ret = true;
4165
+ }
4166
+ return ret;
4167
+ }
4168
+ async canActivate() {
4169
+ console.log('roles');
4170
+ console.log(roles);
4171
+ if (!this.tokenCredentials) {
4172
+ this.tokenCredentials = await this.storageService.getToken();
4173
+ }
4174
+ console.log('this.tokenCredentials');
4175
+ console.log(this.tokenCredentials);
4176
+ console.log('checando');
4177
+ if (!this.allowedSecurityAccess(roles)) {
4178
+ console.log('checou erro');
4179
+ this.navigateToErrorPage();
4180
+ return false;
4181
+ }
4182
+ console.log('checou ok');
4183
+ return true;
4184
+ }
4185
+ }
4186
+ RoleCheck.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: RoleCheck, deps: [{ token: MonkeyEcxTokenStorageService }, { token: i2$2.Router }], target: i0.ɵɵFactoryTarget.Injectable });
4187
+ RoleCheck.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: RoleCheck, providedIn: 'root' });
4188
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: RoleCheck, decorators: [{
4189
+ type: Injectable,
4190
+ args: [{
4191
+ providedIn: 'root'
4192
+ }]
4193
+ }], ctorParameters: function () { return [{ type: MonkeyEcxTokenStorageService }, { type: i2$2.Router }]; } });
4194
+ return RoleCheck;
4121
4195
  }
4122
- }
4123
- MonkeyEcxAuthGuardByRole.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: MonkeyEcxAuthGuardByRole, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
4124
- MonkeyEcxAuthGuardByRole.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: MonkeyEcxAuthGuardByRole, providedIn: 'root' });
4125
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: MonkeyEcxAuthGuardByRole, decorators: [{
4126
- type: Injectable,
4127
- args: [{
4128
- providedIn: 'root'
4129
- }]
4130
- }], ctorParameters: function () { return []; } });
4196
+ };
4197
+ MonkeyEcxAuthGuardByRole = __decorate([
4198
+ Injectable({
4199
+ providedIn: 'root'
4200
+ })
4201
+ ], MonkeyEcxAuthGuardByRole);
4131
4202
 
4132
4203
  class MonkeyEcxAuthGuard {
4133
4204
  constructor(monkeyecxAuthenticationService) {