2019-12-17 18:47:37 +00:00
|
|
|
import Serializer from './application';
|
|
|
|
import { get } from '@ember/object';
|
|
|
|
import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/nspace';
|
|
|
|
|
2020-11-09 17:29:12 +00:00
|
|
|
export default class NspaceSerializer extends Serializer {
|
|
|
|
primaryKey = PRIMARY_KEY;
|
|
|
|
slugKey = SLUG_KEY;
|
|
|
|
|
|
|
|
respondForQuery(respond, serialized, data) {
|
2019-12-17 18:47:37 +00:00
|
|
|
return respond((headers, body) => {
|
|
|
|
return this.attachHeaders(
|
|
|
|
headers,
|
|
|
|
body.map(function(item) {
|
|
|
|
if (get(item, 'ACLs.PolicyDefaults')) {
|
|
|
|
item.ACLs.PolicyDefaults = item.ACLs.PolicyDefaults.map(function(item) {
|
|
|
|
item.template = '';
|
|
|
|
return item;
|
|
|
|
});
|
|
|
|
}
|
2020-11-09 17:29:12 +00:00
|
|
|
// Both of these might come though unset so we make sure we at least
|
|
|
|
// have an empty array here so we can add children to them if we
|
|
|
|
// need to whilst saving nspaces
|
2019-12-17 18:47:37 +00:00
|
|
|
['PolicyDefaults', 'RoleDefaults'].forEach(function(prop) {
|
|
|
|
if (typeof item.ACLs === 'undefined') {
|
|
|
|
item.ACLs = [];
|
|
|
|
}
|
|
|
|
if (typeof item.ACLs[prop] === 'undefined') {
|
|
|
|
item.ACLs[prop] = [];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return item;
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
2020-11-09 17:29:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
respondForQueryRecord(respond, serialized, data) {
|
|
|
|
// We don't attachHeaders here yet, mainly because we don't use blocking
|
|
|
|
// queries on form views yet, and by the time we do Serializers should
|
|
|
|
// have been refactored to not use attachHeaders
|
2019-12-17 18:47:37 +00:00
|
|
|
return respond((headers, body) => {
|
|
|
|
return body;
|
|
|
|
});
|
2020-11-09 17:29:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
respondForCreateRecord(respond, serialized, data) {
|
2019-12-17 18:47:37 +00:00
|
|
|
return respond((headers, body) => {
|
2020-11-09 17:29:12 +00:00
|
|
|
// The data properties sent to be saved in the backend or the same ones
|
|
|
|
// that we receive back if its successfull therefore we can just ignore
|
|
|
|
// the result and avoid ember-data syncing problems
|
2019-12-17 18:47:37 +00:00
|
|
|
return {};
|
|
|
|
});
|
2020-11-09 17:29:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
respondForUpdateRecord(respond, serialized, data) {
|
2019-12-17 18:47:37 +00:00
|
|
|
return respond((headers, body) => {
|
|
|
|
return body;
|
|
|
|
});
|
2020-11-09 17:29:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
respondForDeleteRecord(respond, serialized, data) {
|
2019-12-17 18:47:37 +00:00
|
|
|
return respond((headers, body) => {
|
|
|
|
// Deletes only need the primaryKey/uid returning
|
|
|
|
return body;
|
|
|
|
});
|
2020-11-09 17:29:12 +00:00
|
|
|
}
|
|
|
|
}
|