mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
🐛 Fixed backwards compatibility for newsletters (#12422)
closes https://github.com/TryGhost/Ghost/issues/12416 This fixes compatibility for the `send_email_when_published` option for the Posts API. The model layer only allows setting the `email_recipient_filter` column when the `status` is being changed. Because of this we need to withhold the `status` change until after we have determined the `email_recipient_filter`.
This commit is contained in:
parent
d14f174f35
commit
cbaf6e5a74
1 changed files with 25 additions and 3 deletions
|
@ -159,10 +159,32 @@ module.exports = {
|
||||||
await membersService.checkHostLimit();
|
await membersService.checkHostLimit();
|
||||||
}
|
}
|
||||||
|
|
||||||
let model = await models.Post.edit(frame.data.posts[0], frame.options);
|
let model;
|
||||||
|
|
||||||
if (!frame.options.email_recipient_filter && frame.options.send_email_when_published) {
|
if (!frame.options.email_recipient_filter && frame.options.send_email_when_published) {
|
||||||
frame.options.email_recipient_filter = model.get('visibility') === 'paid' ? 'paid' : 'all';
|
await models.Base.transaction(async (transacting) => {
|
||||||
|
const options = {
|
||||||
|
...frame.options,
|
||||||
|
transacting
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 1. We need to edit the post first in order to know what the visibility is.
|
||||||
|
* 2. We can only pass the email_recipient_filter when we change the status.
|
||||||
|
*
|
||||||
|
* So, we first edit the post as requested, with all information except the status,
|
||||||
|
* from there we can determine what the email_recipient_filter should be and then finish
|
||||||
|
* the edit, with the status and the email_recipient_filter option.
|
||||||
|
*/
|
||||||
|
const status = frame.data.posts[0].status;
|
||||||
|
delete frame.data.posts[0].status;
|
||||||
|
const interimModel = await models.Post.edit(frame.data.posts[0], options);
|
||||||
|
frame.data.posts[0].status = status;
|
||||||
|
|
||||||
|
options.email_recipient_filter = interimModel.get('visibility') === 'paid' ? 'paid' : 'all';
|
||||||
|
|
||||||
|
model = await models.Post.edit(frame.data.posts[0], options);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
model = await models.Post.edit(frame.data.posts[0], frame.options);
|
model = await models.Post.edit(frame.data.posts[0], frame.options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue