Fixed NPE on projected fields + Generalize projected field in Authorization
MODIFY
src/server/rest/v1/service/AuthorizationService.ts
src/server/rest/v1/service/AuthorizationService.ts
@@ -103,6 +103,10 @@ export default class AuthorizationService {
site.canUnassignUsers = await AuthorizationService.canPerformAuthorizationAction(
tenant, userToken, Entity.USERS_SITES, Action.UNASSIGN, authorizationFilter, { SiteID: site.id }, site);
}
+ // Assign projected fields
+ if (authorizationFilter.projectFields) {
+ site.projectedFields = authorizationFilter.projectFields;
+ }
}
public static async checkAndGetSitesAuthorizations(tenant: Tenant, userToken: UserToken,
@@ -260,6 +264,10 @@ export default class AuthorizationService {
user.canDelete = await AuthorizationService.canPerformAuthorizationAction(
tenant, userToken, Entity.USER, Action.DELETE, authorizationFilter, { UserID: user.id }, user);
}
+ // Assign projected fields
+ if (authorizationFilter.projectFields) {
+ user.projectedFields = authorizationFilter.projectFields;
+ }
}
public static async checkAndGetUsersAuthorizations(tenant: Tenant, userToken: UserToken,
@@ -350,6 +358,10 @@ export default class AuthorizationService {
tag.canAssign = await AuthorizationService.canPerformAuthorizationAction(
tenant, userToken, Entity.TAG, Action.ASSIGN, authorizationFilter, { TagID: tag.id }, tag);
}
+ // Assign projected fields
+ if (authorizationFilter.projectFields) {
+ tag.projectedFields = authorizationFilter.projectFields;
+ }
}
public static async checkAndGetCompaniesAuthorizations(tenant: Tenant, userToken: UserToken,
@@ -390,6 +402,10 @@ export default class AuthorizationService {
company.canUpdate = await AuthorizationService.canPerformAuthorizationAction(
tenant, userToken, Entity.COMPANY, Action.UPDATE, authorizationFilter, { CompanyID: company.id }, company);
}
+ // Assign projected fields
+ if (authorizationFilter.projectFields) {
+ company.projectedFields = authorizationFilter.projectFields;
+ }
}
public static async checkAndGetCompanyAuthorizations(tenant: Tenant, userToken: UserToken,
@@ -459,6 +475,10 @@ export default class AuthorizationService {
siteArea.canGenerateQrCode = await AuthorizationService.canPerformAuthorizationAction(
tenant, userToken, Entity.SITE_AREA, Action.GENERATE_QR, authorizationFilter, { SiteAreaID: siteArea.id, SiteID: siteArea.siteID }, siteArea);
}
+ // Assign projected fields
+ if (authorizationFilter.projectFields) {
+ siteArea.projectedFields = authorizationFilter.projectFields;
+ }
}
public static async checkAndGetChargingStationAuthorizations(tenant: Tenant, userToken: UserToken,
@@ -518,17 +538,15 @@ export default class AuthorizationService {
public static async addCarAuthorizations(tenant: Tenant, userToken: UserToken, car: Car, authorizationFilter: AuthorizationFilter): Promise<void> {
// Enrich
- if (!car) {
- car.canRead = true;
- car.canUpdate = false;
- car.canDelete = false;
- } else {
car.canRead = await AuthorizationService.canPerformAuthorizationAction(
tenant, userToken, Entity.CAR, Action.READ, authorizationFilter, { CarID: car.id }, car);
car.canDelete = await AuthorizationService.canPerformAuthorizationAction(
tenant, userToken, Entity.CAR, Action.DELETE, authorizationFilter, { CarID: car.id }, car);
car.canUpdate = await AuthorizationService.canPerformAuthorizationAction(
tenant, userToken, Entity.CAR, Action.UPDATE, authorizationFilter, { CarID: car.id }, car);
+ // Assign projected fields
+ if (authorizationFilter.projectFields) {
+ car.projectedFields = authorizationFilter.projectFields;
}
}
@@ -564,17 +582,15 @@ export default class AuthorizationService {
public static async addCarCatalogAuthorizations(tenant: Tenant, userToken: UserToken, carCatalog: CarCatalog, authorizationFilter: AuthorizationFilter): Promise<void> {
// Enrich
- if (!carCatalog) {
- carCatalog.canRead = true;
- carCatalog.canUpdate = false;
- carCatalog.canDelete = false;
- } else {
carCatalog.canRead = await AuthorizationService.canPerformAuthorizationAction(
tenant, userToken, Entity.CAR_CATALOG, Action.READ, authorizationFilter, { CarCatalogID: carCatalog.id }, carCatalog);
carCatalog.canDelete = await AuthorizationService.canPerformAuthorizationAction(
tenant, userToken, Entity.CAR_CATALOG, Action.DELETE, authorizationFilter, { CarCatalogID: carCatalog.id }, carCatalog);
carCatalog.canUpdate = await AuthorizationService.canPerformAuthorizationAction(
tenant, userToken, Entity.CAR_CATALOG, Action.UPDATE, authorizationFilter, { CarCatalogID: carCatalog.id }, carCatalog);
+ // Assign projected fields
+ if (authorizationFilter.projectFields) {
+ carCatalog.projectedFields = authorizationFilter.projectFields;
}
}

MODIFY
src/server/rest/v1/service/UtilsService.ts
src/server/rest/v1/service/UtilsService.ts
@@ -181,9 +181,6 @@ export default class UtilsService {
},
applyProjectFields ? authorizationFilter.projectFields : null
);
- if (authorizationFilter.projectFields) {
- user.projectedFields = authorizationFilter.projectFields;
- }
UtilsService.assertObjectExists(action, user, `User ID '${userID}' does not exist`,
MODULE_NAME, 'checkAndGetUserAuthorization', userToken);
// External User

MODIFY
src/types/Authorization.ts
src/types/Authorization.ts
@@ -185,6 +185,7 @@ export interface AuthorizationActions {
canCreate?: boolean;
canUpdate?: boolean;
canDelete?: boolean;
+ projectedFields?: string[];
}
export interface TagAuthorizationActions extends AuthorizationActions {

MODIFY
src/types/ChargingStation.ts
src/types/ChargingStation.ts
import { ChargePointStatus, OCPPFirmwareStatus, OCPPPhase, OCPPProtocol, OCPPVersion, RegistrationStatus } from './ocpp/OCPPServer';
+import { AuthorizationActions } from './Authorization';
import { ChargingRateUnitType } from './ChargingProfile';
import CreatedUpdatedProps from './CreatedUpdatedProps';
import { InactivityStatus } from './Transaction';
@@ -11,7 +12,7 @@ import Site from './Site';
import SiteArea from './SiteArea';
import User from './User';
-export default interface ChargingStation extends CreatedUpdatedProps {
+export default interface ChargingStation extends CreatedUpdatedProps, AuthorizationActions {
id?: string;
templateHash?: string;
templateHashCapabilities?: string;

MODIFY
src/types/User.ts
src/types/User.ts
@@ -42,7 +42,6 @@ export default interface User extends CreatedUpdatedProps, AuthorizationActions
autoActivateUserAtImport: boolean;
};
technical: boolean;
- projectedFields: string[];
}
export interface UserSite {

Fixed NPE on projected fields + Generalize projected field in Authorization