John Cowen 36728b961f
ui: Various amends for 1.7beta (#6965)
* Remove empty init

* Actually make the disco chain endpoint send the nspace, note:

The backend doesn't support this as yet.

* Tweak the font size of flash-messages ever so slightly

* Make sure the nspace menu is kept up to date when creating a new one

* Move comment to the correct place

* Only refresh the namespace menu if you specifically created a nspace

* Change FIXMEs to TODOs as we are happy for these to wait until later
2019-12-18 18:27:54 +00:00

53 lines
2.1 KiB
JavaScript

import Route from '@ember/routing/route';
import { get } from '@ember/object';
import { config } from 'consul-ui/env';
import { inject as service } from '@ember/service';
import WithBlockingActions from 'consul-ui/mixins/with-blocking-actions';
export default Route.extend(WithBlockingActions, {
router: service('router'),
settings: service('settings'),
feedback: service('feedback'),
repo: service('repository/token'),
actions: {
authorize: function(secret, nspace) {
const dc = this.modelFor('dc').dc.Name;
return this.feedback.execute(() => {
return this.repo.self(secret, dc).then(item => {
return this.settings
.persist({
token: {
AccessorID: get(item, 'AccessorID'),
SecretID: secret,
Namespace: get(item, 'Namespace'),
},
})
.then(item => {
// a null AccessorID means we are in legacy mode
// take the user to the legacy acls
// otherwise just refresh the page
if (get(item, 'token.AccessorID') === null) {
// returning false for a feedback action means even though
// its successful, please skip this notification and don't display it
return this.transitionTo('dc.acls').then(function() {
return false;
});
} else {
// TODO: Ideally we wouldn't need to use config() at a route level
// transitionTo should probably remove it instead if NSPACES aren't enabled
if (config('CONSUL_NSPACES_ENABLED') && get(item, 'token.Namespace') !== nspace) {
let routeName = this.router.currentRouteName;
if (!routeName.startsWith('nspace')) {
routeName = `nspace.${routeName}`;
}
return this.transitionTo(`${routeName}`, `~${get(item, 'token.Namespace')}`, dc);
} else {
this.refresh();
}
}
});
});
}, 'authorize');
},
},
});