Add canSync on /CarCatalogs response root
MODIFY
src/server/rest/v1/service/AuthorizationService.ts
src/server/rest/v1/service/AuthorizationService.ts
import { Action, AuthorizationActions, AuthorizationContext, AuthorizationFilter, Entity } from '../../../../types/Authorization';
-import { CarDataResult, CompanyDataResult, SiteAreaDataResult, SiteDataResult } from '../../../../types/DataResult';
+import { Car, CarCatalog } from '../../../../types/Car';
+import { CarCatalogDataResult, CarDataResult, CompanyDataResult, DataResult, SiteAreaDataResult, SiteDataResult } from '../../../../types/DataResult';
import { HttpAssignAssetsToSiteAreaRequest, HttpAssignChargingStationToSiteAreaRequest, HttpSiteAreaRequest, HttpSiteAreasRequest } from '../../../../types/requests/HttpSiteAreaRequest';
import { HttpCarCatalogsRequest, HttpCarsRequest } from '../../../../types/requests/HttpCarRequest';
import { HttpCompaniesRequest, HttpCompanyRequest } from '../../../../types/requests/HttpCompanyRequest';
@@ -10,7 +11,6 @@ import User, { UserRole } from '../../../../types/User';
import AppAuthError from '../../../../exception/AppAuthError';
import AssetStorage from '../../../../storage/mongodb/AssetStorage';
import Authorizations from '../../../../authorization/Authorizations';
-import { Car } from '../../../../types/Car';
import ChargingStationStorage from '../../../../storage/mongodb/ChargingStationStorage';
import Company from '../../../../types/Company';
import Constants from '../../../../utils/Constants';
@@ -748,6 +748,13 @@ export default class AuthorizationService {
return authorizationFilters;
}
+ public static async addCarCatalogsAuthorizationActions(tenant: Tenant, userToken: UserToken, carCatalogs: CarCatalogDataResult,
+ authorizationFilter: AuthorizationFilter): Promise<void> {
+ // Add canSync flag to root
+ carCatalogs.canSync = await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.CAR_CATALOGS, Action.SYNCHRONIZE,
+ authorizationFilter);
+ }
+
public static async getSiteAdminSiteIDs(tenantID: string, userToken: UserToken): Promise<string[]> {
// Get the Sites where the user is Site Admin
const userSites = await UserStorage.getUserSites(tenantID,

MODIFY
src/server/rest/v1/service/CarService.ts
src/server/rest/v1/service/CarService.ts
import { Action, Entity } from '../../../../types/Authorization';
import { AsyncTaskType, AsyncTasks } from '../../../../types/AsyncTask';
import { Car, CarType } from '../../../../types/Car';
+import { CarCatalogDataResult, CarDataResult } from '../../../../types/DataResult';
import { HTTPAuthError, HTTPError } from '../../../../types/HTTPError';
import { NextFunction, Request, Response } from 'express';
@@ -9,7 +10,6 @@ import AppError from '../../../../exception/AppError';
import AsyncTaskManager from '../../../../async-task/AsyncTaskManager';
import AuthorizationService from './AuthorizationService';
import Authorizations from '../../../../authorization/Authorizations';
-import { CarDataResult } from '../../../../types/DataResult';
import CarSecurity from './security/CarSecurity';
import CarStorage from '../../../../storage/mongodb/CarStorage';
import Constants from '../../../../utils/Constants';
@@ -54,6 +54,9 @@ export default class CarService {
},
authorizationCarCatalogsFilter.projectFields
);
+ // Add Auth flags
+ await AuthorizationService.addCarCatalogsAuthorizationActions(req.tenant, req.user, carCatalogs as CarCatalogDataResult,
+ authorizationCarCatalogsFilter);
// Return
res.json(carCatalogs);
next();

MODIFY
src/types/DataResult.ts
src/types/DataResult.ts
-import { Car } from './Car';
+import { Car, CarCatalog } from './Car';
+
import Company from './Company';
import Site from './Site';
import SiteArea from './SiteArea';
@@ -25,6 +26,9 @@ export interface CarDataResult extends DataResult<Car>{
canCreate: boolean;
}
+export interface CarCatalogDataResult extends DataResult<CarCatalog>{
+ canSync: boolean;
+}
export interface TransactionDataResult {
count: number;
result: Transaction[];

Add canSync on /CarCatalogs response root