missed siteIDs filter in userStorage *facepalm*
MODIFY
src/authorization/Authorizations.ts
src/authorization/Authorizations.ts
@@ -327,17 +327,6 @@ export default class Authorizations {
}
- public static async canAssignUsersSites(loggedUser: UserToken, authContext?: AuthorizationContext): Promise<AuthorizationResult> {
- return Authorizations.can(loggedUser, Entity.USERS_SITES, Action.ASSIGN, authContext);
- }
-
- public static async canUnassignUsersSites(loggedUser: UserToken, authContext?: AuthorizationContext): Promise<AuthorizationResult> {
- return Authorizations.can(loggedUser, Entity.USERS_SITES, Action.UNASSIGN, authContext);
- }
-
- public static async canListUsersSites(loggedUser: UserToken, authContext?: AuthorizationContext): Promise<AuthorizationResult> {
- return Authorizations.can(loggedUser, Entity.USERS_SITES, Action.LIST, authContext);
- }
public static async canListUsers(loggedUser: UserToken, authContext?: AuthorizationContext): Promise<AuthorizationResult> {
return Authorizations.can(loggedUser, Entity.USER, Action.LIST, authContext);

MODIFY
src/authorization/AuthorizationsDefinition.ts
src/authorization/AuthorizationsDefinition.ts
@@ -253,14 +253,7 @@ export const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
},
},
{
- resource: Entity.USERS_SITES, action: Action.LIST,
- attributes: [
- 'user.id', 'user.name', 'user.firstName', 'user.email', 'user.role', 'siteID',
- 'site.id', 'site.name', 'site.address.city', 'site.address.country', 'siteAdmin', 'siteOwner', 'userID'
- ]
- },
- {
- resource: Entity.USERS_SITES, action: [Action.ASSIGN, Action.READ, Action.UPDATE],
+ resource: Entity.USERS_SITES, action: [Action.ASSIGN, Action.READ, Action.UPDATE, Action.LIST],
condition: {
Fn: 'custom:dynamicAuthorizations',
args: {
@@ -1609,7 +1602,7 @@ export const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
],
},
{
- resource: Entity.USERS_SITES, action: [Action.ASSIGN, Action.READ, Action.LIST],
+ resource: Entity.USERS_SITES, action: [Action.READ, Action.LIST],
condition: {
Fn: 'custom:dynamicAuthorizations',
args: {
@@ -1622,17 +1615,6 @@ export const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
'site.id', 'site.name', 'site.address.city', 'site.address.country', 'siteAdmin', 'siteOwner', 'userID'
]
},
- {
- resource: Entity.USERS_SITES,
- action: Action.UNASSIGN,
- condition: {
- Fn: 'custom:dynamicAuthorizations',
- args: {
- asserts: [],
- filters: ['-OwnUser', 'LocalIssuer']
- }
- },
- },
{
resource: Entity.TRANSACTION, action: [Action.READ, Action.REFUND_TRANSACTION],
condition: {

MODIFY
src/storage/mongodb/UserStorage.ts
src/storage/mongodb/UserStorage.ts
@@ -911,7 +911,7 @@ export default class UserStorage {
}
public static async getSiteUsers(tenant: Tenant,
- params: { search?: string; userIDs: string[]; siteAdmin?: boolean; siteOwner?: boolean },
+ params: { search?: string; userIDs: string[]; siteIDs?: string[]; siteAdmin?: boolean; siteOwner?: boolean },
dbParams: DbParams, projectFields?: string[]): Promise<DataResult<SiteUser>> {
const startTime = Logging.traceDatabaseRequestStart();
DatabaseUtils.checkTenantObject(tenant);
@@ -937,6 +937,16 @@ export default class UserStorage {
}
// Create Aggregation
const aggregation: any[] = [];
+ // Filter on authorized sites
+ if (!Utils.isEmptyArray(params.siteIDs)) {
+ aggregation.push({
+ $match: {
+ siteID: {
+ $in: params.siteIDs.map((siteID) => DatabaseUtils.convertToObjectID(siteID))
+ }
+ }
+ });
+ }
// Filter
aggregation.push({
$match: filters

missed siteIDs filter in userStorage *facepalm*