Add In Error auths
MODIFY
src/authorization/Authorizations.ts
src/authorization/Authorizations.ts
@@ -220,7 +220,7 @@ export default class Authorizations {
}
public static canListTransactionsInError(loggedUser: UserToken): boolean {
- return Authorizations.canPerformAction(loggedUser, Entity.TRANSACTIONS, Action.LIST);
+ return Authorizations.canPerformAction(loggedUser, Entity.TRANSACTIONS, Action.IN_ERROR);
}
public static canReadTransaction(loggedUser: UserToken, transaction: Transaction): boolean {
@@ -256,6 +256,10 @@ export default class Authorizations {
return Authorizations.canPerformAction(loggedUser, Entity.CHARGING_STATIONS, Action.LIST);
}
+ public static canListChargingStationsInError(loggedUser: UserToken): boolean {
+ return Authorizations.canPerformAction(loggedUser, Entity.CHARGING_STATIONS, Action.IN_ERROR);
+ }
+
public static canPerformActionOnChargingStation(loggedUser: UserToken, action: Action, chargingStation: ChargingStation, context?: AuthorizationContext): boolean {
if (!context) {
const isOrgCompActive = Utils.isComponentActiveFromToken(loggedUser, TenantComponents.ORGANIZATION);
@@ -289,7 +293,7 @@ export default class Authorizations {
}
public static canExportParams(loggedUser: UserToken, siteID: string): boolean {
- return Authorizations.canPerformAction(loggedUser, Entity.CHARGING_STATION, Action.EXPORT_PARAMS, {
+ return Authorizations.canPerformAction(loggedUser, Entity.CHARGING_STATION, Action.EXPORT, {
site: siteID,
sitesAdmin: loggedUser.sitesAdmin
});
@@ -312,6 +316,10 @@ export default class Authorizations {
return Authorizations.canPerformAction(loggedUser, Entity.USERS, Action.LIST);
}
+ public static canListUsersInErrors(loggedUser: UserToken): boolean {
+ return Authorizations.canPerformAction(loggedUser, Entity.USERS, Action.IN_ERROR);
+ }
+
public static canListTags(loggedUser: UserToken): boolean {
return Authorizations.canPerformAction(loggedUser, Entity.TAGS, Action.LIST);
}
@@ -562,6 +570,10 @@ export default class Authorizations {
return Authorizations.canPerformAction(loggedUser, Entity.ASSETS, Action.LIST);
}
+ public static canListAssetsInError(loggedUser: UserToken): boolean {
+ return Authorizations.canPerformAction(loggedUser, Entity.ASSETS, Action.IN_ERROR);
+ }
+
public static canReadAsset(loggedUser: UserToken): boolean {
return Authorizations.canPerformAction(loggedUser, Entity.ASSET, Action.READ);
}

MODIFY
src/authorization/AuthorizationsDefinition.ts
src/authorization/AuthorizationsDefinition.ts
@@ -25,7 +25,7 @@ const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
},
admin: {
grants: [
- { resource: Entity.USERS, action: [Action.LIST, Action.SYNCHRONIZE_BILLING_USERS], attributes: ['*'] },
+ { resource: Entity.USERS, action: [Action.LIST, Action.SYNCHRONIZE_BILLING_USERS, Action.EXPORT, Action.IN_ERROR], attributes: ['*'] },
{ resource: Entity.USER, action: [Action.CREATE, Action.READ, Action.UPDATE, Action.SYNCHRONIZE_BILLING_USER], attributes: ['*'] },
{
resource: Entity.USER, action: Action.DELETE, attributes: ['*'],
@@ -41,16 +41,16 @@ const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
{ resource: Entity.SITE, action: [Action.CREATE, Action.READ, Action.UPDATE, Action.DELETE], attributes: ['*'] },
{ resource: Entity.SITE_AREAS, action: Action.LIST, attributes: ['*'] },
{ resource: Entity.SITE_AREA, action: [Action.CREATE, Action.READ, Action.UPDATE, Action.DELETE], attributes: ['*'] },
- { resource: Entity.CHARGING_STATIONS, action: Action.LIST, attributes: ['*'] },
+ { resource: Entity.CHARGING_STATIONS, action: [Action.LIST, Action.IN_ERROR], attributes: ['*'] },
{
resource: Entity.CHARGING_STATION, action: [Action.CREATE, Action.READ, Action.UPDATE, Action.DELETE,
Action.RESET, Action.CLEAR_CACHE, Action.GET_CONFIGURATION, Action.CHANGE_CONFIGURATION,
Action.REMOTE_START_TRANSACTION, Action.REMOTE_STOP_TRANSACTION, Action.STOP_TRANSACTION, Action.START_TRANSACTION,
Action.UNLOCK_CONNECTOR, Action.AUTHORIZE, Action.SET_CHARGING_PROFILE, Action.GET_COMPOSITE_SCHEDULE,
- Action.CLEAR_CHARGING_PROFILE, Action.GET_DIAGNOSTICS, Action.UPDATE_FIRMWARE, Action.EXPORT_PARAMS,
+ Action.CLEAR_CHARGING_PROFILE, Action.GET_DIAGNOSTICS, Action.UPDATE_FIRMWARE, Action.EXPORT,
Action.CHANGE_AVAILABILITY], attributes: ['*']
},
- { resource: Entity.TRANSACTIONS, action: Action.LIST, attributes: ['*'] },
+ { resource: Entity.TRANSACTIONS, action: [Action.LIST, Action.EXPORT, Action.IN_ERROR], attributes: ['*'] },
{
resource: Entity.TRANSACTION,
action: [Action.READ, Action.UPDATE, Action.DELETE],
@@ -70,7 +70,7 @@ const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
resource: Entity.ASSET, action: [Action.CREATE, Action.READ, Action.UPDATE, Action.DELETE,
Action.CHECK_CONNECTION, Action.RETRIEVE_CONSUMPTION], attributes: ['*']
},
- { resource: Entity.ASSETS, action: Action.LIST, attributes: ['*'] },
+ { resource: Entity.ASSETS, action: [Action.LIST, Action.IN_ERROR], attributes: ['*'] },
{ resource: Entity.SETTINGS, action: Action.LIST, attributes: ['*'] },
{ resource: Entity.SETTING, action: [Action.CREATE, Action.READ, Action.UPDATE, Action.DELETE], attributes: ['*'] },
{ resource: Entity.TOKENS, action: Action.LIST, attributes: ['*'] },
@@ -267,7 +267,7 @@ const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
action: [Action.UPDATE, Action.DELETE, Action.RESET, Action.CLEAR_CACHE, Action.GET_CONFIGURATION,
Action.CHANGE_CONFIGURATION, Action.SET_CHARGING_PROFILE, Action.GET_COMPOSITE_SCHEDULE,
Action.CLEAR_CHARGING_PROFILE, Action.GET_DIAGNOSTICS, Action.UPDATE_FIRMWARE, Action.REMOTE_STOP_TRANSACTION,
- Action.STOP_TRANSACTION, Action.EXPORT_PARAMS, Action.CHANGE_AVAILABILITY],
+ Action.STOP_TRANSACTION, Action.EXPORT, Action.CHANGE_AVAILABILITY],
attributes: ['*'],
condition: { Fn: 'LIST_CONTAINS', args: { 'sitesAdmin': '$.site' } }
},

MODIFY
src/server/rest/v1/service/AssetService.ts
src/server/rest/v1/service/AssetService.ts
@@ -204,11 +204,11 @@ export default class AssetService {
UtilsService.assertComponentIsActiveFromToken(req.user, TenantComponents.ASSET,
Action.LIST, Entity.ASSETS, MODULE_NAME, 'handleGetAssetsInError');
// Check auth
- if (!Authorizations.canListAssets(req.user)) {
+ if (!Authorizations.canListAssetsInError(req.user)) {
throw new AppAuthError({
errorCode: HTTPAuthError.ERROR,
user: req.user,
- action: Action.LIST, entity: Entity.ASSETS,
+ action: Action.IN_ERROR, entity: Entity.ASSETS,
module: MODULE_NAME, method: 'handleGetAssetsInError'
});
}

MODIFY
src/server/rest/v1/service/AuthorizationService.ts
src/server/rest/v1/service/AuthorizationService.ts
@@ -204,6 +204,19 @@ export default class AuthorizationService {
return authorizationFilters;
}
+ public static async getUsersInErrorAuthorizationFilters(filteredRequest: HttpUsersRequest, user: UserToken, tenant: Tenant): Promise<AuthorizationFilter> {
+ const authorizationFilters: AuthorizationFilter = {
+ filters: {},
+ project: [
+ 'id', 'name', 'firstName', 'email', 'role', 'status', 'issuer',
+ 'createdOn', 'lastChangedOn', 'errorCodeDetails', 'errorCode'
+ ]
+ };
+ // Get from users
+ authorizationFilters.filters = await AuthorizationService.getUsersAuthorizationFilters(filteredRequest, user, tenant);
+ return authorizationFilters;
+ }
+
public static async getUsersAuthorizationFilters(filteredRequest: HttpUsersRequest, user: UserToken, tenant: Tenant): Promise<AuthorizationFilter> {
const authorizationFilters: AuthorizationFilter = {
filters: {},

MODIFY
src/server/rest/v1/service/ChargingStationService.ts
src/server/rest/v1/service/ChargingStationService.ts
@@ -805,7 +805,7 @@ export default class ChargingStationService {
throw new AppAuthError({
errorCode: HTTPAuthError.ERROR,
user: req.user,
- action: Action.EXPORT_PARAMS,
+ action: Action.EXPORT,
entity: Entity.CHARGING_STATION,
module: MODULE_NAME,
method: 'handleExportChargingStationsOCPPParams',
@@ -861,11 +861,11 @@ export default class ChargingStationService {
public static async handleGetChargingStationsInError(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Check auth
- if (!Authorizations.canListChargingStations(req.user)) {
+ if (!Authorizations.canListChargingStationsInError(req.user)) {
throw new AppAuthError({
errorCode: HTTPAuthError.ERROR,
user: req.user,
- action: Action.LIST, entity: Entity.CHARGING_STATIONS,
+ action: Action.IN_ERROR, entity: Entity.CHARGING_STATIONS,
module: MODULE_NAME, method: 'handleGetChargingStations'
});
}

MODIFY
src/server/rest/v1/service/TransactionService.ts
src/server/rest/v1/service/TransactionService.ts
@@ -783,7 +783,7 @@ export default class TransactionService {
throw new AppAuthError({
errorCode: HTTPAuthError.ERROR,
user: req.user,
- action: Action.LIST, entity: Entity.TRANSACTIONS,
+ action: Action.IN_ERROR, entity: Entity.TRANSACTIONS,
module: MODULE_NAME, method: 'handleGetTransactionsInError'
});
}

MODIFY
src/server/rest/v1/service/UserService.ts
src/server/rest/v1/service/UserService.ts
@@ -804,11 +804,11 @@ export default class UserService {
public static async handleGetUsersInError(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Check auth
- if (!Authorizations.canListUsers(req.user)) {
+ if (!Authorizations.canListUsersInErrors(req.user)) {
throw new AppAuthError({
errorCode: HTTPAuthError.ERROR,
user: req.user,
- action: Action.LIST, entity: Entity.USERS,
+ action: Action.IN_ERROR, entity: Entity.USERS,
module: MODULE_NAME, method: 'handleGetUsersInError'
});
}
@@ -819,12 +819,16 @@ export default class UserService {
UtilsService.assertComponentIsActiveFromToken(req.user, TenantComponents.ORGANIZATION,
Action.READ, Entity.USER, MODULE_NAME, 'handleGetUsersInError');
}
+ // Get authorization filters
+ const authorizationFilters = await AuthorizationService.getUsersInErrorAuthorizationFilters(
+ filteredRequest, req.user, req.tenant);
// Get users
const users = await UserStorage.getUsersInError(req.user.tenantID,
{
search: filteredRequest.Search,
roles: (filteredRequest.Role ? filteredRequest.Role.split('|') : null),
- errorTypes: (filteredRequest.ErrorType ? filteredRequest.ErrorType.split('|') : Object.values(UserInErrorType))
+ errorTypes: (filteredRequest.ErrorType ? filteredRequest.ErrorType.split('|') : Object.values(UserInErrorType)),
+ ...authorizationFilters.filters
},
{
limit: filteredRequest.Limit,
@@ -832,10 +836,7 @@ export default class UserService {
skip: filteredRequest.Skip,
sort: filteredRequest.Sort
},
- [
- 'id', 'name', 'firstName', 'email', 'role', 'status', 'issuer',
- 'createdOn', 'lastChangedOn', 'errorCodeDetails', 'errorCode'
- ]
+ authorizationFilters.project
);
// Return
res.json(users);

MODIFY
src/types/Authorization.ts
src/types/Authorization.ts
@@ -97,6 +97,7 @@ export enum Action {
LOGOUT = 'Logout',
LOGIN = 'Login',
LIST = 'List',
+ IN_ERROR = 'InError',
RESET = 'Reset',
ASSIGN = 'Assign',
UNASSIGN = 'Unassign',
@@ -116,7 +117,7 @@ export enum Action {
CLEAR_CHARGING_PROFILE = 'ClearChargingProfile',
GET_DIAGNOSTICS = 'GetDiagnostics',
UPDATE_FIRMWARE = 'UpdateFirmware',
- EXPORT_PARAMS = 'ExportParams',
+ EXPORT = 'Export',
CHANGE_AVAILABILITY = 'ChangeAvailability',
REFUND_TRANSACTION = 'RefundTransaction',
SYNCHRONIZE_BILLING_USERS = 'SynchronizeBillingUsers',

Add In Error auths