Use correct start transaction auth check
Use correct auth check method
Fix runtime exception
Add missing CS auth flag
MODIFY
src/server/CommonUtilsService.ts
src/server/CommonUtilsService.ts
import User, { UserStatus } from '../types/User';
import { Action } from '../types/Authorization';
-import AuthorizationService from './rest/v1/service/AuthorizationService';
import Authorizations from '../authorization/Authorizations';
import BackendError from '../exception/BackendError';
import ChargingStation from '../types/ChargingStation';
@@ -13,6 +12,7 @@ import Tenant from '../types/Tenant';
import Transaction from '../types/Transaction';
import UserStorage from '../storage/mongodb/UserStorage';
import Utils from '../utils/Utils';
+import UtilsService from './rest/v1/service/UtilsService';
const MODULE_NAME = 'CommonUtilsService';
@@ -102,18 +102,8 @@ export class CommonUtilsService {
if (user.issuer && authAction) {
// Build the JWT Token
const userToken = await Authorizations.buildUserToken(tenant, user, [tag]);
- const authorization = await AuthorizationService.checkAndGetChargingStationsAuthorizations(tenant, userToken, authAction);
- if (!authorization.authorized) {
- throw new BackendError({
- ...LoggingHelper.getChargingStationProperties(chargingStation),
- action: action,
- message: `User with Tag ID '${tag.id}' is not authorized to perform the action '${authAction}'`,
- module: MODULE_NAME,
- method: 'checkAndGetAuthorizedUser',
- user: tag.user,
- detailedMessages: { userToken, tag }
- });
- }
+ // Check charging station authorizations
+ await UtilsService.checkAndGetChargingStationAuthorization(tenant, userToken, chargingStation.id, authAction, action, null, { withSite: true, withSiteArea: true });
}
return user;
}

MODIFY
src/server/rest/v1/service/AuthorizationService.ts
src/server/rest/v1/service/AuthorizationService.ts
@@ -764,6 +764,9 @@ export default class AuthorizationService {
chargingStation.canListUsers = await AuthorizationService.canPerformAuthorizationAction(
tenant, userToken, Entity.USER, Action.LIST, authorizationFilter,
{ chargingStationID: chargingStation.id, SiteID: chargingStation.siteID }, chargingStation);
+ chargingStation.canAuthorize = await AuthorizationService.canPerformAuthorizationAction(
+ tenant, userToken, Entity.CHARGING_STATION, Action.AUTHORIZE, authorizationFilter,
+ { chargingStationID: chargingStation.id, SiteID: chargingStation.siteID }, chargingStation);
chargingStation.canUpdate = await AuthorizationService.canPerformAuthorizationAction(
tenant, userToken, Entity.CHARGING_STATION, Action.UPDATE, authorizationFilter,
{ chargingStationID: chargingStation.id, SiteID: chargingStation.siteID }, chargingStation);
@@ -915,7 +918,7 @@ export default class AuthorizationService {
// Remove sensible data
await AuthorizationService.canPerformAuthorizationAction(
tenant, userToken, Entity.CHARGING_STATION, Action.VIEW_USER_DATA, authorizationFilter,
- { chargingStationID: chargingStation.id, UserID: userToken.user.id, SiteID: chargingStation.siteID, UserData: true, TagData: true }, chargingStation);
+ { chargingStationID: chargingStation.id, UserID: userToken.user?.id, SiteID: chargingStation.siteID, UserData: true, TagData: true }, chargingStation);
// Remove properties
Utils.removeCanPropertiesWithFalseValue(chargingStation);
}

MODIFY
src/types/Authorization.ts
src/types/Authorization.ts
@@ -326,6 +326,7 @@ export interface ChargingStationAuthorizationActions extends AuthorizationAction
canGetConnectorQRCode?:boolean;
canPushTransactionCDR?: boolean;
canListCompletedTransactions?: boolean;
+ canAuthorize?: boolean;
}
export interface ConnectorAuthorizationActions extends AuthorizationActions {

Use correct start transaction auth check

- Use correct auth check method
- Fix runtime exception
- Add missing CS auth flag