Update for ChargingStations.
MODIFY
src/authorization/Authorizations.ts
src/authorization/Authorizations.ts
@@ -98,7 +98,7 @@ export default class Authorizations {
return requestedSites;
}
if (Utils.isEmptyArray(requestedSites)) {
- return loggedUser.sites.length > 0 ? loggedUser.sites : [null];
+ return loggedUser.sites.length > 0 ? loggedUser.sites : null;
}
return requestedSites.filter((site) => loggedUser.sites.includes(site));
}

MODIFY
src/authorization/AuthorizationsDefinition.ts
src/authorization/AuthorizationsDefinition.ts
@@ -283,7 +283,7 @@ const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
resource: Entity.SITE_AREAS, action: Action.LIST,
condition: {
Fn: 'custom:dynamicAuthorizationFilters',
- args: { filters: ['AssignedSiteAreas'] }
+ args: { filters: ['AssignedSites'] }
},
attributes: [
'id', 'name', 'siteID', 'maximumPower', 'voltage', 'numberOfPhases', 'accessControl', 'smartCharging', 'address',
@@ -294,7 +294,7 @@ const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
resource: Entity.SITE_AREA, action: Action.READ,
condition: {
Fn: 'custom:dynamicAuthorizationFilters',
- args: { filters: ['AssignedSiteAreas'] }
+ args: { filters: ['AssignedSites'] }
},
attributes: [
'id', 'name', 'issuer', 'image', 'address', 'maximumPower', 'numberOfPhases',

MODIFY
src/server/rest/v1/service/ChargingStationService.ts
src/server/rest/v1/service/ChargingStationService.ts
@@ -1422,6 +1422,11 @@ export default class ChargingStationService {
if (!Utils.isEmptyArray(httpProjectFields)) {
projectFields = projectFields.filter((projectField) => httpProjectFields.includes(projectField));
}
+ const siteIDs = Authorizations.getAuthorizedSiteIDs(req.user, filteredRequest.SiteID ? filteredRequest.SiteID.split('|') : null);
+ // todo: write this in a nicer way when refactoring the whole auth concept for ChargingStation
+ if (Utils.isEmptyArray(siteIDs) && !Authorizations.isAdmin(req.user)) {
+ return { count: 0, result: [] };
+ }
// Get Charging Stations
const chargingStations = await ChargingStationStorage.getChargingStations(req.user.tenantID,
{
@@ -1432,7 +1437,7 @@ export default class ChargingStationService {
connectorStatuses: filteredRequest.ConnectorStatus ? filteredRequest.ConnectorStatus.split('|') : null,
connectorTypes: filteredRequest.ConnectorType ? filteredRequest.ConnectorType.split('|') : null,
issuer: filteredRequest.Issuer,
- siteIDs: Authorizations.getAuthorizedSiteIDs(req.user, filteredRequest.SiteID ? filteredRequest.SiteID.split('|') : null),
+ siteIDs: siteIDs,
siteAreaIDs: filteredRequest.SiteAreaID ? filteredRequest.SiteAreaID.split('|') : null,
includeDeleted: filteredRequest.IncludeDeleted,
locCoordinates: filteredRequest.LocCoordinates,

Update for ChargingStations.