Add new alias entity type - Current User Owner
This commit is contained in:
parent
a736490a36
commit
e7aae9664a
@ -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;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -28,7 +28,8 @@
|
||||
<tb-entity-autocomplete
|
||||
fxFlex
|
||||
*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"
|
||||
[entityType]="modelValue.entityType"
|
||||
formControlName="entityId">
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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<EntityType | AliasEntityType, Enti
|
||||
type: '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'
|
||||
}
|
||||
]
|
||||
]
|
||||
);
|
||||
|
||||
@ -853,6 +853,7 @@
|
||||
"type-current-customer": "Current Customer",
|
||||
"type-current-tenant": "Current Tenant",
|
||||
"type-current-user": "Current User",
|
||||
"type-current-user-owner": "Current User Owner",
|
||||
"search": "Search entities",
|
||||
"selected-entities": "{ count, plural, 1 {1 entity} other {# entities} } selected",
|
||||
"entity-name": "Entity name",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user