diff --git a/addons/api/mirage/config.js b/addons/api/mirage/config.js index eb949a1a8..e93674b22 100644 --- a/addons/api/mirage/config.js +++ b/addons/api/mirage/config.js @@ -141,9 +141,26 @@ export default function () { this.post('/scopes/:id_method', deauthHandler); // IAM : Users - this.get('/users', ({ users }, { queryParams: { scope_id: scopeId } }) => { - return users.where({ scopeId }); - }); + this.get( + '/users', + ({ users }, { queryParams: { scope_id, recursive, filter } }) => { + let resultSet; + if (recursive && scope_id === 'global') { + resultSet = users.all(); + } else if (recursive) { + resultSet = users.where((user) => { + const userModel = users.find(user.id); + return ( + user.scopeId === scope_id || + userModel?.scope?.scope?.id === scope_id + ); + }); + } else { + resultSet = users.where((user) => user.scopeId === scope_id); + } + return resultSet.filter(makeBooleanFilter(filter)); + } + ); this.post('/users'); this.get('/users/:id'); this.patch('/users/:id'); @@ -175,9 +192,26 @@ export default function () { }); // IAM: Groups - this.get('/groups', ({ groups }, { queryParams: { scope_id: scopeId } }) => { - return groups.where({ scopeId }); - }); + this.get( + '/groups', + ({ groups }, { queryParams: { scope_id, recursive, filter } }) => { + let resultSet; + if (recursive && scope_id === 'global') { + resultSet = groups.all(); + } else if (recursive) { + resultSet = groups.where((group) => { + const groupModel = groups.find(group.id); + return ( + group.scopeId === scope_id || + groupModel?.scope?.scope?.id === scope_id + ); + }); + } else { + resultSet = groups.where((group) => group.scopeId === scope_id); + } + return resultSet.filter(makeBooleanFilter(filter)); + } + ); this.post('/groups'); this.get('/groups/:id'); this.patch('/groups/:id');