From e7aae9664a91b2feb206587ed484030d9e66dd61 Mon Sep 17 00:00:00 2001 From: Igor Kulikov Date: Mon, 10 Aug 2020 15:34:23 +0300 Subject: [PATCH] Add new alias entity type - Current User Owner --- ui-ngx/src/app/core/http/entity.service.ts | 12 +++++++++++ .../entity/entity-autocomplete.component.ts | 21 +++++++++++++++++++ .../entity/entity-select.component.html | 3 ++- .../entity/entity-select.component.ts | 6 ++++-- .../app/shared/models/entity-type.models.ts | 10 ++++++++- .../assets/locale/locale.constant-en_US.json | 1 + 6 files changed, 49 insertions(+), 4 deletions(-) diff --git a/ui-ngx/src/app/core/http/entity.service.ts b/ui-ngx/src/app/core/http/entity.service.ts index 7034029e93..0f5f1d554a 100644 --- a/ui-ngx/src/app/core/http/entity.service.ts +++ b/ui-ngx/src/app/core/http/entity.service.ts @@ -579,6 +579,9 @@ export class EntityService { } if (useAliasEntityTypes) { entityTypes.push(AliasEntityType.CURRENT_USER); + if (authUser.authority !== Authority.SYS_ADMIN) { + entityTypes.push(AliasEntityType.CURRENT_USER_OWNER); + } } if (allowedEntityTypes && allowedEntityTypes.length) { for (let index = entityTypes.length - 1; index >= 0; index--) { @@ -992,6 +995,15 @@ export class EntityService { const authUser = getCurrentAuthUser(this.store); entityId.entityType = EntityType.USER; entityId.id = authUser.userId; + } else if (entityType === AliasEntityType.CURRENT_USER_OWNER){ + const authUser = getCurrentAuthUser(this.store); + if (authUser.authority === Authority.TENANT_ADMIN) { + entityId.entityType = EntityType.TENANT; + entityId.id = authUser.tenantId; + } else if (authUser.authority === Authority.CUSTOMER_USER) { + entityId.entityType = EntityType.CUSTOMER; + entityId.id = authUser.customerId; + } } return entityId; } diff --git a/ui-ngx/src/app/shared/components/entity/entity-autocomplete.component.ts b/ui-ngx/src/app/shared/components/entity/entity-autocomplete.component.ts index e649a8702b..faeda98a10 100644 --- a/ui-ngx/src/app/shared/components/entity/entity-autocomplete.component.ts +++ b/ui-ngx/src/app/shared/components/entity/entity-autocomplete.component.ts @@ -26,6 +26,8 @@ import { BaseData } from '@shared/models/base-data'; import { EntityId } from '@shared/models/id/entity-id'; import { EntityService } from '@core/http/entity.service'; import { coerceBooleanProperty } from '@angular/cdk/coercion'; +import { getCurrentAuthUser } from '@core/auth/auth.selectors'; +import { Authority } from '@shared/models/authority.enum'; @Component({ selector: 'tb-entity-autocomplete', @@ -196,6 +198,18 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit this.noEntitiesMatchingText = 'customer.no-customers-matching'; this.entityRequiredText = 'customer.default-customer-required'; break; + case AliasEntityType.CURRENT_USER_OWNER: + const authUser = getCurrentAuthUser(this.store); + if (authUser.authority === Authority.TENANT_ADMIN) { + this.entityText = 'tenant.tenant'; + this.noEntitiesMatchingText = 'tenant.no-tenants-matching'; + this.entityRequiredText = 'tenant.tenant-required'; + } else { + this.entityText = 'customer.default-customer'; + this.noEntitiesMatchingText = 'customer.no-customers-matching'; + this.entityRequiredText = 'customer.default-customer-required'; + } + break; } } const currentEntity = this.getCurrentEntity(); @@ -328,6 +342,13 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit return EntityType.TENANT; } else if (entityType === AliasEntityType.CURRENT_USER) { return EntityType.USER; + } else if (entityType === AliasEntityType.CURRENT_USER_OWNER) { + const authUser = getCurrentAuthUser(this.store); + if (authUser.authority === Authority.TENANT_ADMIN) { + return EntityType.TENANT; + } else { + return EntityType.CUSTOMER; + } } return entityType; } diff --git a/ui-ngx/src/app/shared/components/entity/entity-select.component.html b/ui-ngx/src/app/shared/components/entity/entity-select.component.html index 8b75e1c00b..957633cd7f 100644 --- a/ui-ngx/src/app/shared/components/entity/entity-select.component.html +++ b/ui-ngx/src/app/shared/components/entity/entity-select.component.html @@ -28,7 +28,8 @@ diff --git a/ui-ngx/src/app/shared/components/entity/entity-select.component.ts b/ui-ngx/src/app/shared/components/entity/entity-select.component.ts index 0383d83c00..fb1c23e93a 100644 --- a/ui-ngx/src/app/shared/components/entity/entity-select.component.ts +++ b/ui-ngx/src/app/shared/components/entity/entity-select.component.ts @@ -97,7 +97,8 @@ export class EntitySelectComponent implements ControlValueAccessor, OnInit, Afte ngOnInit() { this.entitySelectFormGroup.get('entityType').valueChanges.subscribe( (value) => { - if(value === AliasEntityType.CURRENT_TENANT || value === AliasEntityType.CURRENT_USER) { + if(value === AliasEntityType.CURRENT_TENANT || value === AliasEntityType.CURRENT_USER || + value === AliasEntityType.CURRENT_USER_OWNER) { this.modelValue.id = NULL_UUID; } this.updateView(value, this.modelValue.id); @@ -147,7 +148,8 @@ export class EntitySelectComponent implements ControlValueAccessor, OnInit, Afte }; if (this.modelValue.entityType && (this.modelValue.id || this.modelValue.entityType === AliasEntityType.CURRENT_TENANT || - this.modelValue.entityType === AliasEntityType.CURRENT_USER)) { + this.modelValue.entityType === AliasEntityType.CURRENT_USER || + this.modelValue.entityType === AliasEntityType.CURRENT_USER_OWNER)) { this.propagateChange(this.modelValue); } else { this.propagateChange(null); diff --git a/ui-ngx/src/app/shared/models/entity-type.models.ts b/ui-ngx/src/app/shared/models/entity-type.models.ts index 05e240581d..6841a911b7 100644 --- a/ui-ngx/src/app/shared/models/entity-type.models.ts +++ b/ui-ngx/src/app/shared/models/entity-type.models.ts @@ -51,7 +51,8 @@ export enum EntityType { export enum AliasEntityType { CURRENT_CUSTOMER = 'CURRENT_CUSTOMER', CURRENT_TENANT = 'CURRENT_TENANT', - CURRENT_USER = 'CURRENT_USER' + CURRENT_USER = 'CURRENT_USER', + CURRENT_USER_OWNER = 'CURRENT_USER_OWNER' } export interface EntityTypeTranslation { @@ -237,6 +238,13 @@ export const entityTypeTranslations = new Map