feat: List accounts within a managed group

This commit is contained in:
Susmitha Girumala committed 2021-11-12 11:22:16 -05:00
1 parent ff5cc71f60
commit be5f033712
11 files changed
+207 -6

No files matched your search

+11 -2
View File
@@ -77,8 +77,17 @@ export default function () {
// Auth Method Accounts
this.get(
'/accounts',
({ accounts }, { queryParams: { auth_method_id: authMethodId } }) => {
return accounts.where({ authMethodId });
(
{ accounts },
{ queryParams: { auth_method_id: authMethodId, filter } }
) => {
let resultSet;
if (authMethodId) {
resultSet = accounts.where({ authMethodId });
} else {
resultSet = accounts.all();
}
return resultSet.filter(makeBooleanFilter(filter));
}
);
this.post('/accounts');
+11 -1
View File
@@ -36,7 +36,17 @@ export default factory.extend({
});
if (type === 'oidc') {
server.createList('managed-group', 2, { scope, authMethod });
server
.createList('managed-group', 2, { scope, authMethod })
.map((managedGroup) => {
const accounts = server.createList('account', 2, {
scope,
type,
authMethod,
});
const accountIds = accounts.map((account) => account.id);
managedGroup.update({ memberIds: accountIds });
});
}
},
}),
@@ -362,3 +362,6 @@ managed-group:
welcome:
title: Welcome to Managed Groups
description: Create and manage managed groups for an auth method.
accounts:
title: Welcome to Accounts
description: No accounts in this managed group.
+3 -1
View File
@@ -59,7 +59,9 @@ Router.map(function () {
this.route(
'managed-group',
{ path: ':managed_group_id' },
function () {}
function () {
this.route('accounts');
}
);
this.route('new');
});
@@ -0,0 +1,26 @@
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
export default class ScopesScopeAuthMethodsAuthMethodManagedGroupsManagedGroupAccountsRoute extends Route {
// =services
@service resourceFilterStore;
// =methods
/**
* Returns the previously loaded managed group instances accounts.
* @return {Promise{[AccountModel]}}
*/
model() {
const { auth_method_id, member_ids } = this.modelFor(
'scopes.scope.auth-methods.auth-method.managed-groups.managed-group'
);
return this.resourceFilterStore.queryBy(
'account',
{ id: member_ids },
{ auth_method_id }
);
}
}
@@ -1,2 +1,2 @@
{{page-title 'ManagedGroup'}}
{{page-title @model.displayName}}
{{outlet}}
@@ -4,4 +4,9 @@
>
{{t 'titles.details'}}
</nav.link>
<nav.link
@route='scopes.scope.auth-methods.auth-method.managed-groups.managed-group.accounts'
>
{{t 'resources.account.title_plural'}}
</nav.link>
</Rose::Nav::Tabs>
@@ -0,0 +1,62 @@
{{page-title (t 'resources.account.title_plural')}}
{{#if @model}}
<Rose::Table as |table|>
<table.header as |header|>
<header.row as |row|>
<row.headerCell>{{t 'form.name.label'}}</row.headerCell>
<row.headerCell>{{t 'form.issuer.label'}}</row.headerCell>
<row.headerCell>{{t 'form.subject.label'}}</row.headerCell>
<row.headerCell>{{t 'form.email.label'}}</row.headerCell>
<row.headerCell>{{t 'form.full_name.label'}}</row.headerCell>
<row.headerCell>{{t 'form.type.label'}}</row.headerCell>
<row.headerCell>{{t 'form.id.label'}}</row.headerCell>
</header.row>
</table.header>
<table.body as |body|>
{{#each @model as |account|}}
<body.row as |row|>
<row.headerCell scope='row'>
{{account.accountName}}
<p>{{account.description}}</p>
</row.headerCell>
<row.cell>
<code>{{account.attributes.issuer}}</code>
</row.cell>
<row.cell>
<code>{{account.attributes.subject}}</code>
</row.cell>
<row.cell>
<code>{{account.attributes.email}}</code>
</row.cell>
<row.cell>
{{account.attributes.full_name}}
</row.cell>
<row.cell>
<Rose::Badge>{{account.type}}</Rose::Badge>
</row.cell>
<row.cell>
<Copyable
@text={{account.id}}
@buttonText={{t 'actions.copy-to-clipboard'}}
@acknowledgeText={{t 'states.copied'}}
>
<code>{{account.id}}</code>
</Copyable>
</row.cell>
</body.row>
{{/each}}
</table.body>
</Rose::Table>
{{else}}
<Rose::Layout::Centered>
<Rose::Message
@title={{t 'resources.managed-group.messages.accounts.title'}}
as |message|
>
<message.description>
{{t 'resources.managed-group.messages.accounts.description'}}
</message.description>
</Rose::Message>
</Rose::Layout::Centered>
{{/if}}
@@ -123,7 +123,6 @@ module('Acceptance | auth methods | oidc', function (hooks) {
await visit(urls.authMethod);
await click('.rose-layout-page-actions .rose-dropdown-trigger');
await click(`.rose-dropdown[open] input[value="${newState}"]`);
// debugger;
const authMethod = this.server.db.authMethods.find(instances.authMethod.id);
assert.notEqual(
newState,
@@ -0,0 +1,69 @@
import { module, test } from 'qunit';
import { visit, currentURL, findAll } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import a11yAudit from 'ember-a11y-testing/test-support/audit';
import {
authenticateSession,
// These are left here intentionally for future reference.
//currentSession,
//invalidateSession,
} from 'ember-simple-auth/test-support';
module('Acceptance | managed-groups | accounts', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
const instances = {
scopes: {
global: null,
org: null,
},
authMethod: null,
managedGroup: null,
accounts: null,
};
const urls = {
orgScope: null,
authMethods: null,
managedGroups: null,
managedGroup: null,
managedGroupAccounts: null,
};
hooks.beforeEach(function () {
authenticateSession({});
instances.scopes.global = this.server.create('scope', { id: 'global' });
instances.scopes.org = this.server.create('scope', {
type: 'org',
scope: { id: 'global', type: 'global' },
});
instances.authMethod = this.server.create(
'auth-method',
{
scope: instances.scopes.org,
type: 'oidc',
},
'withAccountsAndUsersAndManagedGroups'
);
instances.managedGroup = this.server.db.managedGroups[0];
// Generate route URLs for resources
urls.orgScope = `/scopes/${instances.scopes.org.id}`;
urls.authMethods = `${urls.orgScope}/auth-methods`;
urls.authMethod = `${urls.authMethods}/${instances.authMethod.id}`;
urls.managedGroups = `${urls.authMethod}/managed-groups`;
urls.managedGroup = `${urls.managedGroups}/${instances.managedGroup.id}`;
urls.managedGroupAccounts = `${urls.managedGroup}/accounts`;
});
test('User can navigate to index', async function (assert) {
assert.expect(3);
const accountsCount = instances.managedGroup.memberIds.length;
await visit(urls.managedGroupAccounts);
await a11yAudit();
assert.equal(currentURL(), urls.managedGroupAccounts);
assert.ok(accountsCount);
assert.equal(findAll('tbody tr').length, accountsCount);
});
});
@@ -0,0 +1,16 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module(
'Unit | Route | scopes/scope/auth-methods/auth-method/managed-groups/managed-group/accounts',
function (hooks) {
setupTest(hooks);
test('it exists', function (assert) {
let route = this.owner.lookup(
'route:scopes/scope/auth-methods/auth-method/managed-groups/managed-group/accounts'
);
assert.ok(route);
});
}
);