open-nomad/ui/app/controllers/settings/tokens.js

68 lines
1.7 KiB
JavaScript
Raw Normal View History

import { inject as service } from '@ember/service';
import { reads } from '@ember/object/computed';
import Controller from '@ember/controller';
import { getOwner } from '@ember/application';
import { alias } from '@ember/object/computed';
import { action } from '@ember/object';
import classic from 'ember-classic-decorator';
2017-09-19 14:47:10 +00:00
@classic
export default class Tokens extends Controller {
@service token;
@service store;
2017-09-19 14:47:10 +00:00
@reads('token.secret') secret;
2017-09-19 14:47:10 +00:00
tokenIsValid = false;
tokenIsInvalid = false;
@alias('token.selfToken') tokenRecord;
resetStore() {
2019-03-26 07:46:44 +00:00
this.store.unloadAll();
}
@action
clearTokenProperties() {
this.token.setProperties({
secret: undefined,
});
this.setProperties({
tokenIsValid: false,
tokenIsInvalid: false,
});
// Clear out all data to ensure only data the anonymous token is privileged to see is shown
this.resetStore();
this.token.reset();
}
@action
verifyToken() {
const { secret } = this;
const TokenAdapter = getOwner(this).lookup('adapter:token');
this.set('token.secret', secret);
TokenAdapter.findSelf().then(
() => {
// Clear out all data to ensure only data the new token is privileged to see is shown
this.resetStore();
// Refetch the token and associated policies
2021-12-28 14:45:20 +00:00
this.get('token.fetchSelfTokenAndPolicies').perform().catch();
this.setProperties({
tokenIsValid: true,
tokenIsInvalid: false,
});
},
() => {
this.set('token.secret', undefined);
this.setProperties({
tokenIsValid: false,
tokenIsInvalid: true,
});
}
);
}
}