Ghost/ghost/admin/app/serializers/application.js
Kevin Ansfield a93c8b5be9 Don't send created_by and updated_by attrs in API requests
refs https://github.com/TryGhost/Ghost/issues/9548
- refactor serialisers to use `serialize` rather than `serializeToHash` to avoid code duplication
- strip `created_by` and `updated_by` attrs when serializing - Ghost will set these automatically based on the currently logged in user
2018-04-05 11:54:36 +01:00

32 lines
867 B
JavaScript

import RESTSerializer from 'ember-data/serializers/rest';
import {decamelize} from '@ember/string';
import {pluralize} from 'ember-inflector';
export default RESTSerializer.extend({
serialize(/*snapshot, options*/) {
let json = this._super(...arguments);
// don't send attributes that are updated automatically on the server
delete json.created_by;
delete json.updated_by;
return json;
},
serializeIntoHash(hash, type, record, options) {
// Our API expects an id on the posted object
options = options || {};
options.includeId = true;
// We have a plural root in the API
let root = pluralize(type.modelName);
let data = this.serialize(record, options);
hash[root] = [data];
},
keyForAttribute(attr) {
return decamelize(attr);
}
});