2018-11-06 09:13:23 +00:00
|
|
|
import RepositoryService from 'consul-ui/services/repository';
|
2018-10-19 15:17:02 +00:00
|
|
|
import { get } from '@ember/object';
|
|
|
|
import { Promise } from 'rsvp';
|
|
|
|
import statusFactory from 'consul-ui/utils/acls-status';
|
2018-11-02 14:44:36 +00:00
|
|
|
import isValidServerErrorFactory from 'consul-ui/utils/http/acl/is-valid-server-error';
|
2018-11-06 09:13:23 +00:00
|
|
|
import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/policy';
|
|
|
|
|
2018-11-02 14:44:36 +00:00
|
|
|
const isValidServerError = isValidServerErrorFactory();
|
|
|
|
const status = statusFactory(isValidServerError, Promise);
|
2018-10-19 15:17:02 +00:00
|
|
|
const MODEL_NAME = 'policy';
|
2018-11-06 09:13:23 +00:00
|
|
|
|
|
|
|
export default RepositoryService.extend({
|
2018-10-19 15:17:02 +00:00
|
|
|
getModelName: function() {
|
|
|
|
return MODEL_NAME;
|
|
|
|
},
|
|
|
|
getPrimaryKey: function() {
|
|
|
|
return PRIMARY_KEY;
|
|
|
|
},
|
|
|
|
getSlugKey: function() {
|
|
|
|
return SLUG_KEY;
|
|
|
|
},
|
|
|
|
status: function(obj) {
|
|
|
|
return status(obj);
|
|
|
|
},
|
2019-05-01 18:09:29 +00:00
|
|
|
persist: function(item) {
|
|
|
|
// only if a policy doesn't have a template, save it
|
|
|
|
// right now only ServiceIdentities have templates and
|
|
|
|
// are not saveable themselves (but can be saved to a Role/Token)
|
|
|
|
switch (get(item, 'template')) {
|
|
|
|
case '':
|
|
|
|
return item.save();
|
|
|
|
}
|
|
|
|
return Promise.resolve(item);
|
|
|
|
},
|
2018-10-19 15:17:02 +00:00
|
|
|
translate: function(item) {
|
|
|
|
return get(this, 'store').translate('policy', get(item, 'Rules'));
|
|
|
|
},
|
|
|
|
});
|