aligned failsWithException
deleted unused check for sites assigned / sites admin and owner (replaced in user abac)
MODIFY
src/server/rest/v1/service/AuthorizationService.ts
src/server/rest/v1/service/AuthorizationService.ts
@@ -1401,60 +1401,6 @@ export default class AuthorizationService {
return authorizations;
}
- private static async checkAssignedSites(tenant: Tenant, userToken: UserToken,
- filteredRequest: { SiteID?: string }, authorizationFilters: AuthorizationFilter): Promise<void> {
- if (userToken.role !== UserRole.ADMIN && userToken.role !== UserRole.SUPER_ADMIN) {
- if (Utils.isTenantComponentActive(tenant, TenantComponents.ORGANIZATION)) {
- // Get assigned Site IDs assigned to user from DB
- const siteIDs = await Authorizations.getAssignedSiteIDs(tenant, userToken);
- if (!Utils.isEmptyArray(siteIDs)) {
- // Force the filter
- authorizationFilters.filters.siteIDs = siteIDs;
- // Check if filter is provided
- if (filteredRequest?.SiteID) {
- const filteredSiteIDs = filteredRequest.SiteID.split('|');
- // Override
- authorizationFilters.filters.siteIDs = filteredSiteIDs.filter(
- (siteID) => authorizationFilters.filters.siteIDs.includes(siteID));
- }
- }
- if (!Utils.isEmptyArray(authorizationFilters.filters.siteIDs)) {
- authorizationFilters.authorized = true;
- }
- } else {
- authorizationFilters.authorized = true;
- }
- }
- }
-
- private static async checkAssignedSiteAdminsAndOwners(tenant: Tenant, userToken: UserToken,
- filteredRequest: { SiteID?: string }, authorizationFilters: AuthorizationFilter): Promise<void> {
- if (userToken.role !== UserRole.ADMIN && userToken.role !== UserRole.SUPER_ADMIN) {
- if (Utils.isTenantComponentActive(tenant, TenantComponents.ORGANIZATION)) {
- // Get Site IDs from Site Admin & Site Owner flag
- const siteAdminSiteIDs = await Authorizations.getSiteAdminSiteIDs(tenant, userToken);
- const siteOwnerSiteIDs = await Authorizations.getSiteOwnerSiteIDs(tenant, userToken);
- const allSites = _.uniq([...siteAdminSiteIDs, ...siteOwnerSiteIDs]);
- if (!Utils.isEmptyArray(allSites)) {
- // Force the filters
- authorizationFilters.filters.siteIDs = allSites;
- // Check if filter is provided
- if (filteredRequest?.SiteID) {
- const filteredSiteIDs: string[] = filteredRequest.SiteID.split('|');
- // Override
- authorizationFilters.filters.siteIDs = filteredSiteIDs.filter(
- (filteredSiteID) => authorizationFilters.filters.siteIDs.includes(filteredSiteID));
- }
- }
- if (!Utils.isEmptyArray(authorizationFilters.filters.siteIDs)) {
- authorizationFilters.authorized = true;
- }
- } else {
- authorizationFilters.authorized = true;
- }
- }
- }
-
private static filterProjectFields(authFields: string[], httpProjectField: string): string[] {
let fields = authFields;
// Only allow projected fields

MODIFY
src/server/rest/v1/service/ChargingStationService.ts
src/server/rest/v1/service/ChargingStationService.ts
@@ -542,7 +542,8 @@ export default class ChargingStationService {
// Filter
const filteredRequest = ChargingStationValidatorRest.getInstance().validateChargingStationNotificationsGetReq(req.query);
// Check dynamic auth
- const authorizations = await AuthorizationService.checkAndGetChargingStationsAuthorizations(req.tenant, req.user, Action.GET_BOOT_NOTIFICATION);
+ const authorizations = await AuthorizationService.checkAndGetChargingStationsAuthorizations(
+ req.tenant, req.user, Action.GET_BOOT_NOTIFICATION, filteredRequest, false);
if (!authorizations.authorized) {
UtilsService.sendEmptyDataResult(res, next);
return;
@@ -609,7 +610,7 @@ export default class ChargingStationService {
const filteredRequest = ChargingStationValidatorRest.getInstance().validateChargingStationNotificationsGetReq(req.query);
// Check dynamic auth
const authorizations = await AuthorizationService.checkAndGetChargingStationsAuthorizations(
- req.tenant, req.user, Action.GET_BOOT_NOTIFICATION);
+ req.tenant, req.user, Action.GET_BOOT_NOTIFICATION, filteredRequest, false);
if (!authorizations.authorized) {
UtilsService.sendEmptyDataResult(res, next);
return;

MODIFY
src/server/rest/v1/service/TransactionService.ts
src/server/rest/v1/service/TransactionService.ts
@@ -338,7 +338,7 @@ export default class TransactionService {
});
}
// Check consumption dynamic auth
- const authorizations = await AuthorizationService.checkAndGetConsumptionsAuthorizations(req.tenant, req.user, Action.LIST, null, true);
+ const authorizations = await AuthorizationService.checkAndGetConsumptionsAuthorizations(req.tenant, req.user, Action.LIST);
let consumptions: Consumption[];
if (filteredRequest.LoadAllConsumptions) {
const consumptionsMDB = await ConsumptionStorage.getTransactionConsumptions(
@@ -496,13 +496,10 @@ export default class TransactionService {
// Check if component is active
UtilsService.assertComponentIsActiveFromToken(req.user, TenantComponents.REFUND,
Action.LIST, Entity.TRANSACTION, MODULE_NAME, 'handleGetRefundReports');
-
// Filter request
const filteredRequest = TransactionValidatorRest.getInstance().validateTransactionsGetReq(req.query);
// Check dyna;ic auth
const authorizations = await AuthorizationService.checkAndGetTransactionsAuthorizations(req.tenant, req.user, Action.GET_REFUND_REPORT, filteredRequest);
-
-
// Get Reports
const reports = await TransactionStorage.getRefundReports(
req.tenant,
@@ -570,7 +567,6 @@ export default class TransactionService {
}
public static async handleGetTransactionsInError(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
-
// Check auth
const authorizations = await AuthorizationService.checkAndGetTransactionsAuthorizations(req.tenant, req.user, Action.IN_ERROR);
// Filter
@@ -746,14 +742,12 @@ export default class TransactionService {
private static async getTransactions(req: Request, filteredRequest: HttpTransactionsGetRequest,
authAction: Action = Action.LIST, additionalFilters: Record<string, any> = {}): Promise<DataResult<Transaction>> {
-
// Get authorization filters
const authorizations = await AuthorizationService.checkAndGetTransactionsAuthorizations(
req.tenant, req.user, authAction, filteredRequest, false);
if (!authorizations.authorized) {
return Constants.DB_EMPTY_DATA_RESULT;
}
-
// Get Tag IDs from Visual IDs
if (filteredRequest.VisualTagID) {
const tagIDs = await TagStorage.getTags(req.tenant, { visualIDs: filteredRequest.VisualTagID.split('|') }, Constants.DB_PARAMS_MAX_LIMIT, ['id']);

aligned failsWithException
deleted unused check for sites assigned / sites admin and owner (replaced in user abac)