From d6ab7bcd54702c89dcd5dc6f5dfd2bc6eb3a417b Mon Sep 17 00:00:00 2001 From: Matthew Irish Date: Wed, 22 Aug 2018 11:13:28 -0500 Subject: [PATCH] UI namespace additions (#5150) * add switch link on namespace link page if user has access to the namespace * refresh list when you delete, only show manage if you can list * fix bug where disconnected namespaces wouldn't show the picker properly * namespaces list should end in a slash * end full namespace paths with a / * shorten pop up menu link --- ui/app/components/list-item.js | 3 ++- .../vault/cluster/access/namespaces/index.js | 14 +++++++++++++ ui/app/services/namespace.js | 21 +++++++++++++++++-- .../templates/components/namespace-picker.hbs | 10 +++++---- .../components/namespace-reminder.hbs | 2 +- .../vault/cluster/access/namespaces/index.hbs | 20 +++++++++++++++++- 6 files changed, 61 insertions(+), 9 deletions(-) create mode 100644 ui/app/controllers/vault/cluster/access/namespaces/index.js diff --git a/ui/app/components/list-item.js b/ui/app/components/list-item.js index 709161895a..c5d85896f0 100644 --- a/ui/app/components/list-item.js +++ b/ui/app/components/list-item.js @@ -9,11 +9,12 @@ export default Ember.Component.extend({ componentName: null, hasMenu: false, - callMethod: task(function*(method, model, successMessage, failureMessage) { + callMethod: task(function*(method, model, successMessage, failureMessage, successCallback = () => {}) { let flash = this.get('flashMessages'); try { yield model[method](); flash.success(successMessage); + successCallback(); } catch (e) { let errString = e.errors.join(' '); flash.danger(failureMessage + errString); diff --git a/ui/app/controllers/vault/cluster/access/namespaces/index.js b/ui/app/controllers/vault/cluster/access/namespaces/index.js new file mode 100644 index 0000000000..f2d38c7999 --- /dev/null +++ b/ui/app/controllers/vault/cluster/access/namespaces/index.js @@ -0,0 +1,14 @@ +import Ember from 'ember'; + +const { computed, inject, Controller } = Ember; +export default Controller.extend({ + namespaceService: inject.service('namespace'), + accessibleNamespaces: computed.alias('namespaceService.accessibleNamespaces'), + currentNamespace: computed.alias('namespaceService.path'), + actions: { + refreshNamespaceList() { + // fetch new namespaces for the namespace picker + this.get('namespaceService.findNamespacesForUser').perform(); + }, + }, +}); diff --git a/ui/app/services/namespace.js b/ui/app/services/namespace.js index 256fe49c84..dc29b2dea0 100644 --- a/ui/app/services/namespace.js +++ b/ui/app/services/namespace.js @@ -1,5 +1,6 @@ import Ember from 'ember'; import { task } from 'ember-concurrency'; +import lazyCapabilities, { apiPath } from 'vault/macros/lazy-capabilities'; const { Service, computed, inject } = Ember; const ROOT_NAMESPACE = ''; @@ -18,6 +19,8 @@ export default Service.extend({ setNamespace(path) { this.set('path', path); }, + listPath: lazyCapabilities(apiPath`sys/namespaces/`, 'path'), + canList: computed.alias('listPath.canList'), findNamespacesForUser: task(function*() { // uses the adapter and the raw response here since @@ -25,14 +28,28 @@ export default Service.extend({ // want to keep track of these separately let store = this.get('store'); let adapter = store.adapterFor('namespace'); + let userRoot = this.get('auth.authData.userRootNamespace'); try { let ns = yield adapter.findAll(store, 'namespace', null, { adapterOptions: { forUser: true, - namespace: this.get('userRootNamespace'), + namespace: userRoot, }, }); - this.set('accessibleNamespaces', ns.data.keys.map(n => n.replace(/\/$/, ''))); + this.set( + 'accessibleNamespaces', + ns.data.keys.map(n => { + let fullNS = n; + // if the user's root isn't '', then we need to construct + // the paths so they connect to the user root to the list + // otherwise using the current ns to grab the correct leaf + // node in the graph doesn't work + if (userRoot) { + fullNS = `${userRoot}/${n}`; + } + return fullNS.replace(/\/$/, ''); + }) + ); } catch (e) { //do nothing here } diff --git a/ui/app/templates/components/namespace-picker.hbs b/ui/app/templates/components/namespace-picker.hbs index 5aa0017c4b..134eeb01af 100644 --- a/ui/app/templates/components/namespace-picker.hbs +++ b/ui/app/templates/components/namespace-picker.hbs @@ -33,15 +33,17 @@ {{/if}}
- {{#link-to "vault.cluster.access.namespaces" class="namespace-manage-link"}} - Manage - {{/link-to}} + {{#if namespaceService.canList}} + {{#link-to "vault.cluster.access.namespaces" class="namespace-manage-link"}} + Manage + {{/link-to}} + {{/if}}
Current namespace
diff --git a/ui/app/templates/components/namespace-reminder.hbs b/ui/app/templates/components/namespace-reminder.hbs index 7e094f233c..0263044d3e 100644 --- a/ui/app/templates/components/namespace-reminder.hbs +++ b/ui/app/templates/components/namespace-reminder.hbs @@ -1,5 +1,5 @@ {{#if showMessage}}

- This {{noun}} will be {{modeVerb}} in the {{namespace.path}}namespace. + This {{noun}} will be {{modeVerb}} in the {{namespace.path}}/namespace.

{{/if}} diff --git a/ui/app/templates/vault/cluster/access/namespaces/index.hbs b/ui/app/templates/vault/cluster/access/namespaces/index.hbs index dc16b66eea..0a29642a91 100644 --- a/ui/app/templates/vault/cluster/access/namespaces/index.hbs +++ b/ui/app/templates/vault/cluster/access/namespaces/index.hbs @@ -18,12 +18,30 @@ {{list.item.id}} + {{#with (concat currentNamespace (if currentNamespace "/") list.item.id) as |targetNamespace|}} + {{#if (contains targetNamespace accessibleNamespaces)}} +
  • + {{#link-to "vault.cluster.secrets" (query-params namespace=targetNamespace) class="is-block"}} + Switch to namespace + {{/link-to}} +
  • + {{/if}} + {{/with}}