Merge branch 'main' into feature-auth-methods-filters

This commit is contained in:
Randall Morey authored and GitHub committed 2021-11-12 17:37:04 -05:00
commit 9c95e77597
19 files changed
+589 -10

No files matched your search

+11 -2
View File
@@ -78,8 +78,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,9 @@ managed-group:
welcome:
title: Welcome to Managed Groups
description: Create and manage managed groups for an auth method.
member:
title: Member
title_plural: Members
messages:
title: Welcome to Members
description: No members in this managed group.
@@ -0,0 +1,17 @@
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
export default class ScopesScopeAuthMethodsAuthMethodManagedGroupsManagedGroupMembersController extends Controller {
// =services
@service intl;
// =attributes
/**
* Translated new managed group breadcrumb
* @type {string}
*/
get breadCrumb() {
return this.intl.t('resources.managed-group.member.title_plural');
}
}
@@ -7,8 +7,9 @@ export default class ScopesScopeAuthMethodsAuthMethodManagedGroupsNewController
@service intl;
// =attributes
/**
* Translated new managed group breadcrumb
* Translated new account breadcrumb
* @type {string}
*/
get breadCrumb() {
+3 -1
View File
@@ -59,7 +59,9 @@ Router.map(function () {
this.route(
'managed-group',
{ path: ':managed_group_id' },
function () {}
function () {
this.route('members');
}
);
this.route('new');
});
@@ -0,0 +1,26 @@
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
export default class ScopesScopeAuthMethodsAuthMethodManagedGroupsManagedGroupMembersRoute extends Route {
// =services
@service resourceFilterStore;
// =methods
/**
* Returns the previously loaded managed group instances memebrs.
* @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,3 +0,0 @@
{{page-title (t 'resources.account.title_plural')}}
{{outlet}}
@@ -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.members'
>
{{t 'resources.managed-group.member.title_plural'}}
</nav.link>
</Rose::Nav::Tabs>
@@ -0,0 +1,62 @@
{{page-title (t 'resources.managed-group.member.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 |member|}}
<body.row as |row|>
<row.headerCell scope='row'>
{{member.accountName}}
<p>{{member.description}}</p>
</row.headerCell>
<row.cell>
<code>{{member.attributes.issuer}}</code>
</row.cell>
<row.cell>
<code>{{member.attributes.subject}}</code>
</row.cell>
<row.cell>
<code>{{member.attributes.email}}</code>
</row.cell>
<row.cell>
{{member.attributes.full_name}}
</row.cell>
<row.cell>
<Rose::Badge>{{member.type}}</Rose::Badge>
</row.cell>
<row.cell>
<Copyable
@text={{member.id}}
@buttonText={{t 'actions.copy-to-clipboard'}}
@acknowledgeText={{t 'states.copied'}}
>
<code>{{member.id}}</code>
</Copyable>
</row.cell>
</body.row>
{{/each}}
</table.body>
</Rose::Table>
{{else}}
<Rose::Layout::Centered>
<Rose::Message
@title={{t 'resources.managed-group.member.messages.title'}}
as |message|
>
<message.description>
{{t 'resources.managed-group.member.messages.description'}}
</message.description>
</Rose::Message>
</Rose::Layout::Centered>
{{/if}}
@@ -0,0 +1,3 @@
{{page-title (t 'resources.managed-group.member.title_plural')}}
{{outlet}}
@@ -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,160 @@
import { module, test } from 'qunit';
import { visit, currentURL, click, find, fillIn } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import { authenticateSession } from 'ember-simple-auth/test-support';
import a11yAudit from 'ember-a11y-testing/test-support/audit';
import { Response } from 'miragejs';
module('Acceptance | managed-groups | create', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
const instances = {
scopes: {
global: null,
org: null,
},
authMethod: null,
managedGroup: null,
};
const urls = {
orgScope: null,
authMethods: null,
managedGroups: null,
newManagedGroup: null,
managedGroup: 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',
});
instances.managedGroup = this.server.create('managed-group', {
scope: instances.scopes.org,
authMethod: instances.authMethod,
});
// 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.newManagedGroup = `${urls.managedGroups}/new`;
urls.managedGroup = `${urls.managedGroups}/${instances.authMethod.id}`;
});
hooks.afterEach(async function () {
const notification = find('.rose-notification');
if (notification) {
await click('.rose-notification-dismiss');
}
});
test('visiting managed groups', async function (assert) {
assert.expect(1);
await visit(urls.managedGroups);
await a11yAudit();
assert.equal(currentURL(), urls.managedGroups);
});
test('can create a new managed group', async function (assert) {
assert.expect(1);
const managedGroupsCount = this.server.db.managedGroups.length;
await visit(urls.newManagedGroup);
await fillIn('[name="name"]', 'Managed group name');
await fillIn('[name="description"]', 'description');
await click('form [type="submit"]:not(:disabled)');
assert.equal(this.server.db.managedGroups.length, managedGroupsCount + 1);
});
test('User can not create a new managed group without proper authorization', async function (assert) {
assert.expect(2);
instances.authMethod.authorized_collection_actions['managed-groups'] = [];
await visit(urls.authMethod);
assert.notOk(
instances.authMethod.authorized_collection_actions[
'managed-groups'
].includes('create')
);
assert.notOk(
find(`.rose-layout-page-actions [href="${urls.newManagedGroup}"]`)
);
});
test('User can navigate to new managed group route with proper authorization', async function (assert) {
assert.expect(2);
await visit(urls.managedGroups);
assert.ok(
instances.authMethod.authorized_collection_actions[
'managed-groups'
].includes('create')
);
assert.ok(find(`[href="${urls.newManagedGroup}"]`));
});
test('User cannot navigate to new managed group route without proper authorization', async function (assert) {
assert.expect(2);
instances.authMethod.authorized_collection_actions['managed-groups'] = [];
await visit(urls.managedGroups);
assert.notOk(
instances.authMethod.authorized_collection_actions[
'managed-groups'
].includes('create')
);
assert.notOk(find(`[href="${urls.newManagedGroup}"]`));
});
test('User can cancel a new managed group creation', async function (assert) {
assert.expect(2);
const managedGroupsCount = this.server.db.managedGroups.length;
await visit(urls.newManagedGroup);
await fillIn('[name="name"]', 'Managed group name');
await click('form button:not([type="submit"])');
assert.equal(this.server.db.managedGroups.length, managedGroupsCount);
assert.equal(currentURL(), urls.managedGroups);
});
test('When user saving a new managed group with invalid fields displays error message', async function (assert) {
assert.expect(2);
this.server.post('/managed-groups', () => {
return new Response(
400,
{},
{
status: 400,
code: 'invalid_argument',
message: 'The request was invalid.',
details: {
request_fields: [
{
name: 'name',
description: 'Name is required.',
},
],
},
}
);
});
await visit(urls.newManagedGroup);
await fillIn('[name="name"]', 'new managed group');
await click('form [type="submit"]');
await a11yAudit();
assert.equal(
find('.rose-notification-body').textContent.trim(),
'The request was invalid.',
'Displays primary error message.'
);
assert.equal(
find('.rose-form-error-message').textContent.trim(),
'Name is required.',
'Displays field-level errors.'
);
});
});
@@ -0,0 +1,103 @@
import { module, test } from 'qunit';
import { visit, click, find } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import { authenticateSession } from 'ember-simple-auth/test-support';
import a11yAudit from 'ember-a11y-testing/test-support/audit';
import { Response } from 'miragejs';
module('Acceptance | managed-groups | delete', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
const instances = {
scopes: {
global: null,
org: null,
},
authMethod: null,
managedGroup: null,
};
const urls = {
orgScope: null,
authMethods: null,
managedGroups: null,
newManagedGroup: null,
managedGroup: 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',
});
instances.managedGroup = this.server.create('managed-group', {
scope: instances.scopes.org,
authMethod: instances.authMethod,
});
// 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.newManagedGroup = `${urls.managedGroups}/new`;
// TODO refactor in the rest of the test this url
urls.managedGroup = `${urls.managedGroups}/${instances.managedGroup.id}`;
});
hooks.afterEach(async function () {
const notification = find('.rose-notification');
if (notification) {
await click('.rose-notification-dismiss');
}
});
test('User can delete a managed group', async function (assert) {
assert.expect(1);
const managedGroupsCount = this.server.db.managedGroups.length;
await visit(urls.managedGroup);
await click('.rose-layout-page-actions .rose-dropdown-button-danger');
assert.equal(this.server.db.managedGroups.length, managedGroupsCount - 1);
});
test('User cannot delete a managed-group without proper authorization', async function (assert) {
assert.expect(1);
instances.managedGroup.authorized_actions =
instances.managedGroup.authorized_actions.filter(
(item) => item !== 'delete'
);
await visit(urls.managedGroup);
assert.notOk(
find('.rose-layout-page-actions .rose-dropdown-button-danger')
);
});
test('Errors are displayed when delete on managed group fails', async function (assert) {
assert.expect(1);
this.server.del('/managed-groups/:id', () => {
return new Response(
490,
{},
{
status: 490,
code: 'error',
message: 'Oops.',
}
);
});
await visit(urls.managedGroup);
await click('.rose-layout-page-actions .rose-dropdown-button-danger');
await a11yAudit();
assert.equal(
find('.rose-notification-body').textContent.trim(),
'Oops.',
'Displays primary error message.'
);
});
});
@@ -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 | members', 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,
managedGroupMembers: 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.managedGroupMembers = `${urls.managedGroup}/members`;
});
test('User can navigate to index', async function (assert) {
assert.expect(3);
const membersCount = instances.managedGroup.memberIds.length;
await visit(urls.managedGroupMembers);
await a11yAudit();
assert.equal(currentURL(), urls.managedGroupMembers);
assert.ok(membersCount);
assert.equal(findAll('tbody tr').length, membersCount);
});
});
@@ -0,0 +1,77 @@
import { module, test } from 'qunit';
import { visit, click, find, currentURL } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import { authenticateSession } from 'ember-simple-auth/test-support';
import a11yAudit from 'ember-a11y-testing/test-support/audit';
module('Acceptance | managed-groups | read', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
const instances = {
scopes: {
global: null,
org: null,
},
authMethod: null,
managedGroup: null,
};
const urls = {
orgScope: null,
authMethods: null,
managedGroups: null,
newManagedGroup: null,
managedGroup: 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',
});
instances.managedGroup = this.server.create('managed-group', {
scope: instances.scopes.org,
authMethod: instances.authMethod,
});
// 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.newManagedGroup = `${urls.managedGroups}/new`;
// TODO refactor in the rest of the test this url
urls.managedGroup = `${urls.managedGroups}/${instances.managedGroup.id}`;
});
hooks.afterEach(async function () {
const notification = find('.rose-notification');
if (notification) {
await click('.rose-notification-dismiss');
}
});
test('User can navigate to a managed group form', async function (assert) {
assert.expect(1);
await visit(urls.managedGroups);
await click('main tbody .rose-table-header-cell:nth-child(1) a');
await a11yAudit();
assert.equal(currentURL(), urls.managedGroup);
});
test('User cannot navigate to a managed group form without proper authorization', async function (assert) {
assert.expect(1);
instances.managedGroup.authorized_actions =
instances.managedGroup.authorized_actions.filter(
(item) => item !== 'read'
);
await visit(urls.managedGroups);
assert.notOk(find('main tbody .rose-table-header-cell:nth-child(1) a'));
});
});
@@ -0,0 +1,17 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module(
'Unit | Controller | scopes/scope/auth-methods/auth-method/managed-groups/managed-group/members',
function (hooks) {
setupTest(hooks);
// TODO: Replace this with your real tests.
test('it exists', function (assert) {
let controller = this.owner.lookup(
'controller:scopes/scope/auth-methods/auth-method/managed-groups/managed-group/members'
);
assert.ok(controller);
});
}
);
@@ -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/members',
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/members'
);
assert.ok(route);
});
}
);