🐛 Fixed scheduled send-only post switching to publish+send when rescheduling

closes https://github.com/TryGhost/Ghost/issues/14354

When setting/cleaning up the publish menu state we were incorrectly reverting to the default "publish & send" state when a post was already set to be email-only. This resulted in an unexpected and non-obvious switch to "publish & send" when re-scheduling a scheduled email-only post.

- updated the publish menu setup and cleanup routines to account for scheduled, email-only posts
- fixed the header in the publish menu to say "sent" rather than "published" when an email-only post is scheduled
This commit is contained in:
Kevin Ansfield 2022-03-31 17:10:49 +01:00
parent 37ee53bb4a
commit 623825f8f0
6 changed files with 59 additions and 5 deletions

View File

@ -1,4 +1,4 @@
<span class="gh-publishmenu-select">
<span class="gh-publishmenu-select" ...attributes>
<PowerSelect
@options={{this.availablePublishActions}}
@renderInPlace={{true}}

View File

@ -1,9 +1,10 @@
<div ...attributes>
<header class="gh-publishmenu-heading">Ready to
<header class="gh-publishmenu-heading" data-test-publishmenu-header>Ready to
{{#if @canSendEmail}}
<GhDistributionActionSelect
@distributionAction={{@distributionAction}}
@setDistributionAction={{@setDistributionAction}}
data-test-distribution-action-select
/>
{{else}}
publish

View File

@ -1,5 +1,5 @@
<div data-test-publishmenu-scheduled="true" ...attributes>
<header class="gh-publishmenu-heading">Will be published in {{this.timeToPublished}}</header>
<header class="gh-publishmenu-heading" data-test-publishmenu-header>Will be {{if @emailOnly "sent" "published"}} in {{this.timeToPublished}}</header>
<div class="gh-publishmenu-content">
<section class="gh-publishmenu-section">
<div class="gh-publishmenu-radio {{if (eq @saveType "draft") "active"}}" {{on "click" (fn this.setSaveType "draft")}}>

View File

@ -18,6 +18,7 @@
<GhPublishmenuScheduled
@post={{this.post}}
@saveType={{this.saveType}}
@emailOnly={{this.emailOnly}}
@isClosing={{this.isClosing}}
@canSendEmail={{this.canSendEmail}}
@recipientsFilter={{this.sendEmailWhenPublished}}

View File

@ -217,6 +217,10 @@ export default Component.extend({
const defaultEmailRecipients = this.get('defaultEmailRecipients');
if (this.post.status === 'scheduled' && this.post.emailOnly) {
this.set('distributionAction', 'send');
}
if (this.post.isPage || !defaultEmailRecipients) {
this.set('distributionAction', 'publish');
}
@ -488,7 +492,9 @@ export default Component.extend({
},
_cleanup() {
if (this.post.isPage || !this.defaultEmailRecipients) {
if (this.post.isScheduled && this.post.emailOnly) {
this.set('distributionAction', 'send');
} else if (this.post.isPage || !this.defaultEmailRecipients) {
this.set('distributionAction', 'publish');
} else {
this.set('distributionAction', 'publish_send');

View File

@ -860,7 +860,53 @@ describe('Acceptance: Editor', function () {
await click('[data-test-publishmenu-scheduled-option]');
await click('[data-test-publishmenu-save]');
expect(post.status).to.equal('scheduled');
expect(post.attrs.status).to.equal('scheduled');
});
// BUG: re-scheduling a send-only post unexpectedly switched to publish+send
// https://github.com/TryGhost/Ghost/issues/14354
it('can re-schedule an email-only post', async function () {
// enable email functionality
this.server.db.settings.find({key: 'mailgun_api_key'})
? this.server.db.settings.update({key: 'mailgun_api_key'}, {value: 'MAILGUN_API_KEY'})
: this.server.create('setting', {key: 'mailgun_api_key', value: 'MAILGUN_API_KEY', group: 'email'});
this.server.db.settings.find({key: 'mailgun_domain'})
? this.server.db.settings.update({key: 'mailgun_domain'}, {value: 'MAILGUN_DOMAIN'})
: this.server.create('setting', {key: 'mailgun_domain', value: 'MAILGUN_DOMAIN', group: 'email'});
this.server.db.settings.find({key: 'mailgun_base_url'})
? this.server.db.settings.update({key: 'mailgun_base_url'}, {value: 'MAILGUN_BASE_URL'})
: this.server.create('setting', {key: 'mailgun_base_url', value: 'MAILGUN_BASE_URL', group: 'email'});
this.server.db.settings.find({key: 'editor_default_email_recipients'})
? this.server.db.settings.update({key: 'editor_default_email_recipients'}, {value: 'visibility'})
: this.server.create('setting', {key: 'editor_default_email_recipients', value: 'visibility', group: 'editor'});
this.server.createList('member', 4);
const post = this.server.create('post', {status: 'draft', authors: [user]});
const scheduledTime = moment().add(2, 'hours');
await visit(`/editor/post/${post.id}`);
await click('[data-test-publishmenu-trigger]');
await selectChoose('[data-test-distribution-action-select]', 'send');
await click('[data-test-publishmenu-scheduled-option]');
await datepickerSelect('[data-test-publishmenu-draft] [data-test-date-time-picker-datepicker]', new Date(scheduledTime.format().replace(/\+.*$/, '')));
await click('[data-test-publishmenu-save]');
await click('[data-test-button="confirm-schedule"]');
expect(post.attrs.emailOnly).to.be.true;
await click('[data-test-publishmenu-trigger]');
expect(find('[data-test-publishmenu-header]')).to.contain.text('Will be sent');
await datepickerSelect('[data-test-publishmenu-scheduled] [data-test-date-time-picker-datepicker]', new Date(scheduledTime.add(1, 'day').format().replace(/\+.*$/, '')));
await click('[data-test-publishmenu-save]');
expect(post.attrs.emailOnly).to.be.true;
});
});
});