Added authorization for Exporting the Logs
MODIFY
src/authorization/AuthorizationsDefinition.ts
src/authorization/AuthorizationsDefinition.ts
@@ -30,7 +30,7 @@ export const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
]
},
{
- resource: Entity.LOGGINGS, action: Action.LIST,
+ resource: Entity.LOGGINGS, action: [Action.LIST, Action.EXPORT],
attributes: [
'id', 'level', 'timestamp', 'type', 'source', 'host', 'action', 'message', 'chargingStationID', 'siteID',
'user.name', 'user.firstName', 'actionOnUser.name', 'actionOnUser.firstName', 'hasDetailedMessages', 'method', 'module',
@@ -224,7 +224,7 @@ export const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
},
{ resource: Entity.REPORT, action: [Action.READ] },
{
- resource: Entity.LOGGINGS, action: Action.LIST,
+ resource: Entity.LOGGINGS, action: [Action.LIST, Action.EXPORT],
attributes: [
'id', 'level', 'timestamp', 'type', 'source', 'host', 'action', 'message', 'chargingStationID', 'siteID',
'user.name', 'user.firstName', 'actionOnUser.name', 'actionOnUser.firstName', 'hasDetailedMessages', 'method', 'module',
@@ -1017,7 +1017,7 @@ export const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
},
{ resource: Entity.REPORT, action: [Action.READ] },
{
- resource: Entity.LOGGINGS, action: Action.LIST,
+ resource: Entity.LOGGINGS, action: [Action.LIST, Action.EXPORT],
condition: {
Fn: 'custom:dynamicAuthorizations',
args: {

MODIFY
src/server/rest/v1/service/AuthorizationService.ts
src/server/rest/v1/service/AuthorizationService.ts
@@ -80,14 +80,12 @@ export default class AuthorizationService {
// Add canCreate flag to root
sites.canCreate = await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.SITE, Action.CREATE,
authorizationFilter);
- // Enrich
for (const site of sites.result) {
await AuthorizationService.addSiteAuthorizations(tenant, userToken, site, authorizationFilter);
}
}
public static async addSiteAuthorizations(tenant: Tenant, userToken: UserToken, site: Site, authorizationFilter: AuthorizationFilter): Promise<void> {
- // Enrich
if (!site.issuer) {
site.canRead = true;
} else {
@@ -113,8 +111,8 @@ export default class AuthorizationService {
}
}
- public static addLogsAuthorizations(tenant: Tenant, userToken: UserToken, logs: LogDataResult, authorizationFilter: AuthorizationFilter): void {
- // Enrich
+ public static async addLogsAuthorizations(tenant: Tenant, userToken: UserToken, logs: LogDataResult, authorizationFilter: AuthorizationFilter): Promise<void> {
+ logs.canExport = await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.LOGGINGS, Action.EXPORT, authorizationFilter);
for (const log of logs.result) {
AuthorizationService.addLogAuthorizations(tenant, userToken, log, authorizationFilter);
}
@@ -233,14 +231,12 @@ export default class AuthorizationService {
users.canExport = await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.USERS, Action.EXPORT, authorizationFilter);
users.canImport = await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.USERS, Action.IMPORT, authorizationFilter);
users.canSynchronizeBilling = await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.USERS, Action.SYNCHRONIZE_BILLING_USERS, authorizationFilter);
- // Enrich
for (const user of users.result) {
await AuthorizationService.addUserAuthorizations(tenant, userToken, user, authorizationFilter);
}
}
public static async addUserAuthorizations(tenant: Tenant, userToken: UserToken, user: User, authorizationFilter: AuthorizationFilter): Promise<void> {
- // Enrich
if (!user.issuer) {
user.canRead = true;
} else {
@@ -323,14 +319,12 @@ export default class AuthorizationService {
tags.canUnassign = await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.TAGS, Action.UNASSIGN, authorizationFilter);
!tags.canUnassign && delete tags.canUnassign; // Optimize data over the net
tags.metadata = authorizationFilter.metadata;
- // Enrich
for (const tag of tags.result) {
await AuthorizationService.addTagAuthorizations(tenant, userToken, tag, authorizationFilter);
}
}
public static async addTagAuthorizations(tenant: Tenant, userToken: UserToken, tag: Tag, authorizationFilter: AuthorizationFilter): Promise<void> {
- // Enrich
if (!tag.issuer) {
tag.canRead = true;
} else {
@@ -371,14 +365,12 @@ export default class AuthorizationService {
// Add canCreate flag to root
companies.canCreate = await AuthorizationService.canPerformAuthorizationAction(
tenant, userToken, Entity.COMPANY, Action.CREATE, authorizationFilter);
- // Enrich
for (const company of companies.result) {
await AuthorizationService.addCompanyAuthorizations(tenant, userToken, company, authorizationFilter);
}
}
public static async addCompanyAuthorizations(tenant: Tenant, userToken: UserToken, company: Company, authorizationFilter: AuthorizationFilter): Promise<void> {
- // Enrich
if (!company.issuer) {
company.canRead = true;
} else {
@@ -422,14 +414,12 @@ export default class AuthorizationService {
authorizationFilter: AuthorizationFilter): Promise<void> {
// Add canCreate flag to root
siteAreas.canCreate = await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.SITE_AREA, Action.CREATE, authorizationFilter);
- // Enrich
for (const siteArea of siteAreas.result) {
await AuthorizationService.addSiteAreaAuthorizations(tenant, userToken, siteArea, authorizationFilter);
}
}
public static async addSiteAreaAuthorizations(tenant: Tenant, userToken: UserToken, siteArea: SiteArea, authorizationFilter: AuthorizationFilter): Promise<void> {
- // Enrich
if (!siteArea.issuer) {
siteArea.canRead = true;
} else {
@@ -511,14 +501,12 @@ export default class AuthorizationService {
public static async addCarsAuthorizations(tenant: Tenant, userToken: UserToken, cars: CarDataResult, authorizationFilter: AuthorizationFilter): Promise<void> {
// Add canCreate flag to root
cars.canCreate = await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.CAR, Action.CREATE, authorizationFilter);
- // Enrich
for (const car of cars.result) {
await AuthorizationService.addCarAuthorizations(tenant, userToken, car, authorizationFilter);
}
}
public static async addCarAuthorizations(tenant: Tenant, userToken: UserToken, car: Car, authorizationFilter: AuthorizationFilter): Promise<void> {
- // Enrich
car.canRead = true; // Always true as it should be filtered upfront
car.canDelete = await AuthorizationService.canPerformAuthorizationAction(
tenant, userToken, Entity.CAR, Action.DELETE, authorizationFilter, { CarID: car.id }, car);
@@ -552,14 +540,12 @@ export default class AuthorizationService {
authorizationFilter: AuthorizationFilter): Promise<void> {
// Add canSync flag to root
carCatalogs.canSync = await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.CAR_CATALOGS, Action.SYNCHRONIZE, authorizationFilter);
- // Enrich
for (const carCatalog of carCatalogs.result) {
await AuthorizationService.addCarCatalogAuthorizations(tenant, userToken, carCatalog, authorizationFilter);
}
}
public static async addCarCatalogAuthorizations(tenant: Tenant, userToken: UserToken, carCatalog: CarCatalog, authorizationFilter: AuthorizationFilter): Promise<void> {
- // Enrich
carCatalog.canRead = true; // Always true as it should be filtered upfront
carCatalog.canDelete = await AuthorizationService.canPerformAuthorizationAction(
tenant, userToken, Entity.CAR_CATALOG, Action.DELETE, authorizationFilter, { CarCatalogID: carCatalog.id }, carCatalog);

MODIFY
src/server/rest/v1/service/LoggingService.ts
src/server/rest/v1/service/LoggingService.ts
@@ -109,7 +109,7 @@ export default class LoggingService {
logs.projectFields = authorizationSitesFilter.projectFields;
}
// Add Auth flags
- AuthorizationService.addLogsAuthorizations(req.tenant, req.user, logs as LogDataResult, authorizationSitesFilter);
+ await AuthorizationService.addLogsAuthorizations(req.tenant, req.user, logs as LogDataResult, authorizationSitesFilter);
return logs;
}
}

MODIFY
src/types/DataResult.ts
src/types/DataResult.ts
@@ -30,7 +30,9 @@ export interface SiteDataResult extends DataResult<Site>{
canUnassignUsers: boolean;
}
-export type LogDataResult = DataResult<Log>;
+export interface LogDataResult extends DataResult<Log>{
+ canExport: boolean;
+}
export interface SiteAreaDataResult extends DataResult<SiteArea> {
canCreate: boolean;

MODIFY
src/types/GlobalType.ts
src/types/GlobalType.ts
@@ -3,6 +3,7 @@ import { Car, CarCatalog } from './Car';
import ChargingStation from './ChargingStation';
import Company from './Company';
import JsonCentralSystemServer from '../server/ocpp/json/JsonCentralSystemServer';
+import { Log } from './Log';
import MongoDBStorage from '../storage/mongodb/MongoDBStorage';
import { ServerType } from './Server';
import Site from './Site';
@@ -69,7 +70,7 @@ export enum ImportStatus {
ERROR = 'E',
}
-export type EntityDataType = Car|User|Company|Site|SiteArea|Tag|CarCatalog|ChargingStation;
+export type EntityDataType = Car|User|Company|Site|SiteArea|Tag|CarCatalog|ChargingStation|Log;
interface TSGlobal extends Global {
database: MongoDBStorage;

Added authorization for Exporting the Logs