Commit d61890a96ab6e33e319a93c9c30020f61866b3af

Authored by Igor Kulikov
Committed by GitHub
2 parents 7ff92cf5 b8cc971e

Merge pull request #4236 from vvlladd28/improvement/validate/entityId

UI: Added validate EntityId before update dashboard state
... ... @@ -18,6 +18,8 @@ import _ from 'lodash';
18 18 import { Observable, Subject } from 'rxjs';
19 19 import { finalize, share } from 'rxjs/operators';
20 20 import { Datasource } from '@app/shared/models/widget.models';
  21 +import { EntityId } from '@shared/models/id/entity-id';
  22 +import { NULL_UUID } from '@shared/models/id/has-uuid';
21 23
22 24 const varsRegex = /\${([^}]*)}/g;
23 25
... ... @@ -431,3 +433,7 @@ export function generateSecret(length?: number): string {
431 433 }
432 434 return str.concat(generateSecret(length - str.length));
433 435 }
  436 +
  437 +export function validateEntityId(entityId: EntityId): boolean {
  438 + return isDefinedAndNotNull(entityId.id) && entityId.id !== NULL_UUID && isDefinedAndNotNull(entityId.entityType);
  439 +}
... ...
... ... @@ -55,7 +55,7 @@ import { AppState } from '@core/core.state';
55 55 import { WidgetService } from '@core/http/widget.service';
56 56 import { UtilsService } from '@core/services/utils.service';
57 57 import { forkJoin, Observable, of, ReplaySubject, Subscription, throwError } from 'rxjs';
58   -import { deepClone, insertVariable, isDefined, objToBase64, objToBase64URI } from '@core/utils';
  58 +import { deepClone, insertVariable, isDefined, objToBase64, objToBase64URI, validateEntityId } from '@core/utils';
59 59 import {
60 60 IDynamicWidgetComponent,
61 61 WidgetContext,
... ... @@ -1004,7 +1004,7 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI
1004 1004 const type = descriptor.type;
1005 1005 const targetEntityParamName = descriptor.stateEntityParamName;
1006 1006 let targetEntityId: EntityId;
1007   - if (descriptor.setEntityId) {
  1007 + if (descriptor.setEntityId && validateEntityId(entityId)) {
1008 1008 targetEntityId = entityId;
1009 1009 }
1010 1010 switch (type) {
... ...