monkey-front-core 0.0.347 → 0.0.349

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.
@@ -4037,6 +4037,10 @@ class MonkeyEcxAuthenticationService {
4037
4037
  console.error('refreshToken needs to be declared!');
4038
4038
  return null;
4039
4039
  };
4040
+ this.getToken = async () => {
4041
+ console.error('getToken needs to be declared!');
4042
+ return null;
4043
+ };
4040
4044
  // not to do
4041
4045
  }
4042
4046
  init(args) {
@@ -4054,6 +4058,7 @@ class MonkeyEcxAuthenticationService {
4054
4058
  this.getRequestWithHeadersOb = args?.getRequestWithHeadersOb.bind(this);
4055
4059
  this.refreshShouldHappen = args?.refreshShouldHappen || this.refreshShouldHappen.bind(this);
4056
4060
  this.refreshToken = args?.refreshToken || this.refreshToken.bind(this);
4061
+ this.getToken = args?.getToken || this.getToken.bind(this);
4057
4062
  }
4058
4063
  }
4059
4064
  MonkeyEcxAuthenticationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: MonkeyEcxAuthenticationService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
@@ -4118,79 +4123,79 @@ let MonkeyEcxAuthGuardByRole = class MonkeyEcxAuthGuardByRole {
4118
4123
  }
4119
4124
  static forRoles(roles, companyType, byExclusion) {
4120
4125
  class RoleCheck {
4121
- constructor() {
4126
+ constructor(monkeyecxAuthenticationService, router) {
4127
+ this.monkeyecxAuthenticationService = monkeyecxAuthenticationService;
4128
+ this.router = router;
4122
4129
  this.tokenCredentials = null;
4123
4130
  // not to do
4124
4131
  }
4125
- /* private navigateToErrorPage() {
4126
- let path = '/app/pages/forbidden';
4127
- if (companyType) {
4128
- path = `/app/${companyType}/pages/forbidden`;
4129
- }
4130
- this.router?.navigate([path.toLowerCase()]);
4132
+ navigateToErrorPage() {
4133
+ let path = '/app/pages/forbidden';
4134
+ if (companyType) {
4135
+ path = `/app/${companyType}/pages/forbidden`;
4136
+ }
4137
+ this.router?.navigate([path.toLowerCase()]);
4131
4138
  }
4132
-
4133
- private getRole(): string {
4134
- const { tokenCredentials } = this;
4135
-
4136
- if (!tokenCredentials) return '';
4137
- if (tokenCredentials?.programAdmin === 'true') {
4138
- return 'PROGRAM_ADMIN';
4139
- }
4140
- if (tokenCredentials?.programAdmin === true) {
4141
- return 'PROGRAM_ADMIN';
4142
- }
4143
-
4144
- return tokenCredentials?.role || '';
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 || '';
4145
4150
  }
4146
-
4147
- private allowedSecurityAccess(roles: string[]): boolean {
4148
- if (!roles?.length) return true;
4149
-
4150
- const found = roles?.indexOf(this.getRole());
4151
- let ret = false;
4152
- if (byExclusion) {
4153
- ret = true;
4154
- if (found > -1) {
4155
- ret = false;
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
+ }
4156
4161
  }
4157
- } else {
4158
- ret = false;
4159
- if (found > -1) {
4160
- ret = true;
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;
4161
4170
  }
4162
- }
4163
- if (!roles || roles.length === 0 || this.getRole() === 'PROGRAM_ADMIN') {
4164
- ret = true;
4165
- }
4166
- return ret;
4167
- } */
4171
+ return ret;
4172
+ }
4168
4173
  async canActivate() {
4169
4174
  console.log('roles');
4170
4175
  console.log(roles);
4171
- // if (!this.tokenCredentials) {
4172
- // this.tokenCredentials = await this.storageService.getToken();
4173
- // }
4176
+ if (!this.tokenCredentials) {
4177
+ this.tokenCredentials = await this.monkeyecxAuthenticationService.getToken();
4178
+ }
4174
4179
  console.log('this.tokenCredentials');
4175
4180
  console.log(this.tokenCredentials);
4176
4181
  console.log('checando');
4177
- // if (!this.allowedSecurityAccess(roles)) {
4178
- // console.log('checou erro');
4179
- // this.navigateToErrorPage();
4180
- // return false;
4181
- // }
4182
+ if (!this.allowedSecurityAccess(roles)) {
4183
+ console.log('checou erro');
4184
+ this.navigateToErrorPage();
4185
+ return false;
4186
+ }
4182
4187
  console.log('checou ok');
4183
4188
  return true;
4184
4189
  }
4185
4190
  }
4186
- RoleCheck.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: RoleCheck, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
4191
+ 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 });
4187
4192
  RoleCheck.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: RoleCheck, providedIn: 'root' });
4188
4193
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: RoleCheck, decorators: [{
4189
4194
  type: Injectable,
4190
4195
  args: [{
4191
4196
  providedIn: 'root'
4192
4197
  }]
4193
- }], ctorParameters: function () { return []; } });
4198
+ }], ctorParameters: function () { return [{ type: MonkeyEcxAuthenticationService }, { type: i2$2.Router }]; } });
4194
4199
  return RoleCheck;
4195
4200
  }
4196
4201
  };