Small changes for updateSiteArea.
MODIFY
src/server/rest/v1/service/AuthorizationService.ts
src/server/rest/v1/service/AuthorizationService.ts
@@ -590,6 +590,7 @@ export default class AuthorizationService {
siteArea.canDelete = false;
} else {
filteredRequest.SiteAreaID = siteArea.id;
+ filteredRequest.SiteID = siteArea.siteID;
siteArea.canRead = await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.SITE_AREA, Action.READ, authorizationFilter, filteredRequest);
siteArea.canUpdate = await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.SITE_AREA, Action.DELETE, authorizationFilter, filteredRequest);
siteArea.canDelete = await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.SITE_AREA, Action.UPDATE, authorizationFilter, filteredRequest);

MODIFY
src/server/rest/v1/service/SiteAreaService.ts
src/server/rest/v1/service/SiteAreaService.ts
@@ -6,7 +6,6 @@ import { ActionsResponse } from '../../../../types/GlobalType';
import AppAuthError from '../../../../exception/AppAuthError';
import AppError from '../../../../exception/AppError';
import AuthorizationService from './AuthorizationService';
-import Authorizations from '../../../../authorization/Authorizations';
import { ChargingProfilePurposeType } from '../../../../types/ChargingProfile';
import Constants from '../../../../utils/Constants';
import ConsumptionStorage from '../../../../storage/mongodb/ConsumptionStorage';
@@ -338,6 +337,9 @@ export default class SiteAreaService {
const filteredRequest = SiteAreaSecurity.filterSiteAreaUpdateRequest(req.body);
// Check Mandatory fields
UtilsService.checkIfSiteAreaValid(filteredRequest, req);
+ // Check Site auth
+ await UtilsService.checkAndGetSiteAuthorization(
+ req.tenant, req.user, filteredRequest.siteID, Action.READ, action, {});
// Check and Get SiteArea
const siteArea = await UtilsService.checkAndGetSiteAreaAuthorization(
req.tenant, req.user, filteredRequest.id, Action.UPDATE, action, {
@@ -380,7 +382,7 @@ export default class SiteAreaService {
siteArea.siteID = filteredRequest.siteID;
siteArea.lastChangedBy = { 'id': req.user.id };
siteArea.lastChangedOn = new Date();
- // Update Site Area
+ // Save
await SiteAreaStorage.saveSiteArea(req.user.tenantID, siteArea, Utils.objectHasProperty(filteredRequest, 'image'));
// Retrigger Smart Charging
if (filteredRequest.smartCharging) {

MODIFY
src/types/Authorization.ts
src/types/Authorization.ts
@@ -179,12 +179,14 @@ export enum DynamicAuthorizationFilterName {
ASSIGNED_SITES_COMPANIES = 'AssignedSitesCompanies',
SITES_ADMIN = 'SitesAdmin',
ASSIGNED_SITE_AREAS = 'AssignedSiteAreas',
+ SITE_ADMIN_SITE_AREAS = 'SiteAdminSiteAreas',
}
export enum DynamicAuthorizationDataSourceName {
ASSIGNED_SITES_COMPANIES = 'AssignedSitesCompanies',
SITES_ADMIN = 'SitesAdmin',
ASSIGNED_SITE_AREAS = 'AssignedSiteAreas',
+ SITE_ADMIN_SITE_AREAS = 'SiteAdminSiteAreas',
}
export interface DynamicAuthorizationDataSourceData {}
@@ -200,3 +202,6 @@ export interface SitesAdminDynamicAuthorizationDataSourceData extends DynamicAut
export interface AssignedSiteAreasDynamicAuthorizationDataSourceData extends DynamicAuthorizationDataSourceData {
siteAreaIDs?: string[];
}
+export interface SiteAdminSiteAreasDynamicAuthorizationDataSourceData extends DynamicAuthorizationDataSourceData {
+ siteAreaIDs?: string[];
+}

Small changes for updateSiteArea.