\ No newline at end of file
diff --git a/ui/lib/pki/addon/components/pki-role-form.hbs b/ui/lib/pki/addon/components/pki-role-form.hbs
index 47ed59083..a412d0450 100644
--- a/ui/lib/pki/addon/components/pki-role-form.hbs
+++ b/ui/lib/pki/addon/components/pki-role-form.hbs
@@ -2,35 +2,70 @@
{{! ARG TODO write a test for namespace reminder }}
-
- {{#each @model.formFieldGroups as |fieldGroup|}}
+
+ {{#each @role.formFieldGroups as |fieldGroup|}}
{{#each-in fieldGroup as |group fields|}}
{{! DEFAULT VIEW }}
{{#if (eq group "default")}}
{{#each fields as |attr|}}
-
-
-
+ {{#if (eq attr.name "issuerRef")}}
+
+
+
+ Use default issuer
+
+
+ {{#unless this.showDefaultIssuer}}
+
+ {{/unless}}
+ {{else}}
+
+
+
+ {{/if}}
{{/each}}
{{else}}
{{#let (camelize (concat "show" group)) as |prop|}}
- {{#if (get @model prop)}}
+ {{#if (get @role prop)}}
- {{#let (get @model.fieldGroupsInfo group) as |toggleGroup|}}
+ {{#let (get @role.fieldGroupsInfo group) as |toggleGroup|}}
{{! HEADER }}
{{#if toggleGroup.header}}
@@ -44,16 +79,16 @@
{{/if}}
{{! FIELDS }}
{{#if (eq group "Key usage")}}
-
+
{{else if (eq group "Key parameters")}}
-
+
{{else}}
{{#each fields as |attr|}}
{{yield attr}}
@@ -87,7 +122,7 @@
disabled={{this.save.isRunning}}
data-test-pki-role-save
>
- {{if @model.isNew "Create" "Update"}}
+ {{if @role.isNew "Create" "Update"}}
{
+ return { issuerDisplayName: issuer.issuerName || issuer.issuerId };
+ });
+ }
get breadcrumbs() {
const crumbs = [
@@ -38,8 +53,8 @@ export default class PkiRoleForm extends Component {
{ label: this.secretMountPath.currentPath, route: 'overview' },
{ label: 'roles', route: 'roles.index' },
];
- if (!this.args.model.isNew) {
- crumbs.push({ label: this.args.model.id, route: 'roles.role.details' }, { label: 'edit' });
+ if (!this.args.role.isNew) {
+ crumbs.push({ label: this.args.role.id, route: 'roles.role.details' }, { label: 'edit' });
}
return crumbs;
}
@@ -48,12 +63,12 @@ export default class PkiRoleForm extends Component {
*save(event) {
event.preventDefault();
try {
- const { isValid, state, invalidFormMessage } = this.args.model.validate();
+ const { isValid, state, invalidFormMessage } = this.args.role.validate();
this.modelValidations = isValid ? null : state;
this.invalidFormAlert = invalidFormMessage;
if (isValid) {
- const { isNew, name } = this.args.model;
- yield this.args.model.save();
+ const { isNew, name } = this.args.role;
+ yield this.args.role.save();
this.flashMessages.success(`Successfully ${isNew ? 'created' : 'updated'} the role ${name}.`);
this.args.onSave();
}
@@ -63,4 +78,13 @@ export default class PkiRoleForm extends Component {
this.invalidFormAlert = 'There was an error submitting this form.';
}
}
+
+ @action
+ toggleShowDefaultIssuer() {
+ this.showDefaultIssuer = !this.showDefaultIssuer;
+
+ if (this.showDefaultIssuer) {
+ this.args.role.issuerRef = 'default';
+ }
+ }
}
diff --git a/ui/lib/pki/addon/routes/roles/create.js b/ui/lib/pki/addon/routes/roles/create.js
index 47838509d..ca9d09bd0 100644
--- a/ui/lib/pki/addon/routes/roles/create.js
+++ b/ui/lib/pki/addon/routes/roles/create.js
@@ -6,15 +6,18 @@
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import { withConfirmLeave } from 'core/decorators/confirm-leave';
+import { hash } from 'rsvp';
-@withConfirmLeave()
+@withConfirmLeave('model.role', ['model.issuers'])
export default class PkiRolesCreateRoute extends Route {
@service store;
@service secretMountPath;
model() {
- return this.store.createRecord('pki/role', {
- backend: this.secretMountPath.currentPath,
+ const backend = this.secretMountPath.currentPath;
+ return hash({
+ role: this.store.createRecord('pki/role', { backend }),
+ issuers: this.store.query('pki/issuer', { backend }),
});
}
diff --git a/ui/lib/pki/addon/routes/roles/role/edit.js b/ui/lib/pki/addon/routes/roles/role/edit.js
index ccb25db21..72f36a6f3 100644
--- a/ui/lib/pki/addon/routes/roles/role/edit.js
+++ b/ui/lib/pki/addon/routes/roles/role/edit.js
@@ -6,23 +6,31 @@
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import { withConfirmLeave } from 'core/decorators/confirm-leave';
+import { hash } from 'rsvp';
-@withConfirmLeave()
+@withConfirmLeave('model.role', ['model.issuers'])
export default class PkiRoleEditRoute extends Route {
@service store;
@service secretMountPath;
model() {
const { role } = this.paramsFor('roles/role');
- return this.store.queryRecord('pki/role', {
- backend: this.secretMountPath.currentPath,
- id: role,
+ const backend = this.secretMountPath.currentPath;
+
+ return hash({
+ role: this.store.queryRecord('pki/role', {
+ backend,
+ id: role,
+ }),
+ issuers: this.store.query('pki/issuer', { backend }),
});
}
setupController(controller, resolvedModel) {
super.setupController(controller, resolvedModel);
- const { id } = resolvedModel;
+ const {
+ role: { id },
+ } = resolvedModel;
controller.breadcrumbs = [
{ label: 'secrets', route: 'secrets', linkExternal: true },
{ label: this.secretMountPath.currentPath, route: 'overview' },
diff --git a/ui/lib/pki/addon/templates/roles/create.hbs b/ui/lib/pki/addon/templates/roles/create.hbs
index 437e6e739..17018893d 100644
--- a/ui/lib/pki/addon/templates/roles/create.hbs
+++ b/ui/lib/pki/addon/templates/roles/create.hbs
@@ -10,7 +10,9 @@
\ No newline at end of file
diff --git a/ui/lib/pki/addon/templates/roles/role/edit.hbs b/ui/lib/pki/addon/templates/roles/role/edit.hbs
index d67accb7d..5e86297e6 100644
--- a/ui/lib/pki/addon/templates/roles/role/edit.hbs
+++ b/ui/lib/pki/addon/templates/roles/role/edit.hbs
@@ -9,7 +9,8 @@
\ No newline at end of file
diff --git a/ui/tests/acceptance/pki/pki-engine-route-cleanup-test.js b/ui/tests/acceptance/pki/pki-engine-route-cleanup-test.js
index 1069b82ba..392505cf2 100644
--- a/ui/tests/acceptance/pki/pki-engine-route-cleanup-test.js
+++ b/ui/tests/acceptance/pki/pki-engine-route-cleanup-test.js
@@ -142,7 +142,8 @@ module('Acceptance | pki engine route cleanup test', function (hooks) {
// Edit role
await click(SELECTORS.editRoleLink);
- await fillIn(SELECTORS.roleForm.issuerRef, 'foobar');
+ await click(SELECTORS.roleForm.issuerRefToggle);
+ await fillIn(SELECTORS.roleForm.issuerRefSelect, 'foobar');
role = this.store.peekRecord('pki/role', roleId);
assert.true(role.hasDirtyAttributes, 'Role has dirty attrs');
// Exit page via cancel button
@@ -153,7 +154,8 @@ module('Acceptance | pki engine route cleanup test', function (hooks) {
// Edit again
await click(SELECTORS.editRoleLink);
- await fillIn(SELECTORS.roleForm.issuerRef, 'foobar2');
+ await click(SELECTORS.roleForm.issuerRefToggle);
+ await fillIn(SELECTORS.roleForm.issuerRefSelect, 'foobar2');
role = this.store.peekRecord('pki/role', roleId);
assert.true(role.hasDirtyAttributes, 'Role has dirty attrs');
// Exit page via breadcrumbs
diff --git a/ui/tests/helpers/pki/pki-role-form.js b/ui/tests/helpers/pki/pki-role-form.js
index 145f5f05b..605ee22d6 100644
--- a/ui/tests/helpers/pki/pki-role-form.js
+++ b/ui/tests/helpers/pki/pki-role-form.js
@@ -8,6 +8,8 @@ export const PKI_BASE_URL = `/vault/cluster/secrets/backend/pki/roles`;
export const SELECTORS = {
roleName: '[data-test-input="name"]',
issuerRef: '[data-test-input="issuerRef"]',
+ issuerRefSelect: '[data-test-select="issuerRef"]',
+ issuerRefToggle: '[data-test-toggle-label="issuerRef-toggle"]',
customTtl: '[data-test-field="customTtl"]',
backdateValidity: '[data-test-ttl-value="Backdate validity"]',
maxTtl: '[data-test-toggle-label="Max TTL"]',
diff --git a/ui/tests/integration/components/pki/pki-role-form-test.js b/ui/tests/integration/components/pki/pki-role-form-test.js
index bf4545114..99be4d585 100644
--- a/ui/tests/integration/components/pki/pki-role-form-test.js
+++ b/ui/tests/integration/components/pki/pki-role-form-test.js
@@ -19,8 +19,11 @@ module('Integration | Component | pki-role-form', function (hooks) {
hooks.beforeEach(function () {
this.store = this.owner.lookup('service:store');
- this.model = this.store.createRecord('pki/role');
- this.model.backend = 'pki';
+ this.role = this.store.createRecord('pki/role');
+ this.store.createRecord('pki/issuer', { issuerName: 'issuer-0', issuerId: 'abcd-efgh' });
+ this.store.createRecord('pki/issuer', { issuerName: 'issuer-1', issuerId: 'ijkl-mnop' });
+ this.issuers = this.store.peekAll('pki/issuer');
+ this.role.backend = 'pki';
this.onCancel = sinon.spy();
});
@@ -29,14 +32,15 @@ module('Integration | Component | pki-role-form', function (hooks) {
await render(
hbs`
`,
{ owner: this.engine }
);
- assert.dom(SELECTORS.issuerRef).exists('shows form-field issuer ref');
+ assert.dom(SELECTORS.issuerRefToggle).exists('shows issuer ref toggle');
assert.dom(SELECTORS.backdateValidity).exists('shows form-field backdate validity');
assert.dom(SELECTORS.customTtl).exists('shows custom yielded form field');
assert.dom(SELECTORS.maxTtl).exists('shows form-field max ttl');
@@ -54,7 +58,7 @@ module('Integration | Component | pki-role-form', function (hooks) {
test('it should save a new pki role with various options selected', async function (assert) {
// Key usage, Key params and Not valid after options are tested in their respective component tests
assert.expect(9);
- this.server.post(`/${this.model.backend}/roles/test-role`, (schema, req) => {
+ this.server.post(`/${this.role.backend}/roles/test-role`, (schema, req) => {
assert.ok(true, 'Request made to save role');
const request = JSON.parse(req.requestBody);
const allowedDomainsTemplate = request.allowed_domains_template;
@@ -78,7 +82,8 @@ module('Integration | Component | pki-role-form', function (hooks) {
await render(
hbs`
@@ -87,6 +92,7 @@ module('Integration | Component | pki-role-form', function (hooks) {
);
await click(SELECTORS.roleCreateButton);
+
assert
.dom(SELECTORS.roleName)
.hasClass('has-error-border', 'shows border error on role name field when no role name is submitted');
@@ -120,6 +126,7 @@ module('Integration | Component | pki-role-form', function (hooks) {
test('it should update attributes on the model on update', async function (assert) {
assert.expect(1);
+
this.store.pushPayload('pki/role', {
modelName: 'pki/role',
name: 'test-role',
@@ -127,21 +134,22 @@ module('Integration | Component | pki-role-form', function (hooks) {
id: 'role-id',
});
- this.model = this.store.peekRecord('pki/role', 'role-id');
+ this.role = this.store.peekRecord('pki/role', 'role-id');
await render(
hbs`
`,
{ owner: this.engine }
);
-
- await fillIn(SELECTORS.issuerRef, 'not-default');
+ await click(SELECTORS.issuerRefToggle);
+ await fillIn(SELECTORS.issuerRefSelect, 'issuer-1');
await click(SELECTORS.roleCreateButton);
- assert.strictEqual(this.model.issuerRef, 'not-default', 'Issuer Ref correctly saved on create');
+ assert.strictEqual(this.role.issuerRef, 'issuer-1', 'Issuer Ref correctly saved on create');
});
});