1
0
Fork 0
mirror of https://github.com/TryGhost/Ghost-Admin.git synced 2023-12-14 02:33:04 +01:00
Ghost-Admin/app/serializers/post.js
Kevin Ansfield 150dca7e81 Updated handling of send_email_when_published
refs 5fd2b7fed1

- sends `?send_email_when_published=true` query param when scheduling/publishing a post with the toggle turned on
  - adds support to the posts adapter for handling the `adapterOptions` option
  - updates the editor `save` task to pass through the required adapter option when a post is being published or scheduled with the toggle checked
- moves state for the email toggle into the publish menu so that we don't try to toggle the model attribute which should only be fetched from the API
- prevent `post.send_email_when_published` being sent to the API via the serializer as it's now a read-only attribute
2019-11-14 17:33:35 +00:00

51 lines
1.6 KiB
JavaScript

/* eslint-disable camelcase */
import ApplicationSerializer from 'ghost-admin/serializers/application';
import EmbeddedRecordsMixin from 'ember-data/serializers/embedded-records-mixin';
import {pluralize} from 'ember-inflector';
export default ApplicationSerializer.extend(EmbeddedRecordsMixin, {
// settings for the EmbeddedRecordsMixin.
attrs: {
authors: {embedded: 'always'},
tags: {embedded: 'always'},
publishedAtUTC: {key: 'published_at'},
createdAtUTC: {key: 'created_at'},
updatedAtUTC: {key: 'updated_at'},
email: {embedded: 'always'}
},
normalizeSingleResponse(store, primaryModelClass, payload) {
let root = this.keyForAttribute(primaryModelClass.modelName);
let pluralizedRoot = pluralize(primaryModelClass.modelName);
if (payload[pluralizedRoot]) {
payload[root] = payload[pluralizedRoot][0];
delete payload[pluralizedRoot];
}
return this._super(...arguments);
},
normalizeArrayResponse() {
return this._super(...arguments);
},
serialize(/*snapshot, options*/) {
let json = this._super(...arguments);
// Inserted locally as a convenience.
delete json.author_id;
// Read-only virtual properties
delete json.uuid;
delete json.url;
delete json.send_email_when_published;
// Deprecated property (replaced with data.authors)
delete json.author;
if (json.visibility === null) {
delete json.visibility;
}
return json;
}
});