From 2c72f85da1536accabd9f7504d430d14d6f77c1a Mon Sep 17 00:00:00 2001 From: Dharini Jeeva Date: Mon, 9 Jan 2023 11:32:37 -0800 Subject: [PATCH] Add support for managed groups in add-principals list (#1548) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit chore: 🤖 add managed groups to add-principals view --- .../form/role/add-principals/index.hbs | 14 +--------- .../form/role/add-principals/index.js | 15 ++++++++-- .../app/components/link-to-principal/index.js | 2 +- .../scopes/scope/roles/role/add-principals.js | 28 +++++++++++++++++-- .../scope/roles/role/add-principals.hbs | 1 + 5 files changed, 41 insertions(+), 19 deletions(-) diff --git a/ui/admin/app/components/form/role/add-principals/index.hbs b/ui/admin/app/components/form/role/add-principals/index.hbs index a825b7731..fc357cfc1 100644 --- a/ui/admin/app/components/form/role/add-principals/index.hbs +++ b/ui/admin/app/components/form/role/add-principals/index.hbs @@ -44,19 +44,7 @@ {{principal.id}} - + diff --git a/ui/admin/app/components/form/role/add-principals/index.js b/ui/admin/app/components/form/role/add-principals/index.js index 1d1d0f0f6..9e797f18e 100644 --- a/ui/admin/app/components/form/role/add-principals/index.js +++ b/ui/admin/app/components/form/role/add-principals/index.js @@ -24,14 +24,15 @@ export default class FormRoleAddPrincipalsIndexComponent extends Component { /** * Principals not currently assigned to a role. - * @type {[UserModel, GroupModel]} + * @type {[UserModel, GroupModel, ManagedGroupModel]} */ - @computed('args.{model,model.principals.[],users,groups}') + @computed('args.{model,model.principals.[],users,groups,managedGroups}') get filteredPrincipals() { // Retrieve principal IDs assigned to current role const currentPrincipalIDs = this.args.model.principals.map( (principal) => principal.principal_id ); + // Retrieve principal IDs not assigned to current role const unassignedUsers = this.args.users.filter( ({ id }) => !currentPrincipalIDs.includes(id) @@ -39,7 +40,15 @@ export default class FormRoleAddPrincipalsIndexComponent extends Component { const unassignedGroups = this.args.groups.filter( ({ id }) => !currentPrincipalIDs.includes(id) ); - return [...unassignedUsers, ...unassignedGroups]; + const unassignedManagedGroups = this.args.managedGroups.filter( + ({ id }) => !currentPrincipalIDs.includes(id) + ); + + return [ + ...unassignedUsers, + ...unassignedGroups, + ...unassignedManagedGroups, + ]; } // =actions diff --git a/ui/admin/app/components/link-to-principal/index.js b/ui/admin/app/components/link-to-principal/index.js index a2adfb65e..88321ae37 100644 --- a/ui/admin/app/components/link-to-principal/index.js +++ b/ui/admin/app/components/link-to-principal/index.js @@ -16,7 +16,7 @@ export default class LinkToPrincipalComponent extends Component { return this.args.model.constructor.modelName === 'managed-group'; } - /** + /** * return route based on principal type * @type {string} */ diff --git a/ui/admin/app/routes/scopes/scope/roles/role/add-principals.js b/ui/admin/app/routes/scopes/scope/roles/role/add-principals.js index 57b6e4eb3..d17fa289c 100644 --- a/ui/admin/app/routes/scopes/scope/roles/role/add-principals.js +++ b/ui/admin/app/routes/scopes/scope/roles/role/add-principals.js @@ -1,7 +1,7 @@ import Route from '@ember/routing/route'; import { inject as service } from '@ember/service'; import { action } from '@ember/object'; -import { hash } from 'rsvp'; +import { hash, all } from 'rsvp'; import { loading } from 'ember-loading'; import { notifySuccess, notifyError } from 'core/decorators/notify'; import { resourceFilter } from 'core/decorators/resource-filter'; @@ -38,7 +38,7 @@ export default class ScopesScopeRolesRoleAddPrincipalsRoute extends Route { * Returns the current role, all users, and all groups * @return {{role: RoleModel, users: [UserModel], groups: [GroupModel]}} */ - model() { + async model() { const role = this.modelFor('scopes.scope.roles.role'); const scopes = this.store.peekAll('scope').toArray(); const scopeIDs = this.scope?.map((scope) => scope.id); @@ -66,11 +66,35 @@ export default class ScopesScopeRolesRoleAddPrincipalsRoute extends Route { } ) : this.store.query('group', { scope_id: 'global', recursive: true }); + //query authmethods from all the scopes + const oidcAuthMethods = scopeIDs?.length + ? await this.resourceFilterStore.queryBy( + 'auth-method', + { scope_id: scopeIDs, type: 'oidc' }, + { scope_id: 'global', recursive: true } + ) + : await this.resourceFilterStore.queryBy( + 'auth-method', + { type: 'oidc' }, + { scope_id: 'global', recursive: true } + ); + //extract oidc authMethod IDs + const oidcAuthMethodIDs = oidcAuthMethods.map(({ id }) => id); + //query all the managed groups for each auth method id + const managedGroups = await all( + oidcAuthMethodIDs.map((auth_method_id) => + this.store.query('managed-group', { auth_method_id }) + ) + ); + const managedGroupModels = managedGroups + .map((models) => models.map((model) => model)) + .flat(); return hash({ role, scopes, users, groups, + managedGroups: managedGroupModels, }); } diff --git a/ui/admin/app/templates/scopes/scope/roles/role/add-principals.hbs b/ui/admin/app/templates/scopes/scope/roles/role/add-principals.hbs index 1fd7f1590..749b621d9 100644 --- a/ui/admin/app/templates/scopes/scope/roles/role/add-principals.hbs +++ b/ui/admin/app/templates/scopes/scope/roles/role/add-principals.hbs @@ -78,6 +78,7 @@ @model={{@model.role}} @users={{@model.users}} @groups={{@model.groups}} + @managedGroups={{@model.managedGroups}} @submit={{route-action 'addPrincipals' @model.role}} @cancel={{route-action 'cancel'}} />