From 254ec2203eba6638c83df2e51665663ed0390d98 Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Sat, 12 Sep 2020 12:03:52 -0400 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20add=20missing=20set-grant?= =?UTF-8?q?s=20method=20to=20mocks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/core/mirage/config.js | 24 +++++++++++++++++++----- ui/core/mirage/factories/role.js | 2 +- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/ui/core/mirage/config.js b/ui/core/mirage/config.js index aee4a5b3b..3b9e24cce 100644 --- a/ui/core/mirage/config.js +++ b/ui/core/mirage/config.js @@ -109,17 +109,18 @@ export default function() { const id = idMethod.split(':')[0]; const method = idMethod.split(':')[1]; const role = roles.find(id); - const updatedAttrs = { - version: attrs.version, - userIds: role.userIds, - groupIds: role.groupIds - }; + let updatedAttrs = {}; // Principals is a combined list of users and groups, but in Mirage we've // internally modelled them as separate lists. Therefore we must check // the type by looking up the user or group first, then determine which // list to add the principal to. if (method === 'add-principals') { + updatedAttrs = { + version: attrs.version, + userIds: role.userIds, + groupIds: role.groupIds + }; attrs.principalIds.forEach(id => { const isUser = users.find(id); const isGroup = groups.find(id); @@ -134,6 +135,11 @@ export default function() { // If deleting principals, filter them out of both users and groups, // and in this case don't care about the type if (method === 'remove-principals') { + updatedAttrs = { + version: attrs.version, + userIds: role.userIds, + groupIds: role.groupIds + }; updatedAttrs.userIds = updatedAttrs.userIds.filter(id => { return !attrs.principalIds.includes(id); }); @@ -141,6 +147,14 @@ export default function() { return !attrs.principalIds.includes(id); }); } + + if (method === 'set-grants') { + updatedAttrs = { + version: attrs.version, + grant_strings: attrs.grant_strings + }; + } + return role.update(updatedAttrs); }); diff --git a/ui/core/mirage/factories/role.js b/ui/core/mirage/factories/role.js index ea5734835..87eb39092 100644 --- a/ui/core/mirage/factories/role.js +++ b/ui/core/mirage/factories/role.js @@ -4,7 +4,7 @@ import { trait } from 'ember-cli-mirage'; export default factory.extend({ // eslint-disable-next-line ember/avoid-leaking-state-in-ember-objects - grant_strings: [ + grant_strings: () => [ 'id=*;action=*', 'id=*;type=host-catalog;actions=create,read' ],