fix: 🐛 spelling, merge conflicts

This commit is contained in:
dharini committed 2021-07-27 08:31:25 -07:00
commit cd9f05962c
18 files changed
+506 -12

No files matched your search

@@ -0,0 +1,55 @@
{{#if this.hasAvailableCredentialLibraries}}
<Rose::Form
class='full-width'
@onSubmit={{fn this.submit @submit}}
@cancel={{@cancel}}
@disabled={{@model.isSaving}}
@error={{@model.errors.base}}
as |form|
>
<form.actions
@submitText={{t 'resources.target.actions.add-credential-libraries'}}
@cancelText={{t 'actions.cancel'}}
/>
<Rose::Table as |table|>
<table.header as |header|>
<header.row as |row|>
<row.headerCell>{{t 'form.id.label'}}</row.headerCell>
<row.headerCell>{{t 'form.name.label'}}</row.headerCell>
</header.row>
</table.header>
<table.body as |body|>
{{#each this.filteredCredentialLibraries as |credentialLibrary|}}
<body.row as |row|>
<row.headerCell>
<form.checkbox
@label={{credentialLibrary.id}}
@description={{credentialLibrary.description}}
onChange={{fn this.toggleCredentialLibrary credentialLibrary}}
/>
</row.headerCell>
<row.cell>{{credentialLibrary.name}}</row.cell>
</body.row>
{{/each}}
</table.body>
</Rose::Table>
</Rose::Form>
{{/if}}
{{#unless this.hasAvailableCredentialLibraries}}
<Rose::Layout::Centered>
<Rose::Message
@title={{t 'resources.target.credential-library.messages.none.title'}}
as |message|
>
<message.description>
{{t 'resources.target.credential-library.messages.none.description'}}
</message.description>
<message.link @route='scopes.scope.targets.target.credential-libraries'>
<Rose::Icon @name='chevron-left' />
{{t 'actions.back'}}
</message.link>
</Rose::Message>
</Rose::Layout::Centered>
{{/unless}}
@@ -0,0 +1,65 @@
import Component from '@glimmer/component';
import { computed, action } from '@ember/object';
import { A } from '@ember/array';
export default class FormTargetAddCredentialLibrariesIndexComponent extends Component {
// =properties
/**
* Array of selected credential library IDs.
* @type {EmberArray}
*/
selectedCredentialLibraryIDs = A();
/**
* Checks for unassigned credential libraries.
* @param {[CredentialLibraryModel]} filteredCredentialLibraries
* @type {boolean}
*/
@computed('filteredCredentialLibraries.length')
get hasAvailableCredentialLibraries() {
return this.filteredCredentialLibraries.length > 0;
}
/**
* Filter out credential libraries not already added to the target.
* @type {[CredentialLibraryModel]}
*/
@computed(
'args.{credentialLibraries.[],model.application_credential_library_ids.[]}'
)
get filteredCredentialLibraries() {
// Get IDs for credential libraries already added to the current target
const currentCredentialLibraryIDs =
this.args.model.application_credential_library_ids.map(
(credentialLibrary) => credentialLibrary.value
);
const notAddedCredentialLibraries = this.args.credentialLibraries.filter(
({ id }) => !currentCredentialLibraryIDs.includes(id)
);
return notAddedCredentialLibraries;
}
// =actions
/**
* Add/Remove credential library to current selection
* @param CredentialLibraryModel
*/
@action
toggleCredentialLibrary(credentialLibrary) {
if (!this.selectedCredentialLibraryIDs.includes(credentialLibrary.id)) {
this.selectedCredentialLibraryIDs.addObject(credentialLibrary.id);
} else {
this.selectedCredentialLibraryIDs.removeObject(credentialLibrary.id);
}
}
/**
* Submit selected credential library ids
*/
@action
submit(fn) {
fn(this.selectedCredentialLibraryIDs);
}
}
@@ -0,0 +1,18 @@
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
export default class ScopesScopeTargetsTargetCredentialLibrariesController extends Controller {
// =services
@service intl;
// =attributes
/**
* Translated credential library breadcrumb
* @type {string}
*/
get breadCrumb() {
return this.intl.t('resources.credential-library.title_plural');
}
}
+2
View File
@@ -65,6 +65,8 @@ Router.map(function () {
this.route('target', { path: ':target_id' }, function () {
this.route('host-sets', function () {});
this.route('add-host-sets');
this.route('credential-libraries');
this.route('add-credential-libraries');
});
this.route('new');
});
@@ -0,0 +1,94 @@
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import { all } from 'rsvp';
import { action } from '@ember/object';
import loading from 'ember-loading/decorator';
import { notifySuccess, notifyError } from 'core/decorators/notify';
export default class ScopesScopeTargetsTargetAddCredentialLibrariesRoute extends Route {
// =services
@service intl;
@service notify;
// =methods
/**
* Empty out any previously loaded credential libraries.
*/
beforeModel() {
this.store.unloadAll('credential-library');
}
/**
* Returns the current target and all credential libraries.
* @return {{target: TargetModel, credentialLibraries: [CredentialLibraryModel]}}
*/
async model() {
const target = this.modelFor('scopes.scope.targets.target');
const { id: scope_id } = this.modelFor('scopes.scope');
const credentialStores = await this.store.query('credential-store', {
scope_id,
});
await all(
credentialStores.map(({ id: credential_store_id }) =>
this.store.query('credential-library', { credential_store_id })
)
);
const credentialLibraries = this.store.peekAll('credential-library');
return {
target,
credentialLibraries,
};
}
/**
* Renders credential libraries specific header template.
* @override
*/
renderTemplate() {
super.renderTemplate(...arguments);
this.render(
'scopes/scope/targets/target/add-credential-libraries/-header',
{
into: 'scopes/scope/targets/target',
outlet: 'header',
}
);
this.render('-empty', {
into: 'scopes/scope/targets/target',
outlet: 'navigation',
});
this.render('-empty', {
into: 'scopes/scope/targets/target',
outlet: 'actions',
});
}
// =actions
/**
* Add credential libraries to current target
* @param {TargetModel} target
* @param {[string]} credentialLibraryIDs
*/
@action
@loading
@notifyError(({ message }) => message, { catch: true })
@notifySuccess('notifications.add-success')
async save(target, credentialLibraryIDs) {
await target.addCredentialLibraries(credentialLibraryIDs);
this.replaceWith('scopes.scope.targets.target.credential-libraries');
}
/**
* Redirect to target credential libraries as if nothing ever happened.
*/
@action
cancel() {
this.replaceWith('scopes.scope.targets.target.credential-libraries');
}
}
@@ -0,0 +1,34 @@
import Route from '@ember/routing/route';
import { hash, all } from 'rsvp';
export default class ScopesScopeTargetsTargetCredentialLibrariesRoute extends Route {
// =methods
/**
* Loads all credential libraries under the current target.
* @return {Promise{[CredentialLibraryModel]}}
*/
beforeModel() {
const { application_credential_library_ids: credential_libraries } =
this.modelFor('scopes.scope.targets.target');
return hash({
credentialLibraries: all(
credential_libraries.map((credential_library) =>
this.store.findRecord(
'credential-library',
credential_library.value,
{ reload: true }
)
)
),
});
}
/**
* Returns the previously loaded target instance.
* @return {TargetModel}
*/
model() {
return this.modelFor('scopes.scope.targets.target');
}
}
+1 -1
View File
@@ -85,7 +85,7 @@
</nav.link>
{{#if (feature-flag 'credential-store')}}
<nav.link @route='scopes.scope.credential-stores'>
<Rose::Icon @name='app-icons/credential' @size='medium' />
<Rose::Icon @name='app-icons/credentials' @size='medium' />
{{t 'resources.credential-store.title_plural'}}
</nav.link>
{{/if}}
@@ -6,6 +6,13 @@
<dropdown.link @route='scopes.scope.targets.target.add-host-sets'>
{{t 'resources.target.actions.add-host-sets'}}
</dropdown.link>
{{#if (feature-flag 'credential-store')}}
<dropdown.link
@route='scopes.scope.targets.target.add-credential-libraries'
>
{{t 'resources.target.actions.add-credential-libraries'}}
</dropdown.link>
{{/if}}
<dropdown.separator />
<dropdown.button
@style='danger'
@@ -5,4 +5,9 @@
<nav.link @route='scopes.scope.targets.target.host-sets'>
{{t 'resources.host-set.title_plural'}}
</nav.link>
{{#if (feature-flag 'credential-store')}}
<nav.link @route='scopes.scope.targets.target.credential-libraries'>
{{t 'resources.credential-library.title_plural'}}
</nav.link>
{{/if}}
</Rose::Nav::Tabs>
@@ -0,0 +1,27 @@
{{page-title (t 'resources.target.actions.add-credential-libraries')}}
{{#if @model.credentialLibraries}}
<Form::Target::AddCredentialLibraries
@model={{@model.target}}
@credentialLibraries={{@model.credentialLibraries}}
@submit={{route-action 'save' @model.target}}
@cancel={{route-action 'cancel'}}
/>
{{/if}}
{{#unless @model.credentialLibraries}}
<Rose::Layout::Centered>
<Rose::Message
@title={{t 'resources.target.credential-library.messages.none.title'}}
as |message|
>
<message.description>
{{t 'resources.target.credential-library.messages.none.description'}}
</message.description>
<message.link @route='scopes.scope.targets.target.credential-libraries'>
<Rose::Icon @name='chevron-left' />
{{t 'actions.back'}}
</message.link>
</Rose::Message>
</Rose::Layout::Centered>
{{/unless}}
@@ -0,0 +1,4 @@
<h2>
{{t 'resources.target.credential-library.messages.add.title'}}
</h2>
<p>{{t 'resources.target.credential-library.messages.add.description'}}</p>
@@ -0,0 +1,54 @@
{{page-title (t 'resources.credential-library.title_plural')}}
{{#if @model.credentialLibraries}}
<Rose::Table as |table|>
<table.header as |header|>
<header.row as |row|>
<row.headerCell>{{t 'form.name.label'}}</row.headerCell>
<row.headerCell>{{t 'form.id.label'}}</row.headerCell>
</header.row>
</table.header>
<table.body as |body|>
{{#each @model.credentialLibraries as |credentialLibrary|}}
<body.row as |row|>
<row.headerCell>
<LinkTo
@route='scopes.scope.credential-stores.credential-store.credential-libraries.credential-library'
@models={{array
credentialLibrary.credential_store_id
credentialLibrary.id
}}
>
{{credentialLibrary.displayName}}
</LinkTo>
<p>{{credentialLibrary.description}}</p>
</row.headerCell>
<row.cell>
<Copyable
@text={{credentialLibrary.id}}
@buttonText={{t 'actions.copy-to-clipboard'}}
@acknowledgeText={{t 'states.copied'}}
>
<code>{{credentialLibrary.id}}</code>
</Copyable>
</row.cell>
</body.row>
{{/each}}
</table.body>
</Rose::Table>
{{else}}
<Rose::Layout::Centered>
<Rose::Message
@title={{t 'resources.target.credential-library.messages.welcome.title'}}
as |message|
>
<message.description>
{{t 'resources.target.credential-library.messages.welcome.description'}}
</message.description>
</Rose::Message>
</Rose::Layout::Centered>
{{/if}}
@@ -1,9 +1,10 @@
import { module, test } from 'qunit';
import { visit, currentURL, find, click } from '@ember/test-helpers';
import { visit, click, fillIn, currentURL, find } 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 } from 'ember-simple-auth/test-support';
import { Response } from 'miragejs';
import { resolve, reject } from 'rsvp';
import sinon from 'sinon';
@@ -58,6 +59,7 @@ module('Acceptance | credential-library', function (hooks) {
urls.credentialStore = `${urls.credentialStores}/${instances.credentialStore.id}`;
urls.credentialLibraries = `${urls.credentialStore}/credential-libraries`;
urls.credentialLibrary = `${urls.credentialLibraries}/${instances.credentialLibrary.id}`;
urls.newCredentialLibrary = `${urls.credentialLibraries}/new`;
urls.unknownCredentialLibrary = `${urls.credentialLibraries}/foo`;
// Generate resource couner
getCredentialLibraryCount = () =>
@@ -65,7 +67,7 @@ module('Acceptance | credential-library', function (hooks) {
authenticateSession({});
});
test('visiting credential-libraries', async function (assert) {
test('visiting credential libraries', async function (assert) {
assert.expect(2);
await visit(urls.credentialLibraries);
await a11yAudit();
@@ -75,7 +77,7 @@ module('Acceptance | credential-library', function (hooks) {
assert.equal(currentURL(), urls.credentialLibrary);
});
test('visiting an unknown credentila library displays 404 message', async function (assert) {
test('visiting an unknown credential library displays 404 message', async function (assert) {
assert.expect(1);
await visit(urls.unknownCredentialLibrary);
await a11yAudit();
@@ -83,6 +85,58 @@ module('Acceptance | credential-library', function (hooks) {
assert.ok(find('.rose-message-subtitle').textContent.trim(), 'Error 404');
});
test('can create a credential library', async function (assert) {
assert.expect(1);
const count = getCredentialLibraryCount();
await visit(urls.newCredentialLibrary);
await fillIn('[name="name"]', 'random string');
await click('[type="submit"]');
assert.equal(getCredentialLibraryCount(), count + 1);
});
test('can cancel create a new credential library', async function (assert) {
assert.expect(2);
const count = getCredentialLibraryCount();
await visit(urls.newCredentialLibrary);
await fillIn('[name="name"]', 'random string');
await click('.rose-form-actions [type="button"]');
assert.equal(currentURL(), urls.credentialLibraries);
assert.equal(getCredentialLibraryCount(), count);
});
test('saving a new credential library with invalid fields displays error messasges', async function (assert) {
assert.expect(2);
this.server.post('/credential-libraries', () => {
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.newCredentialLibrary);
await click('[type="submit"]');
assert.ok(
find('[role="alert"]').textContent.trim(),
'The request was invalid.'
);
assert.ok(
find('.rose-form-error-message').textContent.trim(),
'Name is required.'
);
});
test('can delete credential library', async function (assert) {
assert.expect(1);
const count = getCredentialLibraryCount();
@@ -114,4 +168,22 @@ module('Acceptance | credential-library', function (hooks) {
assert.equal(getCredentialLibraryCount(), count);
assert.ok(confirmService.confirm.calledOnce);
});
test('deleting a credential library which errors displays error messages', async function (assert) {
assert.expect(1);
this.server.del('/credential-libraries/:id', () => {
return new Response(
490,
{},
{
status: 490,
code: 'error',
message: 'Oops.',
}
);
});
await visit(urls.credentialLibrary);
await click('.rose-layout-page-actions .rose-dropdown-button-danger');
assert.ok(find('[role="alert"]').textContent.trim(), 'Oops.');
});
});
@@ -0,0 +1,17 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module(
'Unit | Controller | scopes/scope/targets/target/credential-libraries',
function (hooks) {
setupTest(hooks);
// TODO: Replace this with your real tests.
test('it exists', function (assert) {
let controller = this.owner.lookup(
'controller:scopes/scope/targets/target/credential-libraries'
);
assert.ok(controller);
});
}
);
@@ -0,0 +1,16 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module(
'Unit | Route | scopes/scope/targets/target/add-credential-libraries',
function (hooks) {
setupTest(hooks);
test('it exists', function (assert) {
let route = this.owner.lookup(
'route:scopes/scope/targets/target/add-credential-libraries'
);
assert.ok(route);
});
}
);
@@ -0,0 +1,16 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module(
'Unit | Route | scopes/scope/targets/target/credential-libraries',
function (hooks) {
setupTest(hooks);
test('it exists', function (assert) {
let route = this.owner.lookup(
'route:scopes/scope/targets/target/credential-libraries'
);
assert.ok(route);
});
}
);