Fixed Assets' auth
MODIFY
src/server/rest/v1/service/AssetService.ts
src/server/rest/v1/service/AssetService.ts
@@ -9,6 +9,7 @@ import AssetFactory from '../../../../integration/asset/AssetFactory';
import { AssetInErrorType } from '../../../../types/InError';
import AssetSecurity from './security/AssetSecurity';
import AssetStorage from '../../../../storage/mongodb/AssetStorage';
+import AuthorizationService from './AuthorizationService';
import Authorizations from '../../../../authorization/Authorizations';
import Constants from '../../../../utils/Constants';
import ConsumptionStorage from '../../../../storage/mongodb/ConsumptionStorage';
@@ -351,6 +352,13 @@ export default class AssetService {
}
// Filter
const filteredRequest = AssetSecurity.filterAssetsRequest(req.query);
+ // Get authorization filters
+ const authorizationAssetsFilters = await AuthorizationService.checkAndGetAssetsAuthorizationFilters(
+ req.tenant, req.user, filteredRequest);
+ if (!authorizationAssetsFilters.authorized) {
+ UtilsService.sendEmptyDataResult(res, next);
+ return;
+ }
// Get the assets
const assets = await AssetStorage.getAssets(req.user.tenantID,
{
@@ -360,12 +368,10 @@ export default class AssetService {
withSiteArea: filteredRequest.WithSiteArea,
withNoSiteArea: filteredRequest.WithNoSiteArea,
dynamicOnly: filteredRequest.DynamicOnly,
+ ...authorizationAssetsFilters.filters
},
{ limit: filteredRequest.Limit, skip: filteredRequest.Skip, sort: filteredRequest.SortFields, onlyRecordCount: filteredRequest.OnlyRecordCount },
- [
- 'id', 'name', 'siteAreaID', 'siteArea.id', 'siteArea.name', 'siteArea.siteID', 'siteID', 'assetType', 'coordinates',
- 'dynamicAsset', 'connectionID', 'meterID', 'currentInstantWatts', 'currentStateOfCharge'
- ]
+ authorizationAssetsFilters.projectFields
);
res.json(assets);
next();

MODIFY
src/server/rest/v1/service/AuthService.ts
src/server/rest/v1/service/AuthService.ts
@@ -60,7 +60,7 @@ export default class AuthService {
return passport.authenticate('jwt', { session: false });
}
- public static async checkSessionHash(req: Request, res: Response, next: NextFunction) {
+ public static async checkSessionHash(req: Request, res: Response, next: NextFunction): Promise<void> {
// Check if User has been updated and require new login
if (!await SessionHashService.isSessionHashUpdated(req, res, next)) {
next();

MODIFY
src/server/rest/v1/service/CompanyService.ts
src/server/rest/v1/service/CompanyService.ts
@@ -124,7 +124,8 @@ export default class CompanyService {
// Filter
const filteredRequest = CompanySecurity.filterCompaniesRequest(req.query);
// Check dynamic auth
- const authorizationCompaniesFilter = await AuthorizationService.checkAndGetCompaniesAuthorizationFilters(req.tenant, req.user, filteredRequest);
+ const authorizationCompaniesFilter = await AuthorizationService.checkAndGetCompaniesAuthorizationFilters(
+ req.tenant, req.user, filteredRequest);
if (!authorizationCompaniesFilter.authorized) {
UtilsService.sendEmptyDataResult(res, next);
return;

MODIFY
src/server/rest/v1/service/SiteAreaService.ts
src/server/rest/v1/service/SiteAreaService.ts
@@ -438,7 +438,9 @@ export default class SiteAreaService {
UtilsService.checkIfSiteAreaValid(filteredRequest, req);
// Check and Get Site Area
const siteArea = await UtilsService.checkAndGetSiteAreaAuthorization(
- req.tenant, req.user, filteredRequest.id, 'handleUpdateSiteArea', action, {});
+ req.tenant, req.user, filteredRequest.id, 'handleUpdateSiteArea', action, {
+ withChargingStations: true,
+ });
// Update
siteArea.name = filteredRequest.name;
siteArea.address = filteredRequest.address;

MODIFY
src/server/rest/v1/service/UserService.ts
src/server/rest/v1/service/UserService.ts
@@ -3,7 +3,6 @@ import { ActionsResponse, ImportStatus } from '../../../../types/GlobalType';
import { AsyncTaskType, AsyncTasks } from '../../../../types/AsyncTask';
import { HTTPAuthError, HTTPError } from '../../../../types/HTTPError';
import { NextFunction, Request, Response } from 'express';
-import { OCPITokenType, OCPITokenWhitelist } from '../../../../types/ocpi/OCPIToken';
import User, { ImportedUser, UserRequiredImportProperties, UserStatus } from '../../../../types/User';
import Address from '../../../../types/Address';
@@ -22,7 +21,6 @@ import Constants from '../../../../utils/Constants';
import Cypher from '../../../../utils/Cypher';
import { DataResult } from '../../../../types/DataResult';
import EmspOCPIClient from '../../../../client/ocpi/EmspOCPIClient';
-import I18nManager from '../../../../utils/I18nManager';
import JSONStream from 'JSONStream';
import LockingHelper from '../../../../locking/LockingHelper';
import LockingManager from '../../../../locking/LockingManager';
@@ -30,6 +28,7 @@ import Logging from '../../../../utils/Logging';
import NotificationHandler from '../../../../notification/NotificationHandler';
import OCPIClientFactory from '../../../../client/ocpi/OCPIClientFactory';
import { OCPIRole } from '../../../../types/ocpi/OCPIRole';
+import { OCPITokenWhitelist } from '../../../../types/ocpi/OCPIToken';
import OCPIUtils from '../../../ocpi/OCPIUtils';
import { ServerAction } from '../../../../types/Server';
import SettingStorage from '../../../../storage/mongodb/SettingStorage';

Fixed Assets' auth