diff --git a/ui/app/components/secret-link.js b/ui/app/components/secret-link.js index d3b05afac..30c516a19 100644 --- a/ui/app/components/secret-link.js +++ b/ui/app/components/secret-link.js @@ -2,23 +2,6 @@ import { computed } from '@ember/object'; import Component from '@ember/component'; import { encodePath } from 'vault/utils/path-encoding-helpers'; -export function linkParams({ mode, secret, queryParams }) { - let params; - const route = `vault.cluster.secrets.backend.${mode}`; - - if ((mode !== 'versions' && !secret) || secret === ' ') { - params = [route + '-root']; - } else { - params = [route, encodePath(secret)]; - } - - if (queryParams) { - params.push(queryParams); - } - - return params; -} - export default Component.extend({ onLinkClick() {}, tagName: '', @@ -30,8 +13,16 @@ export default Component.extend({ queryParams: null, ariaLabel: null, - linkParams: computed('mode', 'secret', 'queryParams', function () { - let data = { mode: this.mode, secret: this.secret, queryParams: this.queryParams }; - return linkParams(data); + link: computed('mode', 'secret', function () { + const route = `vault.cluster.secrets.backend.${this.mode}`; + if ((this.mode !== 'versions' && !this.secret) || this.secret === ' ') { + return { route: `${route}-root`, models: [] }; + } else { + return { route, models: [encodePath(this.secret)] }; + } + }), + query: computed('queryParams', function () { + const qp = this.queryParams || {}; + return qp.isQueryParams ? qp.values : qp; }), }); diff --git a/ui/app/services/permissions.js b/ui/app/services/permissions.js index eab830c40..6fe090240 100644 --- a/ui/app/services/permissions.js +++ b/ui/app/services/permissions.js @@ -36,12 +36,12 @@ const API_PATHS = { }; const API_PATHS_TO_ROUTE_PARAMS = { - 'sys/auth': ['vault.cluster.access.methods'], - 'identity/entity/id': ['vault.cluster.access.identity', 'entities'], - 'identity/group/id': ['vault.cluster.access.identity', 'groups'], - 'sys/leases/lookup': ['vault.cluster.access.leases'], - 'sys/namespaces': ['vault.cluster.access.namespaces'], - 'sys/control-group/': ['vault.cluster.access.control-groups'], + 'sys/auth': { route: 'vault.cluster.access.methods', models: [] }, + 'identity/entity/id': { route: 'vault.cluster.access.identity', models: ['entities'] }, + 'identity/group/id': { route: 'vault.cluster.access.identity', models: ['groups'] }, + 'sys/leases/lookup': { route: 'vault.cluster.access.leases', models: [] }, + 'sys/namespaces': { route: 'vault.cluster.access.namespaces', models: [] }, + 'sys/control-group/': { route: 'vault.cluster.access.control-groups', models: [] }, }; /* @@ -99,7 +99,7 @@ export default Service.extend({ navPathParams(navItem) { const path = Object.values(API_PATHS[navItem]).find((path) => this.hasPermission(path)); if (['policies', 'tools'].includes(navItem)) { - return path.split('/').lastObject; + return { models: [path.split('/').lastObject] }; } return API_PATHS_TO_ROUTE_PARAMS[path]; diff --git a/ui/app/templates/components/generated-item-list.hbs b/ui/app/templates/components/generated-item-list.hbs index ac13f27d1..aa8d9c264 100644 --- a/ui/app/templates/components/generated-item-list.hbs +++ b/ui/app/templates/components/generated-item-list.hbs @@ -23,13 +23,11 @@ @@ -61,14 +59,10 @@ this.itemType }} will be listed here. Create your first {{this.itemType}} to get started." > - {{! template-lint-configure no-curly-component-invocation "warn" }} - {{! template-lint-configure no-link-to-positional-params "warn" }} - {{#link-to "vault.cluster.access.method.item.create" this.itemType class="link"}} + Create {{singularize this.itemType}} - {{/link-to}} - {{! template-lint-configure no-curly-component-invocation "on" }} - {{! template-lint-configure no-link-to-positional-params "on" }} + {{else if list.item}} @@ -77,20 +71,16 @@
  • - {{! template-lint-configure no-curly-component-invocation "warn" }} - {{! template-lint-configure no-link-to-positional-params "warn" }} - {{#link-to "vault.cluster.access.method.item.show" list.item.id class="is-block"}} + View {{singularize this.itemType}} - {{/link-to}} +
  • - {{#link-to "vault.cluster.access.method.item.edit" list.item.id class="is-block"}} + Edit {{singularize this.itemType}} - {{/link-to}} - {{! template-lint-configure no-curly-component-invocation "on" }} - {{! template-lint-configure no-link-to-positional-params "on" }} +
  • {{yield}} -{{/link-to}} \ No newline at end of file + \ No newline at end of file diff --git a/ui/app/templates/components/secret-version-menu.hbs b/ui/app/templates/components/secret-version-menu.hbs index e2b17e298..1d769bf4d 100644 --- a/ui/app/templates/components/secret-version-menu.hbs +++ b/ui/app/templates/components/secret-version-menu.hbs @@ -46,7 +46,7 @@ @mode="versions" @secret={{@model.id}} @class="has-text-black has-text-weight-semibold has-bottom-shadow" - @onLinkClick={{action D.actions.close}} + @onLinkClick={{D.actions.close}} > View version history diff --git a/ui/app/templates/components/section-tabs.hbs b/ui/app/templates/components/section-tabs.hbs index 20b48ef26..41f207dd2 100644 --- a/ui/app/templates/components/section-tabs.hbs +++ b/ui/app/templates/components/section-tabs.hbs @@ -4,13 +4,11 @@ diff --git a/ui/app/templates/vault/cluster.hbs b/ui/app/templates/vault/cluster.hbs index b4c7be88c..0b6d8f815 100644 --- a/ui/app/templates/vault/cluster.hbs +++ b/ui/app/templates/vault/cluster.hbs @@ -13,51 +13,52 @@
  • {{/if}}
  • - {{! template-lint-configure no-curly-component-invocation "warn" }} - {{! template-lint-configure no-link-to-positional-params "warn" }} - {{#link-to - "vault.cluster.secrets" - current-when="vault.cluster.secrets vault.cluster.settings.mount-secret-backend vault.cluster.settings.configure-secret-backend" - invokeAction=(action Nav.closeDrawer) + Secrets - {{/link-to}} +
  • {{#if (has-permission "access")}}
  • - {{#link-to - params=(route-params-for "access") - current-when="vault.cluster.access vault.cluster.settings.auth" - invokeAction=(action Nav.closeDrawer) + Access - {{/link-to}} +
  • {{/if}} {{#if (has-permission "policies")}}
  • - {{#link-to - "vault.cluster.policies" - (route-params-for "policies") - current-when="vault.cluster.policies vault.cluster.policy" - invokeAction=(action Nav.closeDrawer) + Policies - {{/link-to}} +
  • {{/if}} {{#if (has-permission "tools")}}
  • - {{#link-to "vault.cluster.tools.tool" (route-params-for "tools") invokeAction=(action Nav.closeDrawer)}} + Tools - {{/link-to}} +
  • {{/if}} - {{! template-lint-configure no-curly-component-invocation "on" }} - {{! template-lint-configure no-link-to-positional-params "on" }} @@ -73,17 +74,13 @@ )}} {{/if}} diff --git a/ui/app/templates/vault/cluster/access/leases/list.hbs b/ui/app/templates/vault/cluster/access/leases/list.hbs index d1e4ccc2d..d6894bbaa 100644 --- a/ui/app/templates/vault/cluster/access/leases/list.hbs +++ b/ui/app/templates/vault/cluster/access/leases/list.hbs @@ -105,6 +105,6 @@ @page={{this.model.meta.currentPage}} @lastPage={{this.model.meta.lastPage}} @link={{concat "vault.cluster.access.leases.list" (unless this.baseKey.id "-root")}} - @model={{compact (array (if this.baseKey.id this.baseKey.id))}} + @models={{compact (array (if this.baseKey.id this.baseKey.id))}} /> {{/if}} \ No newline at end of file diff --git a/ui/app/templates/vault/cluster/secrets/backend/error.hbs b/ui/app/templates/vault/cluster/secrets/backend/error.hbs index b381eec62..504403a90 100644 --- a/ui/app/templates/vault/cluster/secrets/backend/error.hbs +++ b/ui/app/templates/vault/cluster/secrets/backend/error.hbs @@ -3,16 +3,10 @@ @@ -33,16 +27,10 @@

    Unable to find secret at {{concat this.model.backend "/" this.model.secret}}. Try going back to the - {{! template-lint-configure no-curly-component-invocation "warn" }} - {{! template-lint-configure no-link-to-positional-params "warn" }} - {{#link-to - params=(if this.model.backend (array "vault.cluster.secrets.backend.list-root") (array "vault.cluster.secrets")) - }} + root - {{/link-to}} + and navigating from there. - {{! template-lint-configure no-curly-component-invocation "on" }} - {{! template-lint-configure no-link-to-positional-params "on" }}

    {{else if (eq this.model.httpStatus 403)}} {{#if (eq this.model.policyPath "sys/capabilities-self")}} diff --git a/ui/app/templates/vault/cluster/secrets/backend/list.hbs b/ui/app/templates/vault/cluster/secrets/backend/list.hbs index 19363ad5c..45014865d 100644 --- a/ui/app/templates/vault/cluster/secrets/backend/list.hbs +++ b/ui/app/templates/vault/cluster/secrets/backend/list.hbs @@ -124,7 +124,7 @@ @page={{this.model.meta.currentPage}} @lastPage={{this.model.meta.lastPage}} @link={{concat "vault.cluster.secrets.backend.list" (unless this.baseKey.id "-root")}} - @model={{compact (array this.backend (if this.baseKey.id this.baseKey.id))}} + @models={{compact (array this.backend (if this.baseKey.id this.baseKey.id))}} /> {{/if}} {{else}} diff --git a/ui/lib/core/addon/components/form-save-buttons.js b/ui/lib/core/addon/components/form-save-buttons.js index 0387bafa2..978796de1 100644 --- a/ui/lib/core/addon/components/form-save-buttons.js +++ b/ui/lib/core/addon/components/form-save-buttons.js @@ -1,4 +1,5 @@ import Component from '@ember/component'; +import { computed } from '@ember/object'; import layout from '../templates/components/form-save-buttons'; /** @@ -23,4 +24,10 @@ import layout from '../templates/components/form-save-buttons'; export default Component.extend({ layout, tagName: '', + + cancelLink: computed('cancelLinkParams.[]', function () { + if (!Array.isArray(this.cancelLinkParams) || !this.cancelLinkParams.length) return; + const [route, ...models] = this.cancelLinkParams; + return { route, models }; + }), }); diff --git a/ui/lib/core/addon/components/list-item.js b/ui/lib/core/addon/components/list-item.js index 3de2043b2..2f379ecfb 100644 --- a/ui/lib/core/addon/components/list-item.js +++ b/ui/lib/core/addon/components/list-item.js @@ -1,6 +1,7 @@ import { inject as service } from '@ember/service'; import Component from '@ember/component'; import { task } from 'ember-concurrency'; +import { computed } from '@ember/object'; import layout from '../templates/components/list-item'; export default Component.extend({ @@ -24,4 +25,9 @@ export default Component.extend({ model.rollbackAttributes(); } }), + link: computed('linkParams.[]', function () { + if (!Array.isArray(this.linkParams) || !this.linkParams.length) return {}; + const [route, ...models] = this.linkParams; + return { route, models }; + }), }); diff --git a/ui/lib/core/addon/components/list-pagination.js b/ui/lib/core/addon/components/list-pagination.js index ba7ebab9b..f41c90127 100644 --- a/ui/lib/core/addon/components/list-pagination.js +++ b/ui/lib/core/addon/components/list-pagination.js @@ -2,6 +2,7 @@ import { gt } from '@ember/object/computed'; import Component from '@ember/component'; import { computed } from '@ember/object'; import { range } from 'ember-composable-helpers/helpers/range'; +import { A } from '@ember/array'; import layout from '../templates/components/list-pagination'; export default Component.extend({ @@ -10,7 +11,7 @@ export default Component.extend({ page: null, lastPage: null, link: null, - model: null, + models: A(), // number of links to show on each side of page spread: 2, hasNext: computed('page', 'lastPage', function () { diff --git a/ui/lib/core/addon/templates/components/form-save-buttons.hbs b/ui/lib/core/addon/templates/components/form-save-buttons.hbs index ffc9f82ed..846b082c0 100644 --- a/ui/lib/core/addon/templates/components/form-save-buttons.hbs +++ b/ui/lib/core/addon/templates/components/form-save-buttons.hbs @@ -10,13 +10,11 @@ {{or @saveButtonText "Save"}} - {{#if @cancelLinkParams}} + {{#if this.cancelLink}}
    - {{! refactor to use @route and @model args and convert to angle brackets }} - {{! template-lint-configure no-curly-component-invocation "warn" }} - {{#link-to params=@cancelLinkParams class="button"}} + {{or @cancelButtonText "Cancel"}} - {{/link-to}} +
    {{/if}} {{#if @onCancel}} diff --git a/ui/lib/core/addon/templates/components/list-item.hbs b/ui/lib/core/addon/templates/components/list-item.hbs index b7e38b007..ca5c0153b 100644 --- a/ui/lib/core/addon/templates/components/list-item.hbs +++ b/ui/lib/core/addon/templates/components/list-item.hbs @@ -10,14 +10,13 @@ >
    - {{! refactor to use @route and @model args and convert to angle brackets }} - {{! template-lint-configure no-curly-component-invocation "warn" }} - {{#link-to - params=this.linkParams + {{yield (hash content=(component "list-item/content"))}} - {{/link-to}} +
    diff --git a/ui/lib/core/addon/templates/components/list-pagination.hbs b/ui/lib/core/addon/templates/components/list-pagination.hbs index 34c7be942..73068d0e8 100644 --- a/ui/lib/core/addon/templates/components/list-pagination.hbs +++ b/ui/lib/core/addon/templates/components/list-pagination.hbs @@ -1,86 +1,89 @@ -{{! warn is not working! }} -{{! template-lint-disable no-curly-component-invocation }} -{{#with (compact (flatten (array this.link this.model))) as |params|}} - \ No newline at end of file diff --git a/ui/lib/kmip/addon/components/edit-form-kmip-role.js b/ui/lib/kmip/addon/components/edit-form-kmip-role.js index 45463e82f..3de03f8f8 100644 --- a/ui/lib/kmip/addon/components/edit-form-kmip-role.js +++ b/ui/lib/kmip/addon/components/edit-form-kmip-role.js @@ -1,10 +1,17 @@ import EditForm from 'core/components/edit-form'; +import { computed } from '@ember/object'; import layout from '../templates/components/edit-form-kmip-role'; export default EditForm.extend({ layout, model: null, + cancelLink: computed('cancelLinkParams.[]', function () { + if (!Array.isArray(this.cancelLinkParams) || !this.cancelLinkParams.length) return; + const [route, ...models] = this.cancelLinkParams; + return { route, models }; + }), + init() { this._super(...arguments); diff --git a/ui/lib/kmip/addon/templates/components/edit-form-kmip-role.hbs b/ui/lib/kmip/addon/templates/components/edit-form-kmip-role.hbs index 68a9eac08..faff4b8d8 100644 --- a/ui/lib/kmip/addon/templates/components/edit-form-kmip-role.hbs +++ b/ui/lib/kmip/addon/templates/components/edit-form-kmip-role.hbs @@ -90,13 +90,16 @@ {{this.saveButtonText}}
    - {{#if this.cancelLinkParams}} + {{#if this.cancelLink}}
    - {{! refactor to use @route and @model args and convert to angle brackets }} - {{! template-lint-configure no-curly-component-invocation "warn" }} - {{#link-to params=this.cancelLinkParams class="button" data-test-edit-form-cancel="true"}} + Cancel - {{/link-to}} +
    {{/if}}
    diff --git a/ui/tests/unit/services/permissions-test.js b/ui/tests/unit/services/permissions-test.js index 06c8680ae..383ea2ebb 100644 --- a/ui/tests/unit/services/permissions-test.js +++ b/ui/tests/unit/services/permissions-test.js @@ -139,7 +139,7 @@ module('Unit | Service | permissions', function (hooks) { }, }; service.set('exactPaths', policyPaths); - assert.equal(service.navPathParams('policies'), 'rgp'); + assert.equal(service.navPathParams('policies').models[0], 'rgp'); }); test('returns the first allowed nav route for access', function (assert) { @@ -152,7 +152,7 @@ module('Unit | Service | permissions', function (hooks) { capabilities: ['read'], }, }; - const expected = ['vault.cluster.access.identity', 'entities']; + const expected = { route: 'vault.cluster.access.identity', models: ['entities'] }; service.set('exactPaths', accessPaths); assert.deepEqual(service.navPathParams('access'), expected); });