Add new alias entity type - Current User Owner

This commit is contained in:
Igor Kulikov 2020-08-10 15:34:23 +03:00
parent a736490a36
commit e7aae9664a
6 changed files with 49 additions and 4 deletions

View File

@ -579,6 +579,9 @@ export class EntityService {
} }
if (useAliasEntityTypes) { if (useAliasEntityTypes) {
entityTypes.push(AliasEntityType.CURRENT_USER); entityTypes.push(AliasEntityType.CURRENT_USER);
if (authUser.authority !== Authority.SYS_ADMIN) {
entityTypes.push(AliasEntityType.CURRENT_USER_OWNER);
}
} }
if (allowedEntityTypes && allowedEntityTypes.length) { if (allowedEntityTypes && allowedEntityTypes.length) {
for (let index = entityTypes.length - 1; index >= 0; index--) { for (let index = entityTypes.length - 1; index >= 0; index--) {
@ -992,6 +995,15 @@ export class EntityService {
const authUser = getCurrentAuthUser(this.store); const authUser = getCurrentAuthUser(this.store);
entityId.entityType = EntityType.USER; entityId.entityType = EntityType.USER;
entityId.id = authUser.userId; 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; return entityId;
} }

View File

@ -26,6 +26,8 @@ import { BaseData } from '@shared/models/base-data';
import { EntityId } from '@shared/models/id/entity-id'; import { EntityId } from '@shared/models/id/entity-id';
import { EntityService } from '@core/http/entity.service'; import { EntityService } from '@core/http/entity.service';
import { coerceBooleanProperty } from '@angular/cdk/coercion'; import { coerceBooleanProperty } from '@angular/cdk/coercion';
import { getCurrentAuthUser } from '@core/auth/auth.selectors';
import { Authority } from '@shared/models/authority.enum';
@Component({ @Component({
selector: 'tb-entity-autocomplete', selector: 'tb-entity-autocomplete',
@ -196,6 +198,18 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit
this.noEntitiesMatchingText = 'customer.no-customers-matching'; this.noEntitiesMatchingText = 'customer.no-customers-matching';
this.entityRequiredText = 'customer.default-customer-required'; this.entityRequiredText = 'customer.default-customer-required';
break; 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(); const currentEntity = this.getCurrentEntity();
@ -328,6 +342,13 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit
return EntityType.TENANT; return EntityType.TENANT;
} else if (entityType === AliasEntityType.CURRENT_USER) { } else if (entityType === AliasEntityType.CURRENT_USER) {
return EntityType.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; return entityType;
} }

View File

@ -28,7 +28,8 @@
<tb-entity-autocomplete <tb-entity-autocomplete
fxFlex fxFlex
*ngIf="modelValue.entityType && modelValue.entityType !== AliasEntityType.CURRENT_TENANT *ngIf="modelValue.entityType && modelValue.entityType !== AliasEntityType.CURRENT_TENANT
&& modelValue.entityType !== AliasEntityType.CURRENT_USER" && modelValue.entityType !== AliasEntityType.CURRENT_USER
&& modelValue.entityType !== AliasEntityType.CURRENT_USER_OWNER"
[required]="required" [required]="required"
[entityType]="modelValue.entityType" [entityType]="modelValue.entityType"
formControlName="entityId"> formControlName="entityId">

View File

@ -97,7 +97,8 @@ export class EntitySelectComponent implements ControlValueAccessor, OnInit, Afte
ngOnInit() { ngOnInit() {
this.entitySelectFormGroup.get('entityType').valueChanges.subscribe( this.entitySelectFormGroup.get('entityType').valueChanges.subscribe(
(value) => { (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.modelValue.id = NULL_UUID;
} }
this.updateView(value, this.modelValue.id); this.updateView(value, this.modelValue.id);
@ -147,7 +148,8 @@ export class EntitySelectComponent implements ControlValueAccessor, OnInit, Afte
}; };
if (this.modelValue.entityType && (this.modelValue.id || if (this.modelValue.entityType && (this.modelValue.id ||
this.modelValue.entityType === AliasEntityType.CURRENT_TENANT || 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); this.propagateChange(this.modelValue);
} else { } else {
this.propagateChange(null); this.propagateChange(null);

View File

@ -51,7 +51,8 @@ export enum EntityType {
export enum AliasEntityType { export enum AliasEntityType {
CURRENT_CUSTOMER = 'CURRENT_CUSTOMER', CURRENT_CUSTOMER = 'CURRENT_CUSTOMER',
CURRENT_TENANT = 'CURRENT_TENANT', CURRENT_TENANT = 'CURRENT_TENANT',
CURRENT_USER = 'CURRENT_USER' CURRENT_USER = 'CURRENT_USER',
CURRENT_USER_OWNER = 'CURRENT_USER_OWNER'
} }
export interface EntityTypeTranslation { export interface EntityTypeTranslation {
@ -237,6 +238,13 @@ export const entityTypeTranslations = new Map<EntityType | AliasEntityType, Enti
type: 'entity.type-current-user', type: 'entity.type-current-user',
list: 'entity.type-current-user' list: 'entity.type-current-user'
} }
],
[
AliasEntityType.CURRENT_USER_OWNER,
{
type: 'entity.type-current-user-owner',
list: 'entity.type-current-user-owner'
}
] ]
] ]
); );

View File

@ -853,6 +853,7 @@
"type-current-customer": "Current Customer", "type-current-customer": "Current Customer",
"type-current-tenant": "Current Tenant", "type-current-tenant": "Current Tenant",
"type-current-user": "Current User", "type-current-user": "Current User",
"type-current-user-owner": "Current User Owner",
"search": "Search entities", "search": "Search entities",
"selected-entities": "{ count, plural, 1 {1 entity} other {# entities} } selected", "selected-entities": "{ count, plural, 1 {1 entity} other {# entities} } selected",
"entity-name": "Entity name", "entity-name": "Entity name",