Fix view own transaction
* Basic user can view charging graph
Handle own user
* Fix charging profile auth check
* Refactor
* Separate methods
MODIFY
src/authorization/AuthorizationsDefinition.ts
src/authorization/AuthorizationsDefinition.ts
@@ -943,7 +943,7 @@ export const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
'connectors.connectorId', 'connectors.status', 'connectors.type', 'connectors.power', 'connectors.errorCode',
'connectors.currentTotalConsumptionWh', 'connectors.currentInstantWatts', 'connectors.currentStateOfCharge', 'connectors.info', 'connectors.vendorErrorCode',
'connectors.currentTransactionID', 'connectors.currentTotalInactivitySecs', 'lastReboot', 'createdOn', 'companyID',
- 'connectors.user.id', 'connectors.user.name', 'connectors.user.firstName', 'connectors.user.email',
+ 'connectors.user.id', 'connectors.user.name', 'connectors.user.firstName', 'connectors.user.email', 'connectors.currentTagID',
'chargePoints.chargePointID','chargePoints.currentType','chargePoints.voltage','chargePoints.amperage','chargePoints.numberOfConnectedPhase',
'chargePoints.cannotChargeInParallel','chargePoints.sharePowerToAllConnectors','chargePoints.excludeFromPowerLimitation','chargePoints.ocppParamForPowerLimitation',
'chargePoints.power','chargePoints.efficiency','chargePoints.connectorIDs'

MODIFY
src/authorization/dynamic-filters/OwnUserDynamicAuthorizationFilter.ts
src/authorization/dynamic-filters/OwnUserDynamicAuthorizationFilter.ts
@@ -29,8 +29,9 @@ export default class OwnUserDynamicAuthorizationFilter extends DynamicAuthorizat
authorizationFilters.authorized = true;
}
// Delete user property in entity in case we are not authorized
- if (!authorizationFilters.authorized && Utils.objectHasProperty(entityData, 'user') && !Utils.isNullOrUndefined(entityData['user'])) {
- delete entityData['user'];
+ if (!authorizationFilters.authorized) {
+ Utils.deleteUserPropertiesFromEntity(entityData);
+ Utils.deleteTagPropertiesFromEntity(entityData);
}
}

MODIFY
src/server/rest/v1/service/ChargingStationService.ts
src/server/rest/v1/service/ChargingStationService.ts
@@ -296,7 +296,7 @@ export default class ChargingStationService {
// Filter
const filteredRequest = ChargingStationValidatorRest.getInstance().validateChargingProfileUpdateReq({ ...req.params, ...req.body });
// Check dynamic auth
- await UtilsService.checkAndGetChargingProfileAuthorization(req.tenant, req.user, filteredRequest.id, Action.UPDATE, action, filteredRequest);
+ await AuthorizationService.checkAndGetChargingProfileAuthorizations(req.tenant, req.user, { ID: filteredRequest.id }, Action.UPDATE);
// Update
const chargingProfileID = await ChargingStationService.setAndSaveChargingProfile(filteredRequest, action, req);
res.send(Object.assign({ id: chargingProfileID }, Constants.REST_RESPONSE_SUCCESS));

MODIFY
src/utils/Utils.ts
src/utils/Utils.ts
@@ -1740,4 +1740,22 @@ export default class Utils {
};
}
}
+
+ public static deleteUserPropertiesFromEntity(entityData?: EntityData): void {
+ Utils.deletePropertiesFromEntity(entityData, ['user']);
+ }
+
+ public static deleteTagPropertiesFromEntity(entityData?: EntityData): void {
+ Utils.deletePropertiesFromEntity(entityData, ['tag', 'currentTagID']);
+ }
+
+ private static deletePropertiesFromEntity(entityData?: EntityData, properties?: string[]): void {
+ if (!Utils.isNullOrUndefined(entityData) && !Utils.isNullOrUndefined(properties)) {
+ for (const propertyName of properties) {
+ if (Utils.objectHasProperty(entityData, propertyName) && !Utils.isNullOrUndefined(entityData[propertyName])) {
+ delete entityData[propertyName];
+ }
+ }
+ }
+ }
}

Fix view own transaction (#3679)

* Basic user can view charging graph

- Handle own user

* Fix charging profile auth check

* Refactor

* Separate methods