open-nomad/ui/app/controllers/settings/tokens.js
Buck Doyle cd11cd290c Add manually-converted classes
I don’t know why the codemod ignored these files 🧐
2020-06-15 10:14:26 -05:00

72 lines
1.6 KiB
JavaScript

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';
@classic
export default class Tokens extends Controller {
@service token;
@service system;
@service store;
@reads('token.secret') secret;
tokenIsValid = false;
tokenIsInvalid = false;
@alias('token.selfToken') tokenRecord;
resetStore() {
this.store.unloadAll();
}
@action
clearTokenProperties() {
this.token.setProperties({
secret: undefined,
});
this.setProperties({
tokenIsValid: false,
tokenIsInvalid: false,
});
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.system.reset();
this.resetStore();
// Refetch the token and associated policies
this.get('token.fetchSelfTokenAndPolicies')
.perform()
.catch();
this.setProperties({
tokenIsValid: true,
tokenIsInvalid: false,
});
},
() => {
this.set('token.secret', undefined);
this.setProperties({
tokenIsValid: false,
tokenIsInvalid: true,
});
}
);
}
}