2018-09-25 16:28:26 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
|
|
|
import Route from '@ember/routing/route';
|
2018-04-03 14:16:57 +00:00
|
|
|
import ClusterRoute from 'vault/mixins/cluster-route';
|
2019-06-21 21:05:45 +00:00
|
|
|
import ListRoute from 'core/mixins/list-route';
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
export default Route.extend(ClusterRoute, ListRoute, {
|
|
|
|
version: service(),
|
|
|
|
wizard: service(),
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2018-08-28 05:03:55 +00:00
|
|
|
activate() {
|
|
|
|
if (this.get('wizard.featureState') === 'details') {
|
|
|
|
this.get('wizard').transitionFeatureMachine('details', 'CONTINUE', this.policyType());
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-04-03 14:16:57 +00:00
|
|
|
shouldReturnEmptyModel(policyType, version) {
|
2018-04-05 21:08:18 +00:00
|
|
|
return policyType !== 'acl' && (version.get('isOSS') || !version.get('hasSentinel'));
|
2018-04-03 14:16:57 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
model(params) {
|
|
|
|
let policyType = this.policyType();
|
|
|
|
if (this.shouldReturnEmptyModel(policyType, this.get('version'))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return this.store
|
|
|
|
.lazyPaginatedQuery(`policy/${policyType}`, {
|
|
|
|
page: params.page,
|
|
|
|
pageFilter: params.pageFilter,
|
|
|
|
responsePath: 'data.keys',
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
// acls will never be empty, but sentinel policies can be
|
|
|
|
if (err.httpStatus === 404 && this.policyType() !== 'acl') {
|
|
|
|
return [];
|
|
|
|
} else {
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
setupController(controller, model) {
|
|
|
|
const params = this.paramsFor(this.routeName);
|
|
|
|
if (!model) {
|
|
|
|
controller.setProperties({
|
|
|
|
model: null,
|
|
|
|
policyType: this.policyType(),
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
controller.setProperties({
|
|
|
|
model,
|
|
|
|
filter: params.pageFilter || '',
|
|
|
|
page: model.get('meta.currentPage') || 1,
|
|
|
|
policyType: this.policyType(),
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
resetController(controller, isExiting) {
|
|
|
|
this._super(...arguments);
|
|
|
|
if (isExiting) {
|
|
|
|
controller.set('filter', '');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
actions: {
|
|
|
|
willTransition(transition) {
|
|
|
|
window.scrollTo(0, 0);
|
|
|
|
if (!transition || transition.targetName !== this.routeName) {
|
|
|
|
this.store.clearAllDatasets();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
},
|
2018-09-25 16:28:26 +00:00
|
|
|
reload() {
|
|
|
|
this.store.clearAllDatasets();
|
|
|
|
this.refresh();
|
|
|
|
},
|
2018-04-03 14:16:57 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
policyType() {
|
|
|
|
return this.paramsFor('vault.cluster.policies').type;
|
|
|
|
},
|
|
|
|
});
|