mirror of
https://github.com/status-im/consul.git
synced 2025-01-10 05:45:46 +00:00
f21b17a1f2
* 6 new components for new login/logout flow, plus SSO support UI Components: 1. AuthDialog: Wraps/orchestrates AuthForm and AuthProfile 2. AuthForm: Authorization form shown when logged out. 3. AuthProfile: Simple presentational component to show the users 'Profile' 4. OidcSelect: A 'select' component for selecting an OIDC provider, dynamically uses either a single select menu or multiple buttons depending on the amount of providers Data Components: 1. JwtSource: Given an OIDC provider URL this component will request a token from the provider and fire an donchange event when it has been retrieved. Used by TokenSource. 2. TokenSource: Given a oidc provider name or a Consul SecretID, TokenSource will use whichever method/API requests required to retrieve Consul ACL Token, which is emitted to the onchange event handler. Very basic README documentation included here, which is likely to be refined somewhat. * CSS required for new auth/SSO UI components * Remaining app code required to tie the new auth/SSO work together * CSS code required to help tie the auth/SSO work together * Test code in order to get current tests passing with new auth/SSO flow ..plus extremely basics/skipped rendering tests for the new components * Treat the secret received from the server as the truth Previously we've always treated what the user typed as the truth, this breaks down when using SSO as the user doesn't type anything to retrieve a token. Therefore we change this so that we use the secret in the API response as the truth. * Make sure removing an dom tree from a buffer only removes its own tree
111 lines
3.5 KiB
JavaScript
111 lines
3.5 KiB
JavaScript
import Component from '@ember/component';
|
|
import { get, set, computed } from '@ember/object';
|
|
import { alias } from '@ember/object/computed';
|
|
import { inject as service } from '@ember/service';
|
|
|
|
import SlotsMixin from 'block-slots';
|
|
import WithListeners from 'consul-ui/mixins/with-listeners';
|
|
|
|
export default Component.extend(SlotsMixin, WithListeners, {
|
|
onchange: function() {},
|
|
tagName: '',
|
|
|
|
error: function() {},
|
|
type: '',
|
|
|
|
dom: service('dom'),
|
|
container: service('search'),
|
|
formContainer: service('form'),
|
|
|
|
item: alias('form.data'),
|
|
|
|
selectedOptions: alias('items'),
|
|
|
|
init: function() {
|
|
this._super(...arguments);
|
|
this.searchable = this.container.searchable(this.type);
|
|
this.form = this.formContainer.form(this.type);
|
|
this.form.clear({ Datacenter: this.dc, Namespace: this.nspace });
|
|
},
|
|
options: computed('selectedOptions.[]', 'allOptions.[]', function() {
|
|
// It's not massively important here that we are defaulting `items` and
|
|
// losing reference as its just to figure out the diff
|
|
let options = this.allOptions || [];
|
|
const items = this.selectedOptions || [];
|
|
if (get(items, 'length') > 0) {
|
|
// find a proper ember-data diff
|
|
options = options.filter(item => !items.findBy('ID', get(item, 'ID')));
|
|
this.searchable.add(options);
|
|
}
|
|
return options;
|
|
}),
|
|
actions: {
|
|
search: function(term) {
|
|
// TODO: make sure we can either search before things are loaded
|
|
// or wait until we are loaded, guess power select take care of that
|
|
return new Promise(resolve => {
|
|
const remove = this.listen(this.searchable, 'change', function(e) {
|
|
remove();
|
|
resolve(e.target.data);
|
|
});
|
|
this.searchable.search(term);
|
|
});
|
|
},
|
|
reset: function() {
|
|
this.form.clear({ Datacenter: this.dc, Namespace: this.nspace });
|
|
},
|
|
save: function(item, items, success = function() {}) {
|
|
// Specifically this saves an 'new' option/child
|
|
// and then adds it to the selectedOptions, not options
|
|
const repo = this.repo;
|
|
set(item, 'CreateTime', new Date().getTime());
|
|
// TODO: temporary async
|
|
// this should be `set(this, 'item', repo.persist(item));`
|
|
// need to be sure that its saved before adding/closing the modal for now
|
|
// and we don't open the modal on prop change yet
|
|
item = repo.persist(item);
|
|
this.listen(item, {
|
|
message: e => {
|
|
this.actions.change.apply(this, [
|
|
{
|
|
target: {
|
|
name: 'items[]',
|
|
value: items,
|
|
},
|
|
},
|
|
items,
|
|
e.data,
|
|
]);
|
|
success();
|
|
},
|
|
error: e => this.error(e),
|
|
});
|
|
},
|
|
remove: function(item, items) {
|
|
const prop = this.repo.getSlugKey();
|
|
const value = get(item, prop);
|
|
const pos = items.findIndex(function(item) {
|
|
return get(item, prop) === value;
|
|
});
|
|
if (pos !== -1) {
|
|
return items.removeAt(pos, 1);
|
|
}
|
|
this.onchange({ target: this });
|
|
},
|
|
change: function(e, value, item) {
|
|
const event = this.dom.normalizeEvent(...arguments);
|
|
const items = value;
|
|
switch (event.target.name) {
|
|
case 'items[]':
|
|
set(item, 'CreateTime', new Date().getTime());
|
|
// this always happens synchronously
|
|
items.pushObject(item);
|
|
// TODO: Fire a proper event
|
|
this.onchange({ target: this });
|
|
break;
|
|
default:
|
|
}
|
|
},
|
|
},
|
|
});
|