Site Admin can only create basic users
MODIFY
src/authorization/AuthorizationsDefinition.ts
src/authorization/AuthorizationsDefinition.ts
@@ -774,7 +774,16 @@ const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
'notificationsActive', 'notifications', 'phone', 'mobile', 'iNumber', 'costCenter', 'address', 'technical'
],
},
- { resource: Entity.USER, action: [Action.CREATE, Action.UPDATE, Action.SYNCHRONIZE_BILLING_USER] },
+ {
+ resource: Entity.USER, action: [Action.CREATE, Action.UPDATE],
+ condition: {
+ Fn: 'custom:dynamicAuthorizations',
+ args: {
+ asserts: ['BasicUser']
+ }
+ }
+ },
+ { resource: Entity.USER, action: Action.SYNCHRONIZE_BILLING_USER },
{
resource: Entity.USER, action: Action.DELETE,
condition: {

MODIFY
src/authorization/DynamicAuthorizationFactory.ts
src/authorization/DynamicAuthorizationFactory.ts
@@ -4,6 +4,7 @@ import AssignedSitesCompaniesDynamicAuthorizationDataSource from './dynamic-data
import AssignedSitesCompaniesDynamicAuthorizationFilter from './dynamic-filters/AssignedSitesCompaniesDynamicAuthorizationFilter';
import AssignedSitesDynamicAuthorizationDataSource from './dynamic-data-source/AssignedSitesDynamicAuthorizationDataSource';
import AssignedSitesDynamicAuthorizationFilter from './dynamic-filters/AssignedSitesDynamicAuthorizationFilter';
+import BasicUserDynamicAuthorizationAssert from './dynamic-assert/BasicUserDynamicAuthorizationAssert';
import DynamicAuthorizationAssert from './DynamicAuthorizationAssert';
import DynamicAuthorizationDataSource from './DynamicAuthorizationDataSource';
import DynamicAuthorizationFilter from './DynamicAuthorizationFilter';
@@ -80,6 +81,9 @@ export default class DynamicAuthorizationFactory {
case DynamicAuthorizationAssertName.OWN_USER:
dynamicAssert = new OwnUserDynamicAuthorizationAssert(tenant, userToken, negateAssert);
break;
+ case DynamicAuthorizationAssertName.BASIC_USER:
+ dynamicAssert = new BasicUserDynamicAuthorizationAssert(tenant, userToken, negateAssert);
+ break;
}
return dynamicAssert;
}

ADD
src/authorization/dynamic-assert/BasicUserDynamicAuthorizationAssert.ts
+import User, { UserRole } from '../../types/User';
+
+import DynamicAuthorizationAssert from '../DynamicAuthorizationAssert';
+import { Entity } from '../../types/Authorization';
+import { EntityDataType } from '../../types/GlobalType';
+
+export default class BasicUserDynamicAuthorizationAssert extends DynamicAuthorizationAssert {
+ public processAssert(entityData: EntityDataType): boolean {
+ const user = entityData as User;
+ if (user.role === UserRole.BASIC) {
+ return true;
+ }
+ return false;
+ }
+
+ public getApplicableEntities(): Entity[] {
+ return [
+ Entity.USER
+ ];
+ }
+}

MODIFY
src/types/Authorization.ts
src/types/Authorization.ts
@@ -223,6 +223,7 @@ export enum DynamicAuthorizationFilterName {
export enum DynamicAuthorizationAssertName {
POOL_CAR = 'PoolCar',
OWN_USER = 'OwnUser',
+ BASIC_USER = 'BasicUser'
}
export enum DynamicAuthorizationDataSourceName {

Site Admin can only create basic users