mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-15 03:12:54 +03:00
6a057fad99
We want to allow admin users to trigger a retry of failed emails without having to go through the unpublish/republish dance. - fixed resource identifier in email permissions migration so email permissions are added correctly - added new email permissions migration so that beta releases can be upgraded without rollback (will be a no-op for any non-beta upgrades) - added `/emails/:id/retry/` canary Admin API endpoint - follows same URL pattern as theme activation - only triggers mega service retry endpoint if the email has a `'failed'` status
61 lines
1.8 KiB
JavaScript
61 lines
1.8 KiB
JavaScript
const models = require('../../models');
|
|
const common = require('../../lib/common');
|
|
const megaService = require('../../services/mega');
|
|
|
|
module.exports = {
|
|
docName: 'emails',
|
|
|
|
read: {
|
|
options: [
|
|
'fields'
|
|
],
|
|
validation: {
|
|
options: {
|
|
fields: ['html', 'plaintext', 'subject']
|
|
}
|
|
},
|
|
data: [
|
|
'id'
|
|
],
|
|
permissions: true,
|
|
query(frame) {
|
|
return models.Email.findOne(frame.data, frame.options)
|
|
.then((model) => {
|
|
if (!model) {
|
|
throw new common.errors.NotFoundError({
|
|
message: common.i18n.t('errors.models.email.emailNotFound')
|
|
});
|
|
}
|
|
|
|
return model.toJSON(frame.options);
|
|
});
|
|
}
|
|
},
|
|
|
|
retry: {
|
|
data: [
|
|
'id'
|
|
],
|
|
permissions: true,
|
|
query(frame) {
|
|
return models.Email.findOne(frame.data, frame.options)
|
|
.then(async (model) => {
|
|
if (!model) {
|
|
throw new common.errors.NotFoundError({
|
|
message: common.i18n.t('errors.models.email.emailNotFound')
|
|
});
|
|
}
|
|
|
|
if (model.get('status') !== 'failed') {
|
|
throw new common.errors.IncorrectUsageError({
|
|
message: common.i18n.t('errors.models.email.retryNotAllowed')
|
|
});
|
|
}
|
|
|
|
const result = await megaService.mega.retryFailedEmail(model);
|
|
return result.toJSON(frame.options);
|
|
});
|
|
}
|
|
}
|
|
};
|