Add smart charging auth
Can check smart charging connection
Use new auth
MODIFY
src/authorization/AuthorizationsDefinition.ts
src/authorization/AuthorizationsDefinition.ts
@@ -372,6 +372,7 @@ export const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
'id'
]
},
+ { resource: Entity.SMART_CHARGING, action: Action.CHECK_CONNECTION },
{
resource: Entity.USER_SITE, action: [Action.ASSIGN_SITES_TO_USER, Action.UNASSIGN_SITES_FROM_USER, Action.READ, Action.UPDATE, Action.LIST],
condition: {

MODIFY
src/server/rest/v1/service/AuthorizationService.ts
src/server/rest/v1/service/AuthorizationService.ts
@@ -1011,7 +1011,6 @@ export default class AuthorizationService {
}
}
-
public static addTaxAuthorizations(tenant: Tenant, userToken: UserToken, billingTax: BillingTax, authorizationFilter: AuthorizationFilter): void {
billingTax.canRead = true; // Always true as it should be filtered upfront
// Optimize data over the net
@@ -1154,6 +1153,7 @@ export default class AuthorizationService {
setting.canDelete = await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.SETTING, Action.DELETE, authorizationFilter);
setting.canSyncRefund = await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.TRANSACTION, Action.SYNCHRONIZE_REFUNDED_TRANSACTION, authorizationFilter);
setting.canCheckBillingConnection = await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.BILLING, Action.CHECK_CONNECTION, authorizationFilter);
+ setting.canCheckSmartChargingConnection = await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.SMART_CHARGING, Action.CHECK_CONNECTION, authorizationFilter);
// Remove auth flags set to false
Utils.removeCanPropertiesWithFalseValue(setting);
}
@@ -1416,6 +1416,20 @@ export default class AuthorizationService {
return authorizations;
}
+ public static async checkAndGetSmartChargingAuthorizations(tenant: Tenant, userToken: UserToken,
+ authAction: Action, failsWithException = true): Promise<AuthorizationFilter> {
+ const authorizations: AuthorizationFilter = {
+ filters: {},
+ dataSources: new Map(),
+ projectFields: [],
+ authorized: false,
+ };
+ // Check static & dynamic authorization
+ await this.canPerformAuthorizationAction(tenant, userToken, Entity.SMART_CHARGING, authAction,
+ authorizations, {}, null, failsWithException);
+ return authorizations;
+ }
+
private static filterProjectFields(authFields: string[], httpProjectField: string): string[] {
// Init with authorization fields
let applicableProjectedFields = authFields;

MODIFY
src/server/rest/v1/service/ChargingStationService.ts
src/server/rest/v1/service/ChargingStationService.ts
@@ -902,14 +902,7 @@ export default class ChargingStationService {
UtilsService.assertComponentIsActiveFromToken(req.user, TenantComponents.SMART_CHARGING,
Action.CHECK_CONNECTION, Entity.CHARGING_STATION, MODULE_NAME, 'handleCheckSmartChargingConnection');
// Check auth
- if (!await Authorizations.canReadSetting(req.user)) {
- throw new AppAuthError({
- errorCode: HTTPAuthError.FORBIDDEN,
- user: req.user,
- entity: Entity.SETTING, action: Action.UPDATE,
- module: MODULE_NAME, method: 'handleCheckSmartChargingConnection'
- });
- }
+ await AuthorizationService.checkAndGetSmartChargingAuthorizations(req.tenant, req.user, Action.CHECK_CONNECTION);
// Get implementation
const smartCharging = await SmartChargingFactory.getSmartChargingImpl(req.tenant);
if (!smartCharging) {

MODIFY
src/types/Authorization.ts
src/types/Authorization.ts
@@ -111,6 +111,7 @@ export enum Entity {
PAYMENT_METHOD = 'PaymentMethod',
SOURCE = 'Source',
CONSUMPTION = 'Consumption',
+ SMART_CHARGING = 'SmartCharging'
}
export enum Action {
@@ -363,6 +364,7 @@ export interface TransactionAuthorizationActions extends AuthorizationActions {
export interface SettingAuthorizationActions extends AuthorizationActions {
canSyncRefund?: boolean;
canCheckBillingConnection?: boolean;
+ canCheckSmartChargingConnection?: boolean;
}
export enum DynamicAuthorizationFilterName {

Add smart charging auth

- Can check smart charging connection
- Use new auth