Comply with PR remarks
Remove debug and poolcar action
Add metadata for pool car
Update auth definition to comply with remarks
Remove unnecessary auth interface
Update loggingHelper
MODIFY
src/authorization/AuthorizationsDefinition.ts
src/authorization/AuthorizationsDefinition.ts
@@ -487,7 +487,7 @@ export const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
'chargeAlternativePhase', 'chargeOptionPower', 'chargeOptionPhase', 'image', 'chargeOptionPhaseAmp', 'chargeAlternativePhaseAmp'
]
},
- { resource: Entity.CAR, action: [Action.CREATE, Action.CREATE_POOL_CAR, Action.UPDATE, Action.DELETE] },
+ { resource: Entity.CAR, action: [Action.CREATE, Action.UPDATE, Action.DELETE] },
{
resource: Entity.CAR, action: Action.READ,
attributes: [
@@ -501,6 +501,18 @@ export const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
},
{
resource: Entity.CAR, action: Action.LIST,
+ condition: {
+ Fn: 'custom:dynamicAuthorizations',
+ args: {
+ asserts: [],
+ filters: [],
+ metadata: {
+ createPoolCar: {
+ visible: true
+ }
+ }
+ }
+ },
attributes: [
'id', 'type', 'vin', 'licensePlate', 'converter', 'default', 'createdOn', 'lastChangedOn',
'carCatalog.id', 'carCatalog.vehicleMake', 'carCatalog.vehicleModel', 'carCatalog.vehicleModelVersion',
@@ -1209,7 +1221,12 @@ export const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
Fn: 'custom:dynamicAuthorizations',
args: {
asserts: [],
- filters: ['SitesAdmin']
+ filters: ['SitesAdmin'],
+ metadata: {
+ createPoolCar: {
+ visible: true
+ }
+ }
}
},
attributes: [
@@ -1225,7 +1242,7 @@ export const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
condition: {
Fn: 'custom:dynamicAuthorizations',
args: {
- asserts: ['-PoolCar'],
+ asserts: [],
filters: []
}
},

MODIFY
src/server/rest/v1/service/AuthorizationService.ts
src/server/rest/v1/service/AuthorizationService.ts
@@ -596,7 +596,6 @@ export default class AuthorizationService {
cars.canCreate = await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.CAR, Action.CREATE, authorizationFilter);
cars.canListUsers = await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.USER, Action.LIST, authorizationFilter);
cars.canListCarCatalog = await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.CAR_CATALOG, Action.LIST, authorizationFilter);
- cars.canCreatePoolCar = await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.CAR, Action.CREATE_POOL_CAR, authorizationFilter);
for (const car of cars.result) {
await AuthorizationService.addCarAuthorizations(tenant, userToken, car, authorizationFilter);
}
@@ -607,7 +606,6 @@ export default class AuthorizationService {
car.canDelete = await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.CAR, Action.DELETE, authorizationFilter, { CarID: car.id }, car);
car.canUpdate = await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.CAR, Action.UPDATE, authorizationFilter, { CarID: car.id }, car);
car.canListUsers = await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.USER, Action.LIST, authorizationFilter);
- car.canCreatePoolCar = await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.CAR, Action.CREATE_POOL_CAR, authorizationFilter);
// Optimize data over the net
Utils.removeCanPropertiesWithFalseValue(car);
}

MODIFY
src/types/Authorization.ts
src/types/Authorization.ts
@@ -156,8 +156,6 @@ export enum Action {
EXPORT_OCPP_PARAMS = 'ExportOCPPParams',
GENERATE_QR = 'GenerateQrCode',
MAINTAIN_PRICING_DEFINITIONS = 'MaintainPricingDefinitions',
- CREATE_POOL_CAR = 'CreatePoolCar',
- DEBUG = 'Debug',
}
export interface AuthorizationContext {
@@ -188,10 +186,6 @@ export interface AuthorizationActions {
metadata?: Record<string, unknown>;
}
-export interface CarAuthorizationActions extends AuthorizationActions {
- canCreatePoolCar?: boolean;
-}
-
export interface TagAuthorizationActions extends AuthorizationActions {
canUnassign?: boolean;
canAssign?: boolean;

MODIFY
src/types/Car.ts
src/types/Car.ts
-import { AuthorizationActions, CarAuthorizationActions } from './Authorization';
-
+import { AuthorizationActions } from './Authorization';
import CreatedUpdatedProps from './CreatedUpdatedProps';
export interface CarCatalog extends CreatedUpdatedProps, AuthorizationActions {
@@ -129,7 +128,7 @@ export enum CarType {
POOL_CAR = 'PC',
}
-export interface Car extends CreatedUpdatedProps, CarAuthorizationActions {
+export interface Car extends CreatedUpdatedProps, AuthorizationActions {
id?: string;
vin: string;
licensePlate: string;

MODIFY
src/utils/LoggingHelper.ts
src/utils/LoggingHelper.ts
@@ -50,26 +50,21 @@ export default class LoggingHelper {
};
}
- public static getCarProperties(car: Car): { carID: string; userID: string, carCatalogID: number } {
+ public static getCarProperties(car: Car): { userID: string } {
return {
- carID: car.id,
userID: car.userID,
- carCatalogID: car.carCatalogID
};
}
- public static getRegistrationTokenProperties(registrationToken: RegistrationToken): { registrationTokenID: string; siteAreaID: string } {
+ public static getRegistrationTokenProperties(registrationToken: RegistrationToken): { siteAreaID: string } {
return {
- registrationTokenID: registrationToken.id,
siteAreaID: registrationToken.siteAreaID
};
}
- public static getTagProperties(tag: Tag): { tagID: string; userID: string, visualID: string } {
+ public static getTagProperties(tag: Tag): { userID: string } {
return {
- tagID: tag.id,
- userID: tag.userID,
- visualID: tag.visualID
+ userID: tag.userID
};
}
}

Comply with PR remarks

- Remove debug and poolcar action
- Add metadata for pool car
- Update auth definition to comply with remarks
- Remove unnecessary auth interface
- Update loggingHelper