From 3a11faf0b6bb2be7fecb621dc5538bcdd3739a2f Mon Sep 17 00:00:00 2001 From: Simon Backx Date: Mon, 16 May 2022 10:18:46 +0200 Subject: [PATCH] Updated publishing with renamed newsletter and email_segment options (#2380) refs https://github.com/TryGhost/Team/issues/1596 This commit updates admin to align with the changes in the backend in https://github.com/TryGhost/Ghost/pull/14798 - `post.email_recipient_filter` option and property is renamed to `email_segment` - `newsletter_id` option is renamed to `newsletter` (and now uses slug instead of id) - Sending a post via email, means you need to set the `newsletter` option. The `email_segment` option is optional now and defaults to `all`. Not setting `newsletter` means not sending an email, setting `email_segment` is ignored if `newsletter` is missing. - We can no longer use `email_recipient_filter` (now renamed to `email_segment`) to know whether a post is published/scheduled to be sent as an email. We need to rely on the newsletter relation now. The `email_segment` `none` value has been dropped and will be `all` even if no email will be sent (newsletter will be null). - `sendEmailWhenPublished` option is no longer supported in the backend. --- ghost/admin/app/adapters/post.js | 29 +++++++++---------- .../editor-labs/modals/update-flow.hbs | 2 +- .../app/components/gh-editor-post-status.hbs | 2 +- .../app/components/gh-posts-list-item.hbs | 22 +++++++------- .../app/components/gh-posts-list-item.js | 5 ---- ghost/admin/app/components/gh-publishmenu.js | 4 +-- ghost/admin/app/controllers/editor.js | 3 +- ghost/admin/app/models/post.js | 13 ++++----- ghost/admin/app/utils/publish-options.js | 4 +-- 9 files changed, 37 insertions(+), 47 deletions(-) diff --git a/ghost/admin/app/adapters/post.js b/ghost/admin/app/adapters/post.js index 8b3b5afaa8..86bd0846b7 100644 --- a/ghost/admin/app/adapters/post.js +++ b/ghost/admin/app/adapters/post.js @@ -6,22 +6,21 @@ export default class Post extends ApplicationAdapter { const url = this.buildURL(modelName, id, snapshot, requestType, query); const parsedUrl = new URL(url); - // TODO: cleanup sendEmailWhenPublished when removing publishingFlow flag - let emailRecipientFilter = snapshot?.adapterOptions?.emailRecipientFilter - || snapshot?.adapterOptions?.sendEmailWhenPublished; - - 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); + const newsletter = snapshot.adapterOptions.newsletter; + parsedUrl.searchParams.append('newsletter', newsletter); + + // TODO: cleanup sendEmailWhenPublished when removing publishingFlow flag + let emailSegment = snapshot?.adapterOptions?.emailSegment + || snapshot?.adapterOptions?.sendEmailWhenPublished; + + if (emailSegment) { + if (emailSegment === 'status:free,status:-free') { + emailSegment = 'all'; + } + + parsedUrl.searchParams.append('email_segment', emailSegment); + } } return parsedUrl.toString(); diff --git a/ghost/admin/app/components/editor-labs/modals/update-flow.hbs b/ghost/admin/app/components/editor-labs/modals/update-flow.hbs index 72aacc6922..5ac05ec256 100644 --- a/ghost/admin/app/components/editor-labs/modals/update-flow.hbs +++ b/ghost/admin/app/components/editor-labs/modals/update-flow.hbs @@ -33,7 +33,7 @@ {{#if (or post.isSent (and post.isPublished post.email) - (and post.isScheduled post.emailRecipientFilter (not post.email)) + post.willEmail ) }} {{#if post.emailOnly}} diff --git a/ghost/admin/app/components/gh-editor-post-status.hbs b/ghost/admin/app/components/gh-editor-post-status.hbs index d11b9f95c8..5cbd0fb6a3 100644 --- a/ghost/admin/app/components/gh-editor-post-status.hbs +++ b/ghost/admin/app/components/gh-editor-post-status.hbs @@ -23,7 +23,7 @@ Scheduled {{#if this.isHovered}} to be published - {{#if (and @post.emailRecipientFilter (not @post.email))}} + {{#if (and @post.newsletter (not @post.email))}} and sent to {{/if}} {{this.scheduledTime}} diff --git a/ghost/admin/app/components/gh-posts-list-item.hbs b/ghost/admin/app/components/gh-posts-list-item.hbs index cb956babd0..5e4553824a 100644 --- a/ghost/admin/app/components/gh-posts-list-item.hbs +++ b/ghost/admin/app/components/gh-posts-list-item.hbs @@ -51,13 +51,11 @@ {{#if (and this.feature.emailAnalytics (eq @post.displayName "post"))}}
- {{#if (or @post.email @post.willEmail)}} - {{#if (eq @post.email.status "submitted")}} - - {{format-number @post.email.emailCount}} - {{gh-pluralize @post.email.emailCount "send"}} - - {{/if}} + {{#if (eq @post.email.status "submitted")}} + + {{format-number @post.email.emailCount}} + {{gh-pluralize @post.email.emailCount "send"}} + {{/if}}
@@ -84,9 +82,9 @@