get Site ID to check permission of basic user on site Area
MODIFY
src/server/rest/v1/service/SiteAreaService.ts
src/server/rest/v1/service/SiteAreaService.ts
@@ -269,8 +269,13 @@ export default class SiteAreaService {
const filteredRequest = SiteAreaSecurity.filterSiteAreaRequest(req.query);
// ID is mandatory
UtilsService.assertIdIsProvided(action, filteredRequest.ID, MODULE_NAME, 'handleGetSiteArea', req.user);
+ // Get it
+ const siteArea = await SiteAreaStorage.getSiteArea(req.user.tenantID, filteredRequest.ID,
+ { withSite: filteredRequest.WithSite, withChargingStations: filteredRequest.WithChargingStations });
+ UtilsService.assertObjectExists(action, siteArea, `Site Area with ID '${filteredRequest.ID}' does not exist`,
+ MODULE_NAME, 'handleGetSiteArea', req.user);
// Check auth
- if (!Authorizations.canReadSiteArea(req.user, filteredRequest.ID)) {
+ if (!Authorizations.canReadSiteArea(req.user, siteArea.siteID)) {
throw new AppAuthError({
errorCode: HTTPAuthError.ERROR,
user: req.user,
@@ -279,11 +284,6 @@ export default class SiteAreaService {
value: filteredRequest.ID
});
}
- // Get it
- const siteArea = await SiteAreaStorage.getSiteArea(req.user.tenantID, filteredRequest.ID,
- { withSite: filteredRequest.WithSite, withChargingStations: filteredRequest.WithChargingStations });
- UtilsService.assertObjectExists(action, siteArea, `Site Area with ID '${filteredRequest.ID}' does not exist`,
- MODULE_NAME, 'handleGetSiteArea', req.user);
// Return
res.json(
// Filter
@@ -299,8 +299,10 @@ export default class SiteAreaService {
// Filter
const siteAreaID = SiteAreaSecurity.filterSiteAreaRequestByID(req.query);
UtilsService.assertIdIsProvided(action, siteAreaID, MODULE_NAME, 'handleGetSiteAreaImage', req.user);
+ // Get it
+ const siteArea = await SiteAreaStorage.getSiteArea(req.user.tenantID, siteAreaID);
// Check auth
- if (!Authorizations.canReadSiteArea(req.user, siteAreaID)) {
+ if (!Authorizations.canReadSiteArea(req.user, siteArea.siteID)) {
throw new AppAuthError({
errorCode: HTTPAuthError.ERROR,
user: req.user,
@@ -309,8 +311,6 @@ export default class SiteAreaService {
value: siteAreaID
});
}
- // Get it
- const siteArea = await SiteAreaStorage.getSiteArea(req.user.tenantID, siteAreaID);
UtilsService.assertObjectExists(action, siteArea, `Site Area with ID '${siteAreaID}' does not exist`,
MODULE_NAME, 'handleGetSiteAreaImage', req.user);
// Get it

get Site ID to check permission of basic user on site Area