Add support for managed groups in add-principals list (#1548)
chore: 🤖 add managed groups to add-principals view
This commit is contained in:
1 parent
73be8268a6
commit
2c72f85da1
5 files changed
+41
-19
No files matched your search
@@ -44,19 +44,7 @@
|
|||||||
</row.headerCell>
|
</row.headerCell>
|
||||||
<row.cell>{{principal.id}}</row.cell>
|
<row.cell>{{principal.id}}</row.cell>
|
||||||
<row.cell>
|
<row.cell>
|
||||||
<Hds::Badge
|
<PrincipalTypeBadge @model={{principal}} />
|
||||||
@icon={{if
|
|
||||||
(eq principal.constructor.modelName 'group')
|
|
||||||
'folder-users'
|
|
||||||
'user'
|
|
||||||
}}
|
|
||||||
@text={{t
|
|
||||||
(concat
|
|
||||||
'resources.role.principal.types.'
|
|
||||||
principal.constructor.modelName
|
|
||||||
)
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</row.cell>
|
</row.cell>
|
||||||
<row.cell>
|
<row.cell>
|
||||||
<ScopeBadge @scope={{principal.scopeModel}} />
|
<ScopeBadge @scope={{principal.scopeModel}} />
|
||||||
|
|||||||
@@ -24,14 +24,15 @@ export default class FormRoleAddPrincipalsIndexComponent extends Component {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Principals not currently assigned to a role.
|
* 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() {
|
get filteredPrincipals() {
|
||||||
// Retrieve principal IDs assigned to current role
|
// Retrieve principal IDs assigned to current role
|
||||||
const currentPrincipalIDs = this.args.model.principals.map(
|
const currentPrincipalIDs = this.args.model.principals.map(
|
||||||
(principal) => principal.principal_id
|
(principal) => principal.principal_id
|
||||||
);
|
);
|
||||||
|
|
||||||
// Retrieve principal IDs not assigned to current role
|
// Retrieve principal IDs not assigned to current role
|
||||||
const unassignedUsers = this.args.users.filter(
|
const unassignedUsers = this.args.users.filter(
|
||||||
({ id }) => !currentPrincipalIDs.includes(id)
|
({ id }) => !currentPrincipalIDs.includes(id)
|
||||||
@@ -39,7 +40,15 @@ export default class FormRoleAddPrincipalsIndexComponent extends Component {
|
|||||||
const unassignedGroups = this.args.groups.filter(
|
const unassignedGroups = this.args.groups.filter(
|
||||||
({ id }) => !currentPrincipalIDs.includes(id)
|
({ id }) => !currentPrincipalIDs.includes(id)
|
||||||
);
|
);
|
||||||
return [...unassignedUsers, ...unassignedGroups];
|
const unassignedManagedGroups = this.args.managedGroups.filter(
|
||||||
|
({ id }) => !currentPrincipalIDs.includes(id)
|
||||||
|
);
|
||||||
|
|
||||||
|
return [
|
||||||
|
...unassignedUsers,
|
||||||
|
...unassignedGroups,
|
||||||
|
...unassignedManagedGroups,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
// =actions
|
// =actions
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ export default class LinkToPrincipalComponent extends Component {
|
|||||||
return this.args.model.constructor.modelName === 'managed-group';
|
return this.args.model.constructor.modelName === 'managed-group';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return route based on principal type
|
* return route based on principal type
|
||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import Route from '@ember/routing/route';
|
import Route from '@ember/routing/route';
|
||||||
import { inject as service } from '@ember/service';
|
import { inject as service } from '@ember/service';
|
||||||
import { action } from '@ember/object';
|
import { action } from '@ember/object';
|
||||||
import { hash } from 'rsvp';
|
import { hash, all } from 'rsvp';
|
||||||
import { loading } from 'ember-loading';
|
import { loading } from 'ember-loading';
|
||||||
import { notifySuccess, notifyError } from 'core/decorators/notify';
|
import { notifySuccess, notifyError } from 'core/decorators/notify';
|
||||||
import { resourceFilter } from 'core/decorators/resource-filter';
|
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
|
* Returns the current role, all users, and all groups
|
||||||
* @return {{role: RoleModel, users: [UserModel], groups: [GroupModel]}}
|
* @return {{role: RoleModel, users: [UserModel], groups: [GroupModel]}}
|
||||||
*/
|
*/
|
||||||
model() {
|
async model() {
|
||||||
const role = this.modelFor('scopes.scope.roles.role');
|
const role = this.modelFor('scopes.scope.roles.role');
|
||||||
const scopes = this.store.peekAll('scope').toArray();
|
const scopes = this.store.peekAll('scope').toArray();
|
||||||
const scopeIDs = this.scope?.map((scope) => scope.id);
|
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 });
|
: 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({
|
return hash({
|
||||||
role,
|
role,
|
||||||
scopes,
|
scopes,
|
||||||
users,
|
users,
|
||||||
groups,
|
groups,
|
||||||
|
managedGroups: managedGroupModels,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -78,6 +78,7 @@
|
|||||||
@model={{@model.role}}
|
@model={{@model.role}}
|
||||||
@users={{@model.users}}
|
@users={{@model.users}}
|
||||||
@groups={{@model.groups}}
|
@groups={{@model.groups}}
|
||||||
|
@managedGroups={{@model.managedGroups}}
|
||||||
@submit={{route-action 'addPrincipals' @model.role}}
|
@submit={{route-action 'addPrincipals' @model.role}}
|
||||||
@cancel={{route-action 'cancel'}}
|
@cancel={{route-action 'cancel'}}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in new issue
Block a user