From c6a917d21b28278e7baf903727d75b2fac180043 Mon Sep 17 00:00:00 2001 From: Cameron Perera Date: Tue, 4 Jun 2024 13:32:29 -0500 Subject: [PATCH] Icu 12707 update role mirage (#2319) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 🎸 add grant_scope_ids to role mirage ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12707 * feat: 🎸 set grant_scope_ids in onboarding workflow ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12707 * refactor: 💡 set grant_scope_ids when calling updateGrantScopeID ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12707 * refactor: 💡 add TODO for removal of grant_scope_id ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12707 --- addons/api/mirage/config.js | 7 +++++++ addons/api/mirage/factories/role.js | 13 +++---------- addons/api/mirage/serializers/role.js | 8 ++++++-- ui/admin/app/components/form/role/index.js | 2 ++ ui/admin/app/routes/onboarding.js | 2 ++ 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/addons/api/mirage/config.js b/addons/api/mirage/config.js index f80496507..e8087c897 100644 --- a/addons/api/mirage/config.js +++ b/addons/api/mirage/config.js @@ -320,6 +320,13 @@ function routes() { const role = roles.find(id); let updatedAttrs = {}; + if (method === 'set-grant-scopes') { + updatedAttrs = { + version: attrs.version, + grantScopeIds: attrs.grantScopeIds, + }; + } + // Principals is a combined list of users, groups and managed 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 diff --git a/addons/api/mirage/factories/role.js b/addons/api/mirage/factories/role.js index 6cc4efa28..448a53c24 100644 --- a/addons/api/mirage/factories/role.js +++ b/addons/api/mirage/factories/role.js @@ -26,6 +26,9 @@ export default factory.extend({ ], id: () => generateId('r_'), + // TODO: all grant_scope_id instances will be removed in future PR + grant_scope_id: 'this', + grant_scope_ids: () => ['this'], /** * Adds principals to the role. @@ -42,14 +45,4 @@ export default factory.extend({ role.update({ users, groups, managedGroups }); }, }), - - /** - * Set the grant scope ID to match the scope ID. - */ - afterCreate(role) { - const { - scope: { id }, - } = role; - role.update({ grant_scope_id: id }); - }, }); diff --git a/addons/api/mirage/serializers/role.js b/addons/api/mirage/serializers/role.js index ff6b6e6b0..7c63726b6 100644 --- a/addons/api/mirage/serializers/role.js +++ b/addons/api/mirage/serializers/role.js @@ -38,8 +38,12 @@ export default ApplicationSerializer.extend({ if (!json.principals.length) delete json.principals; - // default grant scope - if (!json.grant_scope_id) json.grant_scope_id = json.scope.id; + // default grant scopes + // TODO: all grant_scope_id instances will be removed in future PR + if (!json.grant_scope_id) json.grant_scope_id = 'this'; + if (json.grant_scope_ids.length === 0) { + json.grant_scope_ids = ['this']; + } return json; }, diff --git a/ui/admin/app/components/form/role/index.js b/ui/admin/app/components/form/role/index.js index d3b2ed2d9..31987ef40 100644 --- a/ui/admin/app/components/form/role/index.js +++ b/ui/admin/app/components/form/role/index.js @@ -11,6 +11,8 @@ export default class FormRoleGrantsComponent extends Component { @action updateGrantScopeID(id) { + // TODO: all grant_scope_id instances will be removed in future PR this.args.model.grant_scope_id = id; + this.args.model.grant_scope_ids = [id]; } } diff --git a/ui/admin/app/routes/onboarding.js b/ui/admin/app/routes/onboarding.js index 2540ee3f9..913540d56 100644 --- a/ui/admin/app/routes/onboarding.js +++ b/ui/admin/app/routes/onboarding.js @@ -132,7 +132,9 @@ export default class OnboardingRoute extends Route { async createGrants(org, project, target, role) { role.scopeID = org.id; + // TODO: all grant_scope_id instances will be removed in future PR role.grant_scope_id = project.id; + role.grant_scope_ids = [project.id]; try { await role.save(); await role.saveGrantStrings([