Fix siteadmin user filter
SA can see correct transactions
MODIFY
src/authorization/dynamic-filters/SitesAdminUsersDynamicAuthorizationFilter.ts
src/authorization/dynamic-filters/SitesAdminUsersDynamicAuthorizationFilter.ts
@@ -15,39 +15,38 @@ export default class SitesAdminUsersDynamicAuthorizationFilter extends DynamicAu
// Perform site ids check only if organization component is active
if (Utils.isTenantComponentActive(this.tenant, TenantComponents.ORGANIZATION)) {
// Init user site IDs
- let userSiteIds = [];
+ authorizationFilters.filters.siteAdminIDs = [];
if (!Utils.isEmptyArray(siteIDs)) {
- userSiteIds = siteIDs;
+ authorizationFilters.filters.siteAdminIDs = siteIDs;
// Check if filter is provided
if (Utils.objectHasProperty(extraFilters, 'SiteID') &&
!Utils.isNullOrUndefined(extraFilters['SiteID'])) {
const filteredSiteIDs: string[] = extraFilters['SiteID'].split('|');
// Override
- userSiteIds = filteredSiteIDs.filter(
- (siteID) => userSiteIds.includes(siteID));
+ authorizationFilters.filters.siteAdminIDs = filteredSiteIDs.filter(
+ (siteID) => authorizationFilters.filters.siteAdminIDs.includes(siteID));
}
}
- if (!Utils.isEmptyArray(userSiteIds)) {
+ if (!Utils.isEmptyArray(authorizationFilters.filters.siteAdminIDs)) {
authorizationFilters.authorized = true;
}
}
// Check user filter
- if (!authorizationFilters.authorized) {
- let siteAdminUserId = [userID];
+ authorizationFilters.filters.ownerID = [];
if (userID) {
+ authorizationFilters.filters.ownerID = [userID];
// Check if filter is provided
if (Utils.objectHasProperty(extraFilters, 'UserID') &&
!Utils.isNullOrUndefined(extraFilters['UserID'])) {
const filteredUserIDs: string[] = extraFilters['UserID'].split('|');
// Override
- siteAdminUserId = filteredUserIDs.filter(
- (user) => siteAdminUserId.includes(user));
+ authorizationFilters.filters.ownerID = filteredUserIDs.filter(
+ (user) => authorizationFilters.filters.ownerID.includes(user));
}
}
- if (!Utils.isEmptyArray(siteAdminUserId)) {
+ if (!Utils.isEmptyArray(authorizationFilters.filters.ownerID)) {
authorizationFilters.authorized = true;
}
- }
// Remove sensible data if not authorized and filter is provided
if (!authorizationFilters.authorized) {
Utils.removeSensibeDataFromEntity(extraFilters, entityData);

MODIFY
src/storage/mongodb/TransactionStorage.ts
src/storage/mongodb/TransactionStorage.ts
@@ -322,7 +322,7 @@ export default class TransactionStorage {
public static async getTransactions(tenant: Tenant,
params: {
- transactionIDs?: number[]; issuer?: boolean; search?: string; ownerID?: string; userIDs?: string[]; siteAdminIDs?: string[]; status?: TransactionStatus;
+ transactionIDs?: number[]; issuer?: boolean; search?: string; ownerID?: string[]; userIDs?: string[]; siteAdminIDs?: string[]; status?: TransactionStatus;
chargingStationIDs?: string[]; siteAreaIDs?: string[]; siteIDs?: string[]; connectorIDs?: number[]; startDateTime?: Date; withChargingStation?: boolean;
endDateTime?: Date; stop?: any; minimalPrice?: boolean; reportIDs?: string[]; tagIDs?: string[]; inactivityStatus?: string[];
ocpiSessionID?: string; ocpiAuthorizationID?: string; ocpiSessionDateFrom?: Date; ocpiSessionDateTo?: Date; ocpiCdrDateFrom?: Date; ocpiCdrDateTo?: Date;
@@ -343,9 +343,11 @@ export default class TransactionStorage {
const ownerMatch = { $or: [] };
const filters: FilterParams = {};
// User / Site Admin
- if (params.ownerID) {
+ if (!Utils.isEmptyArray(params.ownerID)) {
ownerMatch.$or.push({
- userID: DatabaseUtils.convertToObjectID(params.ownerID)
+ userID: {
+ $in: params.ownerID.map((userID) => DatabaseUtils.convertToObjectID(userID))
+ }
});
}
if (params.siteAdminIDs) {

Fix siteadmin user filter

- SA can see correct transactions