ui: Move ACL policy and token repos to use the RepositoryService (#4867)

This commit is contained in:
John Cowen 2018-11-06 09:13:23 +00:00 committed by John Cowen
parent c9fae76b7d
commit d6c1b9ed3f
2 changed files with 10 additions and 76 deletions

View File

@ -1,14 +1,15 @@
import Service, { inject as service } from '@ember/service';
import RepositoryService from 'consul-ui/services/repository';
import { get } from '@ember/object';
import { typeOf } from '@ember/utils';
import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/policy';
import { Promise } from 'rsvp';
import statusFactory from 'consul-ui/utils/acls-status';
import isValidServerErrorFactory from 'consul-ui/utils/http/acl/is-valid-server-error';
import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/policy';
const isValidServerError = isValidServerErrorFactory();
const status = statusFactory(isValidServerError, Promise);
const MODEL_NAME = 'policy';
export default Service.extend({
export default RepositoryService.extend({
getModelName: function() {
return MODEL_NAME;
},
@ -18,43 +19,10 @@ export default Service.extend({
getSlugKey: function() {
return SLUG_KEY;
},
store: service('store'),
status: function(obj) {
return status(obj);
},
translate: function(item) {
return get(this, 'store').translate('policy', get(item, 'Rules'));
},
findAllByDatacenter: function(dc) {
return get(this, 'store').query('policy', {
dc: dc,
});
},
findBySlug: function(slug, dc) {
return get(this, 'store').queryRecord('policy', {
id: slug,
dc: dc,
});
},
create: function(obj) {
return get(this, 'store').createRecord('policy', obj);
},
persist: function(item) {
return item.save();
},
remove: function(obj) {
let item = obj;
if (typeof obj.destroyRecord === 'undefined') {
item = obj.get('data');
}
if (typeOf(item) === 'object') {
item = get(this, 'store').peekRecord('policy', item[PRIMARY_KEY]);
}
return item.destroyRecord().then(item => {
return get(this, 'store').unloadRecord(item);
});
},
invalidate: function() {
get(this, 'store').unloadAll('policy');
},
});

View File

@ -1,14 +1,15 @@
import Service, { inject as service } from '@ember/service';
import RepositoryService from 'consul-ui/services/repository';
import { get } from '@ember/object';
import { typeOf } from '@ember/utils';
import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/token';
import { Promise } from 'rsvp';
import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/token';
import statusFactory from 'consul-ui/utils/acls-status';
import isValidServerErrorFactory from 'consul-ui/utils/http/acl/is-valid-server-error';
const isValidServerError = isValidServerErrorFactory();
const status = statusFactory(isValidServerError, Promise);
const MODEL_NAME = 'token';
export default Service.extend({
export default RepositoryService.extend({
getModelName: function() {
return MODEL_NAME;
},
@ -48,39 +49,4 @@ export default Service.extend({
dc: dc,
});
},
// TODO: RepositoryService
store: service('store'),
findAllByDatacenter: function(dc) {
return get(this, 'store').query(this.getModelName(), {
dc: dc,
});
},
findBySlug: function(slug, dc) {
return get(this, 'store').queryRecord(this.getModelName(), {
id: slug,
dc: dc,
});
},
create: function(obj) {
// TODO: This should probably return a Promise
return get(this, 'store').createRecord(this.getModelName(), obj);
},
persist: function(item) {
return item.save();
},
remove: function(obj) {
let item = obj;
if (typeof obj.destroyRecord === 'undefined') {
item = obj.get('data');
}
if (typeOf(item) === 'object') {
item = get(this, 'store').peekRecord(this.getModelName(), item[this.getPrimaryKey()]);
}
return item.destroyRecord().then(item => {
return get(this, 'store').unloadRecord(item);
});
},
invalidate: function() {
get(this, 'store').unloadAll(this.getModelName());
},
});