0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

Fixed order of flatten/clean operations in posts output serializers (#13038)

no issue

`post.clean()` implementation was expecting a flat structure representing final API output but was being called before the flatten operation for `posts_meta` meaning the structure looked like `attrs.posts_meta.property` instead

- adjusted order in output serializers to call `clean()` after flattening the `posts_meta` object
- in `v2` output serializer, moved removal of properties from the serializer into `clean()` for consistency
This commit is contained in:
Kevin Ansfield 2021-06-10 15:14:02 +01:00 committed by GitHub
parent f49f7699aa
commit 4e724b6451
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 31 deletions

View file

@ -47,6 +47,15 @@ const mapPost = (model, frame) => {
gating.forPost(jsonModel, frame);
}
// Transforms post/page metadata to flat structure
let metaAttrs = _.keys(_.omit(postsMetaSchema, ['id', 'post_id']));
_(metaAttrs).filter((k) => {
return (!frame.options.columns || (frame.options.columns && frame.options.columns.includes(k)));
}).each((attr) => {
jsonModel[attr] = _.get(jsonModel.posts_meta, attr) || null;
});
delete jsonModel.posts_meta;
clean.post(jsonModel, frame);
if (frame.options && frame.options.withRelated) {
@ -72,15 +81,6 @@ const mapPost = (model, frame) => {
});
}
// Transforms post/page metadata to flat structure
let metaAttrs = _.keys(_.omit(postsMetaSchema, ['id', 'post_id']));
_(metaAttrs).filter((k) => {
return (!frame.options.columns || (frame.options.columns && frame.options.columns.includes(k)));
}).each((attr) => {
jsonModel[attr] = _.get(jsonModel.posts_meta, attr) || null;
});
delete jsonModel.posts_meta;
return jsonModel;
};

View file

@ -133,6 +133,9 @@ const post = (attrs, frame) => {
delete attrs.locale;
delete attrs.author;
delete attrs.type;
delete attrs.send_email_when_published;
delete attrs.email_recipient_filter;
delete attrs.email_subject;
return attrs;
};

View file

@ -50,6 +50,15 @@ const mapPost = (model, frame) => {
gating.forPost(jsonModel, frame);
}
// Transforms post/page metadata to flat structure
let metaAttrs = _.keys(_.omit(postsMetaSchema, ['id', 'post_id']));
_(metaAttrs).filter((k) => {
return (!frame.options.columns || (frame.options.columns && frame.options.columns.includes(k)));
}).each((attr) => {
jsonModel[attr] = _.get(jsonModel.posts_meta, attr) || null;
});
delete jsonModel.posts_meta;
clean.post(jsonModel, frame);
if (frame.options && frame.options.withRelated) {
@ -67,19 +76,6 @@ const mapPost = (model, frame) => {
});
}
// Transforms post/page metadata to flat structure
let metaAttrs = _.keys(_.omit(postsMetaSchema, ['id', 'post_id']));
_(metaAttrs).filter((k) => {
return (!frame.options.columns || (frame.options.columns && frame.options.columns.includes(k)));
}).each((attr) => {
jsonModel[attr] = _.get(jsonModel.posts_meta, attr) || null;
});
delete jsonModel.posts_meta;
delete jsonModel.send_email_when_published;
delete jsonModel.email_recipient_filter;
delete jsonModel.email_subject;
return jsonModel;
};

View file

@ -55,6 +55,15 @@ const mapPost = (model, frame) => {
jsonModel.send_email_when_published = true;
}
// Transforms post/page metadata to flat structure
let metaAttrs = _.keys(_.omit(postsMetaSchema, ['id', 'post_id']));
_(metaAttrs).filter((k) => {
return (!frame.options.columns || (frame.options.columns && frame.options.columns.includes(k)));
}).each((attr) => {
jsonModel[attr] = _.get(jsonModel.posts_meta, attr) || null;
});
delete jsonModel.posts_meta;
clean.post(jsonModel, frame);
if (frame.options && frame.options.withRelated) {
@ -80,15 +89,6 @@ const mapPost = (model, frame) => {
});
}
// Transforms post/page metadata to flat structure
let metaAttrs = _.keys(_.omit(postsMetaSchema, ['id', 'post_id']));
_(metaAttrs).filter((k) => {
return (!frame.options.columns || (frame.options.columns && frame.options.columns.includes(k)));
}).each((attr) => {
jsonModel[attr] = _.get(jsonModel.posts_meta, attr) || null;
});
delete jsonModel.posts_meta;
return jsonModel;
};