From c2083aefab58fb9a30568c15221f9dad1b680104 Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Mon, 18 Jul 2022 15:53:34 -0700 Subject: [PATCH] =?UTF-8?q?chore:=20=F0=9F=A4=96=20add=20recursion=20and?= =?UTF-8?q?=20filtering=20to=20user=20and=20group=20mocks=20-=20ICU-4528?= =?UTF-8?q?=20(#1190)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: 🤖 add scope column to role principals and group members * chore: 🤖 add recursion and filtering to user and group mocks --- addons/api/mirage/config.js | 46 ++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 6 deletions(-) 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');