open-consul/ui/packages/consul-ui/app/services/repository/policy.js
John Cowen ef01ea18f1
ui: Run Ember native class code mod (#9093)
* ui: Apply native class codemod to all services

* ui: Apply native class codemod to routes

* ui: Apply native class codemod to controllers

* Fix up ember proxy `content` issue

* Add a CreateTime on policy creation

* Minor formatting

* Convert child based saving to use ec instead of custom approach

* Remove custom event source repo wrapping initializer

* Repos here are no longer proxy objects revert to using them normally

* Remove areas of code that were used to set up source backed repos
2020-11-09 09:25:35 +00:00

43 lines
1.1 KiB
JavaScript

import RepositoryService from 'consul-ui/services/repository';
import { get } from '@ember/object';
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 class PolicyService extends RepositoryService {
getModelName() {
return MODEL_NAME;
}
getPrimaryKey() {
return PRIMARY_KEY;
}
getSlugKey() {
return SLUG_KEY;
}
status(obj) {
return status(obj);
}
persist(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);
}
translate(item) {
return this.store.translate('policy', get(item, 'Rules'));
}
}