@seniorsistemas/yms-integration 1.10.6 → 1.11.0

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.
@@ -188,6 +188,10 @@
188
188
  ControladorCancelasService.prototype.closeGate = function (ip) {
189
189
  return this.http.post(this.url + "actions/closeGate", { ip: ip }).pipe(this.defaultCatch());
190
190
  };
191
+ ControladorCancelasService.prototype.checkAccess = function (resources) {
192
+ var acess = { includeFilters: false, permissions: resources };
193
+ return this.http.post("platform/authorization/queries/checkAccess", acess).pipe(this.defaultCatch());
194
+ };
191
195
  ControladorCancelasService = __decorate([
192
196
  core.Injectable(),
193
197
  __metadata("design:paramtypes", [http.HttpClient, api.MessageService])
@@ -212,35 +216,90 @@
212
216
  }());
213
217
  var ControladorCancelaComponent = /** @class */ (function (_super) {
214
218
  __extends(ControladorCancelaComponent, _super);
215
- function ControladorCancelaComponent(service, translate, permissionsService) {
219
+ function ControladorCancelaComponent(service, translate) {
216
220
  var _this = _super.call(this) || this;
217
221
  _this.service = service;
218
222
  _this.translate = translate;
219
- _this.permissionsService = permissionsService;
220
223
  _this.successState = 'default';
221
- _this.canOpenGate = false;
222
- _this.canCloseGate = false;
224
+ _this.permissionOpenGate = false;
225
+ _this.permissionCloseGate = false;
226
+ _this.uriGateDefault = "res://senior.com.br/yms/devices/gate";
223
227
  _this.unsubscribe$ = new rxjs.Subject();
224
228
  _this.gates$ = new rxjs.Subject();
225
229
  return _this;
226
230
  }
227
231
  ControladorCancelaComponent.prototype.ngOnInit = function () {
232
+ this.checkPermissionsGates();
233
+ };
234
+ ControladorCancelaComponent.prototype.checkPermissionsGates = function () {
228
235
  var _this = this;
229
236
  this.service
230
237
  .listGateByArea(this.sequenciaCircuito.area.id)
231
238
  .pipe(operators.takeUntil(this.unsubscribe$))
232
- .subscribe(function (res) { return _this.gates$.next(res.contents); });
233
- this.permissionsService
234
- .get("gate")
235
- .pipe(operators.map(function (permissions) {
236
- if (permissions.Open) {
237
- _this.canOpenGate = true;
239
+ .subscribe(function (res) {
240
+ var gates = res.contents;
241
+ var resourcesUri = _this.buildResourceGateAndAction(gates);
242
+ if (resourcesUri.length <= 0) {
243
+ return;
238
244
  }
239
- if (permissions.Close) {
240
- _this.canCloseGate = true;
245
+ _this.checkAcessPermissionGate(resourcesUri, gates);
246
+ });
247
+ };
248
+ ControladorCancelaComponent.prototype.buildResourceGateAndAction = function (gates) {
249
+ var resourcesUri = [];
250
+ resourcesUri.push({ resource: this.uriGateDefault, action: "Close" });
251
+ resourcesUri.push({ resource: this.uriGateDefault, action: "Open" });
252
+ gates.filter(function (gate) {
253
+ if (gate.resourceUri !== undefined) {
254
+ resourcesUri.push({ resource: gate.resourceUri, action: "Close" });
255
+ resourcesUri.push({ resource: gate.resourceUri, action: "Open" });
241
256
  }
242
- }))
243
- .toPromise();
257
+ });
258
+ return resourcesUri;
259
+ };
260
+ ControladorCancelaComponent.prototype.checkAcessPermissionGate = function (resourcesUri, gates) {
261
+ var _this = this;
262
+ this.service.checkAccess(resourcesUri)
263
+ .pipe(operators.takeUntil(this.unsubscribe$), operators.finalize(function () { return _this.loading = undefined; }))
264
+ .subscribe(function (_a) {
265
+ var permissions = _a.permissions;
266
+ _this.gates$.next(_this.buildGateWithActionsAndPermissions(permissions, gates));
267
+ });
268
+ };
269
+ ControladorCancelaComponent.prototype.buildGateWithActionsAndPermissions = function (permissions, gates) {
270
+ var _this = this;
271
+ var gateActions = [];
272
+ gates.filter(function (gate) {
273
+ gate.isActionButton = false;
274
+ gate.actions = [];
275
+ if (_this.permissionCloseGate && _this.permissionOpenGate) {
276
+ gate.isActionButton = true;
277
+ gateActions.push(gate);
278
+ return;
279
+ }
280
+ permissions.filter(function (permission) {
281
+ gate.isActionButton = gate.isActionButton ? true : _this.checkDefaultGatePermission(permission, gate);
282
+ if (gate.resourceUri === permission.resource) {
283
+ gate.actions.push({ action: permission.action, authorized: permission.authorized });
284
+ gate.isActionButton = gate.isActionButton ? true : permission.authorized;
285
+ }
286
+ });
287
+ gateActions.push(gate);
288
+ });
289
+ return gateActions;
290
+ };
291
+ ControladorCancelaComponent.prototype.checkDefaultGatePermission = function (permission, gate) {
292
+ if (this.uriGateDefault === permission.resource) {
293
+ if (permission.action === "Open") {
294
+ this.permissionOpenGate = permission.authorized;
295
+ return permission.authorized;
296
+ }
297
+ if (permission.action === "Close") {
298
+ this.permissionCloseGate = permission.authorized;
299
+ return permission.authorized;
300
+ }
301
+ }
302
+ return false;
244
303
  };
245
304
  ControladorCancelaComponent.prototype.ngOnDestroy = function () {
246
305
  this.unsubscribe$.next();
@@ -248,15 +307,33 @@
248
307
  };
249
308
  ControladorCancelaComponent.prototype.model = function (gate) {
250
309
  var _this = this;
310
+ var canOpenGate = false;
311
+ var canCloseGate = false;
312
+ if (!(this.permissionCloseGate && this.permissionOpenGate)) {
313
+ gate.actions.filter(function (action) {
314
+ if (action.action === "Open") {
315
+ canOpenGate = action.authorized;
316
+ }
317
+ if (action.action === "Close") {
318
+ canCloseGate = action.authorized;
319
+ }
320
+ });
321
+ }
322
+ if (this.permissionOpenGate === true) {
323
+ canOpenGate = this.permissionOpenGate;
324
+ }
325
+ if (this.permissionCloseGate === true) {
326
+ canCloseGate = this.permissionCloseGate;
327
+ }
251
328
  return [
252
329
  {
253
330
  label: this.translate.instant('yms.integration.open_gate'),
254
- visible: this.canOpenGate,
331
+ visible: canOpenGate,
255
332
  command: function () { return _this.openGate(gate); }
256
333
  },
257
334
  {
258
335
  label: this.translate.instant('yms.integration.close_gate'),
259
- visible: this.canCloseGate,
336
+ visible: canCloseGate,
260
337
  command: function () { return _this.closeGate(gate); }
261
338
  }
262
339
  ];
@@ -282,7 +359,7 @@
282
359
  ControladorCancelaComponent = __decorate([
283
360
  core.Component({
284
361
  selector: 'controlador-cancela-component',
285
- template: "<div>\n <p-table [value]=\"gates$ | async\">\n <ng-template pTemplate=\"header\">\n <tr>\n <th>{{'yms.integration.gate_ip' | translate}}</th>\n <th>{{'yms.integration.gate_type' | translate}}</th>\n <th></th>\n </tr>\n </ng-template>\n <ng-template pTemplate=\"body\" let-rowData>\n <tr \n [@success]=\"successState === rowData.id ? successState : 'default'\" \n (@success.done)=\"successState = 'default'\"\n >\n <td>{{rowData.ip}}</td>\n <td>{{rowData.type | translate}}</td>\n <td>\n <span *sLoadingState=\"loading === rowData.id\">\n <s-button priority=\"default\" [auxiliary]=\"true\" label=\"A\u00E7\u00F5es\" [model]=\"model(rowData)\">\n </s-button>\n </span>\n </td>\n </tr>\n </ng-template>\n </p-table>\n</div>",
362
+ template: "<div>\n <p-table [value]=\"gates$ | async\">\n <ng-template pTemplate=\"header\">\n <tr>\n <th>{{'yms.integration.gate_ip' | translate}}</th>\n <th>{{'yms.integration.gate_type' | translate}}</th>\n <th></th>\n </tr>\n </ng-template>\n <ng-template pTemplate=\"body\" let-rowData>\n <tr \n [@success]=\"successState === rowData.id ? successState : 'default'\" \n (@success.done)=\"successState = 'default'\"\n >\n <td>{{rowData.ip}}</td>\n <td>{{rowData.type | translate}}</td>\n <td>\n <div *ngIf=\"rowData.isActionButton\">\n <span *sLoadingState=\"loading === rowData.id\" >\n <s-button priority=\"default\" [auxiliary]=\"true\" label=\"A\u00E7\u00F5es\" [model]=\"model(rowData)\" >\n </s-button>\n </span>\n </div>\n </td>\n </tr>\n </ng-template>\n </p-table>\n</div>",
286
363
  animations: [
287
364
  animations.trigger('success', [
288
365
  animations.state('*', animations.style({
@@ -298,7 +375,8 @@
298
375
  ])
299
376
  ]
300
377
  }),
301
- __metadata("design:paramtypes", [ControladorCancelasService, core$1.TranslateService, platformComponents.PermissionsService])
378
+ __metadata("design:paramtypes", [ControladorCancelasService,
379
+ core$1.TranslateService])
302
380
  ], ControladorCancelaComponent);
303
381
  return ControladorCancelaComponent;
304
382
  }(ControladorCancelaDescritor));