Ghost/ghost/admin/app/adapters/post.js

34 lines
1.3 KiB
JavaScript
Raw Normal View History

import ApplicationAdapter from 'ghost-admin/adapters/application';
export default class Post extends ApplicationAdapter {
// posts and pages now include everything by default
buildIncludeURL(store, modelName, id, snapshot, requestType, query) {
const url = this.buildURL(modelName, id, snapshot, requestType, query);
const parsedUrl = new URL(url);
Added first iteration of saving to new publish flow refs https://github.com/TryGhost/Team/issues/1542 - extracted before/after save routines in the editor controller into separate actions - allows saving to occur in the publish flow without it needing any editor-specific knowledge - allows for easier cleanup of email related logic from the editor save tasks later on - added `saveTask` to `PublishOptions` - applies the selected options to the post model where they correspond to model attributes and keeps the previous values in memory so the changes can be undone on failure - this keeps the local model state in sync because if a publish fails we want the editor to continue showing the draft state, non-scheduled publish time, and not have an unexpected email-only state - saves the post model directly passing `adapterOptions` so the save request query params match the chosen publish options - added a `saveTask` to the `<PublishManagement>` component - passed through to the `publish-flow` modal and is triggered by the confirm button on the confirmation screen - runs the before/afterSave arguments passed in from the editor - runs the `saveTask` on `PublishOptions` which handles everything needed to change status and send emails - polls the post after saving to wait for the attached email to switch to submitted/failed which lets us show a failure message and retry button as required (message + retry not yet implemented) - adds "complete" state to publish flow once save has finished - confirms what just happened based on saved post data rather than chosen publish options - has a link to the view the post
2022-05-04 12:30:37 +03:00
// TODO: cleanup sendEmailWhenPublished when removing publishingFlow flag
let emailRecipientFilter = snapshot?.adapterOptions?.emailRecipientFilter
|| snapshot?.adapterOptions?.sendEmailWhenPublished;
Added first iteration of saving to new publish flow refs https://github.com/TryGhost/Team/issues/1542 - extracted before/after save routines in the editor controller into separate actions - allows saving to occur in the publish flow without it needing any editor-specific knowledge - allows for easier cleanup of email related logic from the editor save tasks later on - added `saveTask` to `PublishOptions` - applies the selected options to the post model where they correspond to model attributes and keeps the previous values in memory so the changes can be undone on failure - this keeps the local model state in sync because if a publish fails we want the editor to continue showing the draft state, non-scheduled publish time, and not have an unexpected email-only state - saves the post model directly passing `adapterOptions` so the save request query params match the chosen publish options - added a `saveTask` to the `<PublishManagement>` component - passed through to the `publish-flow` modal and is triggered by the confirm button on the confirmation screen - runs the before/afterSave arguments passed in from the editor - runs the `saveTask` on `PublishOptions` which handles everything needed to change status and send emails - polls the post after saving to wait for the attached email to switch to submitted/failed which lets us show a failure message and retry button as required (message + retry not yet implemented) - adds "complete" state to publish flow once save has finished - confirms what just happened based on saved post data rather than chosen publish options - has a link to the view the post
2022-05-04 12:30:37 +03:00
if (emailRecipientFilter) {
if (emailRecipientFilter === 'status:free,status:-free') {
emailRecipientFilter = 'all';
}
parsedUrl.searchParams.append('email_recipient_filter', emailRecipientFilter);
}
if (snapshot?.adapterOptions?.newsletter) {
// TODO: rename newsletter_id to newsletter once changed in the backend
const newsletterId = snapshot.adapterOptions.newsletter;
parsedUrl.searchParams.append('newsletter_id', newsletterId);
}
return parsedUrl.toString();
}
buildQuery(store, modelName, options) {
return options;
}
}