New Assert User Mandatory
MODIFY
src/authorization/AuthorizationsDefinition.ts
src/authorization/AuthorizationsDefinition.ts
@@ -1073,7 +1073,16 @@ export const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
'user.name', 'user.firstName', 'user.email', 'createdOn', 'lastChangedOn'
],
},
- { resource: Entity.TAG, action: Action.CREATE },
+ {
+ resource: Entity.TAG, action: Action.CREATE,
+ condition: {
+ Fn: 'custom:dynamicAuthorizations',
+ args: {
+ asserts: ['UserMandatory'],
+ filters: []
+ }
+ }
+ },
{
resource: Entity.TAG, action: Action.READ,
condition: {
@@ -1098,7 +1107,7 @@ export const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
],
},
{
- resource: Entity.TAG, action: [Action.UPDATE, Action.DELETE],
+ resource: Entity.TAG, action: Action.DELETE,
condition: {
Fn: 'custom:dynamicAuthorizations',
args: {
@@ -1107,6 +1116,16 @@ export const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
}
}
},
+ {
+ resource: Entity.TAG, action: Action.UPDATE,
+ condition: {
+ Fn: 'custom:dynamicAuthorizations',
+ args: {
+ asserts: ['UserMandatory'],
+ filters: ['SitesAdmin', 'LocalIssuer']
+ }
+ }
+ },
]
},
siteOwner: {

MODIFY
src/authorization/DynamicAuthorizationFactory.ts
src/authorization/DynamicAuthorizationFactory.ts
@@ -20,6 +20,7 @@ import SitesAdminDynamicAuthorizationFilter from './dynamic-filters/SitesAdminDy
import SitesOwnerDynamicAuthorizationDataSource from './dynamic-data-source/SitesOwnerDynamicAuthorizationDataSource';
import SitesOwnerDynamicAuthorizationFilter from './dynamic-filters/SitesOwnerDynamicAuthorizationFilter';
import Tenant from '../types/Tenant';
+import UserMandatoryDynamicAuthorizationAssert from './dynamic-assert/UserMandatoryDynamicAuthorizationAssert';
import UserToken from '../types/UserToken';
export default class DynamicAuthorizationFactory {
@@ -84,6 +85,9 @@ export default class DynamicAuthorizationFactory {
case DynamicAuthorizationAssertName.BASIC_USER:
dynamicAssert = new BasicUserDynamicAuthorizationAssert(tenant, userToken, negateAssert);
break;
+ case DynamicAuthorizationAssertName.USER_MANDATORY:
+ dynamicAssert = new UserMandatoryDynamicAuthorizationAssert(tenant, userToken, negateAssert);
+ break;
}
return dynamicAssert;
}

ADD
src/authorization/dynamic-assert/UserMandatoryDynamicAuthorizationAssert.ts
+import DynamicAuthorizationAssert from '../DynamicAuthorizationAssert';
+import { Entity } from '../../types/Authorization';
+import { EntityDataType } from '../../types/GlobalType';
+import Tag from '../../types/Tag';
+
+export default class UserMandatoryDynamicAuthorizationAssert extends DynamicAuthorizationAssert {
+ public processAssert(entityData: EntityDataType): boolean {
+ const tag = entityData as Tag;
+ if (tag?.userID) {
+ return true;
+ }
+ return false;
+ }
+
+ public getApplicableEntities(): Entity[] {
+ return [
+ Entity.TAG
+ ];
+ }
+}

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

New Assert User Mandatory