Fixed Site Area / Site coordinates
MODIFY
src/server/rest/service/security/SiteAreaSecurity.ts
src/server/rest/service/security/SiteAreaSecurity.ts
@@ -93,9 +93,13 @@ export default class SiteAreaSecurity {
filteredSiteArea.numberOfPhases = siteArea.numberOfPhases;
filteredSiteArea.smartCharging = siteArea.smartCharging;
filteredSiteArea.accessControl = siteArea.accessControl;
- if (!forList && Utils.objectHasProperty(siteArea, 'address')) {
+ if (Utils.objectHasProperty(siteArea, 'address')) {
+ if (forList) {
+ filteredSiteArea.address = UtilsSecurity.filterAddressCoordinatesRequest(siteArea.address);
+ } else {
filteredSiteArea.address = UtilsSecurity.filterAddressRequest(siteArea.address);
}
+ }
if (siteArea.connectorStats) {
filteredSiteArea.connectorStats = siteArea.connectorStats;
}

MODIFY
src/server/rest/service/security/SiteSecurity.ts
src/server/rest/service/security/SiteSecurity.ts
-import { HttpSiteAssignUsersRequest, HttpSiteOwnerRequest, HttpSiteRequest, HttpSiteUserAdminRequest, HttpSiteUsersRequest, HttpSitesRequest } from '../../../../types/requests/HttpSiteRequest';
-
+import sanitize from 'mongo-sanitize';
import Authorizations from '../../../../authorization/Authorizations';
-import CompanySecurity from './CompanySecurity';
import { DataResult } from '../../../../types/DataResult';
+import { HttpSiteAssignUsersRequest, HttpSiteOwnerRequest, HttpSiteRequest, HttpSiteUserAdminRequest, HttpSiteUsersRequest, HttpSitesRequest } from '../../../../types/requests/HttpSiteRequest';
import Site from '../../../../types/Site';
-import SiteAreaSecurity from './SiteAreaSecurity';
import UserToken from '../../../../types/UserToken';
+import Utils from '../../../../utils/Utils';
+import CompanySecurity from './CompanySecurity';
+import SiteAreaSecurity from './SiteAreaSecurity';
import UtilsSecurity from './UtilsSecurity';
-import sanitize from 'mongo-sanitize';
+
export default class SiteSecurity {
public static filterUpdateSiteUserAdminRequest(request: any): HttpSiteUserAdminRequest {
@@ -100,7 +101,6 @@ export default class SiteSecurity {
static filterSiteResponse(site: Site, loggedUser: UserToken, forList = false): Site {
let filteredSite;
-
if (!site) {
return null;
}
@@ -113,9 +113,13 @@ export default class SiteSecurity {
filteredSite.companyID = site.companyID;
filteredSite.autoUserSiteAssignment = site.autoUserSiteAssignment;
filteredSite.issuer = site.issuer;
- if (!forList && site.address) {
+ if (Utils.objectHasProperty(site, 'address')) {
+ if (forList) {
+ filteredSite.address = UtilsSecurity.filterAddressCoordinatesRequest(site.address);
+ } else {
filteredSite.address = UtilsSecurity.filterAddressRequest(site.address);
}
+ }
if (site.company) {
filteredSite.company = CompanySecurity.filterCompanyResponse(site.company, loggedUser);
}

MODIFY
src/server/rest/service/security/UtilsSecurity.ts
src/server/rest/service/security/UtilsSecurity.ts
@@ -124,6 +124,19 @@ export default class UtilsSecurity {
return filteredAddress;
}
+ static filterAddressCoordinatesRequest(address: Address): Address {
+ const filteredAddress: Address = {} as Address;
+ if (address) {
+ if (address.coordinates && address.coordinates.length === 2) {
+ filteredAddress.coordinates = [
+ sanitize(address.coordinates[0]),
+ sanitize(address.coordinates[1])
+ ];
+ }
+ }
+ return filteredAddress;
+ }
+
static filterCreatedAndLastChanged(filteredEntity: any, entity: any, loggedUser: UserToken): void {
if (entity.createdBy && typeof entity.createdBy === 'object' &&
entity.createdBy.id && Authorizations.canReadUser(loggedUser, entity.createdBy.id)) {

Fixed Site Area / Site coordinates