2022-04-20 20:41:29 +03:00
|
|
|
import Component from '@glimmer/component';
|
2022-05-04 12:30:37 +03:00
|
|
|
import EmailFailedError from 'ghost-admin/errors/email-failed-error';
|
2022-04-27 20:20:46 +03:00
|
|
|
import PublishFlowModal from './modals/publish-flow';
|
2022-04-22 19:56:05 +03:00
|
|
|
import PublishOptionsResource from 'ghost-admin/helpers/publish-options';
|
2022-05-05 17:59:34 +03:00
|
|
|
import UpdateFlowModal from './modals/update-flow';
|
2022-05-10 12:04:14 +03:00
|
|
|
import envConfig from 'ghost-admin/config/environment';
|
2022-04-27 20:20:46 +03:00
|
|
|
import moment from 'moment';
|
2022-04-22 19:56:05 +03:00
|
|
|
import {action, get} from '@ember/object';
|
2022-05-10 13:22:36 +03:00
|
|
|
import {capitalize} from '@ember/string';
|
2022-04-20 20:41:29 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
2022-05-10 12:04:14 +03:00
|
|
|
import {task, taskGroup, timeout} from 'ember-concurrency';
|
2022-04-22 19:56:05 +03:00
|
|
|
import {tracked} from '@glimmer/tracking';
|
|
|
|
import {use} from 'ember-could-get-used-to-this';
|
2022-04-20 20:41:29 +03:00
|
|
|
|
2022-05-10 12:04:14 +03:00
|
|
|
const SHOW_SAVE_STATUS_DURATION = 3000;
|
2022-05-04 12:30:37 +03:00
|
|
|
const CONFIRM_EMAIL_POLL_LENGTH = 1000;
|
|
|
|
const CONFIRM_EMAIL_MAX_POLL_LENGTH = 15 * 1000;
|
|
|
|
|
2022-04-22 19:56:05 +03:00
|
|
|
export class PublishOptions {
|
|
|
|
// passed in services
|
|
|
|
config = null;
|
|
|
|
settings = null;
|
|
|
|
store = null;
|
|
|
|
|
2022-04-27 20:20:46 +03:00
|
|
|
// passed in models
|
2022-04-22 19:56:05 +03:00
|
|
|
post = null;
|
|
|
|
user = null;
|
|
|
|
|
2022-05-04 12:30:37 +03:00
|
|
|
@tracked totalMemberCount = 0;
|
|
|
|
|
2022-04-22 19:56:05 +03:00
|
|
|
get isLoading() {
|
|
|
|
return this.setupTask.isRunning;
|
|
|
|
}
|
|
|
|
|
2022-04-28 17:35:50 +03:00
|
|
|
get willEmail() {
|
2022-05-05 17:59:34 +03:00
|
|
|
return this.publishType !== 'publish'
|
|
|
|
&& this.recipientFilter
|
|
|
|
&& this.post.isDraft
|
|
|
|
&& !this.post.email;
|
2022-04-28 17:35:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
get willPublish() {
|
|
|
|
return this.publishType !== 'send';
|
|
|
|
}
|
|
|
|
|
2022-05-04 12:30:37 +03:00
|
|
|
get willOnlyEmail() {
|
|
|
|
return this.publishType === 'send';
|
|
|
|
}
|
|
|
|
|
2022-04-27 20:20:46 +03:00
|
|
|
// publish date ------------------------------------------------------------
|
|
|
|
|
|
|
|
@tracked isScheduled = false;
|
|
|
|
@tracked scheduledAtUTC = this.minScheduledAt;
|
|
|
|
|
|
|
|
get minScheduledAt() {
|
|
|
|
return moment.utc().add(5, 'minutes');
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
toggleScheduled(shouldSchedule) {
|
|
|
|
if (shouldSchedule === undefined) {
|
|
|
|
shouldSchedule = !this.isScheduled;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.isScheduled = shouldSchedule;
|
|
|
|
|
|
|
|
if (shouldSchedule && (!this.scheduledAtUTC || this.scheduledAtUTC.isBefore(this.minScheduledAt))) {
|
|
|
|
this.scheduledAtUTC = this.minScheduledAt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
setScheduledAt(date) {
|
|
|
|
if (moment.utc(date).isBefore(this.minScheduledAt)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.scheduledAtUTC = moment.utc(date);
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
resetPastScheduledAt() {
|
|
|
|
if (this.scheduledAtUTC.isBefore(this.minScheduledAt)) {
|
|
|
|
this.isScheduled = false;
|
|
|
|
this.scheduledAt = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-22 19:56:05 +03:00
|
|
|
// publish type ------------------------------------------------------------
|
|
|
|
|
|
|
|
@tracked publishType = 'publish+send';
|
|
|
|
|
|
|
|
get publishTypeOptions() {
|
|
|
|
return [{
|
2022-05-04 12:30:37 +03:00
|
|
|
value: 'publish+send', // internal
|
|
|
|
label: 'Publish and email', // shown in expanded options
|
|
|
|
display: 'Publish and email', // shown in option title
|
2022-04-22 19:56:05 +03:00
|
|
|
disabled: this.emailDisabled
|
|
|
|
}, {
|
|
|
|
value: 'publish',
|
2022-04-25 13:22:50 +03:00
|
|
|
label: 'Publish only',
|
2022-05-06 17:12:38 +03:00
|
|
|
display: 'Publish'
|
2022-04-22 19:56:05 +03:00
|
|
|
}, {
|
|
|
|
value: 'send',
|
2022-04-25 13:22:50 +03:00
|
|
|
label: 'Email only',
|
2022-04-28 18:46:53 +03:00
|
|
|
display: 'Email',
|
2022-04-22 19:56:05 +03:00
|
|
|
disabled: this.emailDisabled
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
get selectedPublishTypeOption() {
|
|
|
|
return this.publishTypeOptions.find(pto => pto.value === this.publishType);
|
|
|
|
}
|
|
|
|
|
|
|
|
// publish type dropdown is not shown at all
|
|
|
|
get emailUnavailable() {
|
|
|
|
const emailDisabled = get(this.settings, 'editorDefaultEmailRecipients') === 'disabled'
|
|
|
|
|| get(this.settings, 'membersSignupAccess') === 'none';
|
|
|
|
|
|
|
|
return this.post.isPage || this.post.email || !this.user.canEmail || emailDisabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
// publish type dropdown is shown but email options are disabled
|
|
|
|
get emailDisabled() {
|
2022-05-04 12:30:37 +03:00
|
|
|
const mailgunIsNotConfigured = !get(this.settings, 'mailgunIsConfigured')
|
|
|
|
&& !get(this.config, 'mailgunIsConfigured');
|
|
|
|
|
|
|
|
const hasNoMembers = this.totalMemberCount === 0;
|
2022-04-22 19:56:05 +03:00
|
|
|
|
|
|
|
// TODO: check email limit
|
|
|
|
|
2022-05-04 12:30:37 +03:00
|
|
|
return mailgunIsNotConfigured || hasNoMembers;
|
2022-04-22 19:56:05 +03:00
|
|
|
}
|
|
|
|
|
2022-04-25 13:22:50 +03:00
|
|
|
@action
|
2022-04-27 20:20:46 +03:00
|
|
|
setPublishType(newValue) {
|
|
|
|
// TODO: validate option is allowed when setting?
|
|
|
|
this.publishType = newValue;
|
2022-04-25 13:22:50 +03:00
|
|
|
}
|
|
|
|
|
2022-04-28 13:50:05 +03:00
|
|
|
// recipients --------------------------------------------------------------
|
|
|
|
|
|
|
|
// set in constructor because services are not injected
|
|
|
|
allNewsletters = [];
|
2022-04-22 19:56:05 +03:00
|
|
|
|
2022-05-05 13:18:41 +03:00
|
|
|
// both of these are set to site defaults in `setupTask`
|
|
|
|
@tracked newsletter = null;
|
2022-05-05 20:18:50 +03:00
|
|
|
@tracked selectedRecipientFilter = undefined;
|
2022-04-28 13:50:05 +03:00
|
|
|
|
|
|
|
get newsletters() {
|
|
|
|
return this.allNewsletters
|
|
|
|
.filter(n => n.status === 'active')
|
|
|
|
.sort(({sortOrder: a}, {sortOrder: b}) => a - b);
|
|
|
|
}
|
2022-04-22 19:56:05 +03:00
|
|
|
|
|
|
|
get defaultNewsletter() {
|
2022-04-28 13:50:05 +03:00
|
|
|
return this.newsletters[0];
|
2022-04-22 19:56:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
get onlyDefaultNewsletter() {
|
|
|
|
return this.newsletters.length === 1;
|
|
|
|
}
|
|
|
|
|
2022-05-05 20:18:50 +03:00
|
|
|
get recipientFilter() {
|
|
|
|
return this.selectedRecipientFilter === undefined ? this.defaultRecipientFilter : this.selectedRecipientFilter;
|
|
|
|
}
|
|
|
|
|
|
|
|
get defaultRecipientFilter() {
|
|
|
|
const defaultEmailRecipients = this.settings.get('editorDefaultEmailRecipients');
|
|
|
|
|
|
|
|
if (defaultEmailRecipients === 'disabled') {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (defaultEmailRecipients === 'visibility') {
|
|
|
|
if (this.post.visibility === 'public') {
|
|
|
|
return 'status:free,status:-free';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.post.visibility === 'members') {
|
|
|
|
return 'status:free,status:-free';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.post.visibility === 'paid') {
|
|
|
|
return 'status:-free';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.post.visibility === 'tiers') {
|
|
|
|
return this.post.visibilitySegment;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.post.visibility;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.settings.get('editorDefaultEmailRecipientsFilter');
|
|
|
|
}
|
|
|
|
|
2022-05-05 13:18:41 +03:00
|
|
|
get fullRecipientFilter() {
|
2022-05-05 15:33:26 +03:00
|
|
|
let filter = this.newsletter.recipientFilter;
|
2022-05-05 13:18:41 +03:00
|
|
|
|
|
|
|
if (this.recipientFilter) {
|
|
|
|
filter += `+(${this.recipientFilter})`;
|
|
|
|
}
|
|
|
|
|
|
|
|
return filter;
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
setNewsletter(newsletter) {
|
|
|
|
this.newsletter = newsletter;
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
setRecipientFilter(newFilter) {
|
2022-05-05 20:18:50 +03:00
|
|
|
this.selectedRecipientFilter = newFilter;
|
2022-04-28 13:50:05 +03:00
|
|
|
}
|
2022-04-22 19:56:05 +03:00
|
|
|
|
|
|
|
// setup -------------------------------------------------------------------
|
|
|
|
|
|
|
|
constructor({config, post, settings, store, user} = {}) {
|
|
|
|
this.config = config;
|
|
|
|
this.post = post;
|
|
|
|
this.settings = settings;
|
|
|
|
this.store = store;
|
|
|
|
this.user = user;
|
|
|
|
|
2022-05-04 12:30:37 +03:00
|
|
|
// this needs to be set here rather than a class-level property because
|
2022-04-22 19:56:05 +03:00
|
|
|
// unlike Ember-based classes the services are not injected so can't be
|
|
|
|
// used until after they are assigned above
|
2022-04-28 13:50:05 +03:00
|
|
|
this.allNewsletters = this.store.peekAll('newsletter');
|
2022-04-22 19:56:05 +03:00
|
|
|
|
|
|
|
this.setupTask.perform();
|
|
|
|
}
|
|
|
|
|
|
|
|
@task
|
|
|
|
*setupTask() {
|
|
|
|
yield this.fetchRequiredDataTask.perform();
|
|
|
|
|
|
|
|
// TODO: set up initial state / defaults
|
|
|
|
|
2022-04-28 13:50:05 +03:00
|
|
|
this.newsletter = this.defaultNewsletter;
|
|
|
|
|
2022-04-25 13:22:50 +03:00
|
|
|
if (this.emailUnavailable || this.emailDisabled) {
|
2022-04-22 19:56:05 +03:00
|
|
|
this.publishType = 'publish';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@task
|
|
|
|
*fetchRequiredDataTask() {
|
|
|
|
// total # of members - used to enable/disable email
|
2022-05-04 12:30:37 +03:00
|
|
|
const countTotalMembers = this.store.query('member', {limit: 1}).then((res) => {
|
|
|
|
this.totalMemberCount = res.meta.pagination.total;
|
|
|
|
});
|
2022-04-22 19:56:05 +03:00
|
|
|
|
|
|
|
// email limits
|
|
|
|
// TODO: query limit service
|
|
|
|
|
|
|
|
// newsletters
|
2022-04-28 13:50:05 +03:00
|
|
|
const fetchNewsletters = this.store.query('newsletter', {status: 'active', limit: 'all'});
|
2022-04-22 19:56:05 +03:00
|
|
|
|
|
|
|
yield Promise.all([countTotalMembers, fetchNewsletters]);
|
|
|
|
}
|
2022-04-28 17:35:50 +03:00
|
|
|
|
|
|
|
// saving ------------------------------------------------------------------
|
2022-05-04 12:30:37 +03:00
|
|
|
|
|
|
|
@task({drop: true})
|
|
|
|
*saveTask() {
|
2022-05-09 15:54:07 +03:00
|
|
|
// willEmail can change after model changes are applied because the post
|
|
|
|
// can leave draft status - grab it now before that happens
|
|
|
|
const willEmail = this.willEmail;
|
|
|
|
|
2022-05-04 12:30:37 +03:00
|
|
|
this._applyModelChanges();
|
|
|
|
|
|
|
|
const adapterOptions = {};
|
|
|
|
|
2022-05-09 15:54:07 +03:00
|
|
|
if (willEmail) {
|
2022-05-04 12:30:37 +03:00
|
|
|
adapterOptions.newsletterId = this.newsletter.id;
|
2022-05-05 13:18:41 +03:00
|
|
|
adapterOptions.emailRecipientFilter = this.recipientFilter;
|
2022-05-04 12:30:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
return yield this.post.save({adapterOptions});
|
|
|
|
} catch (e) {
|
|
|
|
this._revertModelChanges();
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-05 17:59:34 +03:00
|
|
|
@task({drop: true})
|
|
|
|
*revertToDraftTask() {
|
|
|
|
const originalStatus = this.post.status;
|
|
|
|
const originalPublishedAtUTC = this.post.publishedAtUTC;
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (this.post.isScheduled) {
|
|
|
|
this.post.publishedAtUTC = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.post.status = 'draft';
|
|
|
|
|
|
|
|
return yield this.post.save();
|
|
|
|
} catch (e) {
|
|
|
|
this.post.status = originalStatus;
|
|
|
|
this.post.publishedAtUTC = originalPublishedAtUTC;
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-04 12:30:37 +03:00
|
|
|
// Publishing/scheduling is a side-effect of changing model properties.
|
|
|
|
// We don't want to get into a situation where we've applied these changes
|
|
|
|
// but they haven't been saved because that would result in confusing UI.
|
|
|
|
//
|
|
|
|
// Here we apply those changes from the selected publish options but keep
|
|
|
|
// track of the previous values in case saving fails. We can't use ED's
|
|
|
|
// rollbackAttributes() because it would also rollback any other unsaved edits
|
|
|
|
_applyModelChanges() {
|
|
|
|
// store backup of original values in case we need to revert
|
|
|
|
this._originalModelValues = {};
|
2022-05-05 17:59:34 +03:00
|
|
|
|
|
|
|
// this only applies to the full publish flow which is only available for drafts
|
|
|
|
if (!this.post.isDraft) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const revertableModelProperties = ['status', 'publishedAtUTC', 'emailOnly'];
|
|
|
|
|
|
|
|
revertableModelProperties.forEach((property) => {
|
2022-05-04 12:30:37 +03:00
|
|
|
this._originalModelValues[property] = this.post[property];
|
|
|
|
});
|
|
|
|
|
|
|
|
this.post.status = this.isScheduled ? 'scheduled' : 'published';
|
|
|
|
|
2022-05-05 17:59:34 +03:00
|
|
|
if (this.isScheduled) {
|
2022-05-04 12:30:37 +03:00
|
|
|
this.post.publishedAtUTC = this.scheduledAtUTC;
|
|
|
|
}
|
|
|
|
|
2022-05-05 17:59:34 +03:00
|
|
|
if (this.willEmail) {
|
|
|
|
this.post.emailOnly = this.publishType === 'email';
|
|
|
|
}
|
2022-05-04 12:30:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
_revertModelChanges() {
|
2022-05-05 17:59:34 +03:00
|
|
|
Object.keys(this._originalModelValues).forEach((property) => {
|
2022-05-04 12:30:37 +03:00
|
|
|
this.post[property] = this._originalModelValues[property];
|
|
|
|
});
|
|
|
|
}
|
2022-04-22 19:56:05 +03:00
|
|
|
}
|
|
|
|
|
2022-05-04 12:30:37 +03:00
|
|
|
/* Component -----------------------------------------------------------------*/
|
|
|
|
|
2022-04-22 19:56:05 +03:00
|
|
|
// This component exists for the duration of the editor screen being open.
|
2022-05-05 17:59:34 +03:00
|
|
|
// It's used to store the selected publish options, control the publishing flow
|
|
|
|
// modal display, and provide an editor-specific save behaviour wrapper around
|
|
|
|
// PublishOptions saving.
|
2022-04-22 19:56:05 +03:00
|
|
|
export default class PublishManagement extends Component {
|
2022-04-20 20:41:29 +03:00
|
|
|
@service modals;
|
2022-05-10 13:22:36 +03:00
|
|
|
@service notifications;
|
2022-04-20 20:41:29 +03:00
|
|
|
|
2022-04-22 19:56:05 +03:00
|
|
|
// ensure we get a new PublishOptions instance when @post is replaced
|
|
|
|
@use publishOptions = new PublishOptionsResource(() => [this.args.post]);
|
|
|
|
|
2022-04-20 20:41:29 +03:00
|
|
|
publishFlowModal = null;
|
2022-05-05 17:59:34 +03:00
|
|
|
updateFlowModal = null;
|
2022-04-20 20:41:29 +03:00
|
|
|
|
|
|
|
willDestroy() {
|
|
|
|
super.willDestroy(...arguments);
|
|
|
|
this.publishFlowModal?.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
2022-04-22 19:56:05 +03:00
|
|
|
openPublishFlow(event) {
|
|
|
|
event?.preventDefault();
|
|
|
|
|
2022-05-05 17:59:34 +03:00
|
|
|
this.updateFlowModal?.close();
|
|
|
|
|
2022-04-22 19:56:05 +03:00
|
|
|
if (!this.publishFlowModal || this.publishFlowModal.isClosing) {
|
2022-04-27 20:20:46 +03:00
|
|
|
this.publishOptions.resetPastScheduledAt();
|
|
|
|
|
2022-04-22 19:56:05 +03:00
|
|
|
this.publishFlowModal = this.modals.open(PublishFlowModal, {
|
2022-05-04 12:30:37 +03:00
|
|
|
publishOptions: this.publishOptions,
|
2022-05-10 12:04:14 +03:00
|
|
|
saveTask: this.publishTask
|
2022-04-22 19:56:05 +03:00
|
|
|
});
|
|
|
|
}
|
2022-04-20 20:41:29 +03:00
|
|
|
}
|
2022-05-04 12:30:37 +03:00
|
|
|
|
2022-05-05 17:59:34 +03:00
|
|
|
@action
|
2022-05-10 13:22:36 +03:00
|
|
|
async openUpdateFlow(event) {
|
2022-05-05 17:59:34 +03:00
|
|
|
event?.preventDefault();
|
|
|
|
|
|
|
|
this.publishFlowModal?.close();
|
|
|
|
|
|
|
|
if (!this.updateFlowModal || this.updateFlowModal.isClosing) {
|
|
|
|
this.updateFlowModal = this.modals.open(UpdateFlowModal, {
|
|
|
|
publishOptions: this.publishOptions,
|
2022-05-10 13:22:36 +03:00
|
|
|
saveTask: this.publishTask
|
2022-05-05 17:59:34 +03:00
|
|
|
});
|
2022-05-10 13:22:36 +03:00
|
|
|
|
|
|
|
const result = await this.updateFlowModal;
|
|
|
|
|
|
|
|
if (result?.afterTask && this[result?.afterTask]) {
|
|
|
|
this[result.afterTask].perform();
|
|
|
|
}
|
2022-05-05 17:59:34 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-04 12:30:37 +03:00
|
|
|
@task
|
2022-05-10 12:04:14 +03:00
|
|
|
*publishTask({taskName = 'saveTask'} = {}) {
|
2022-05-05 17:59:34 +03:00
|
|
|
const willEmail = this.publishOptions.willEmail;
|
|
|
|
|
2022-05-04 12:30:37 +03:00
|
|
|
// clean up blank editor cards
|
|
|
|
// apply cloned mobiledoc
|
|
|
|
// apply scratch values
|
|
|
|
// generate slug if needed (should never happen - publish flow can't be opened on new posts)
|
2022-05-10 12:04:14 +03:00
|
|
|
yield this.args.beforePublish();
|
2022-05-04 12:30:37 +03:00
|
|
|
|
|
|
|
// apply publish options (with undo on failure)
|
|
|
|
// save with the required query params for emailing
|
2022-05-05 17:59:34 +03:00
|
|
|
const result = yield this.publishOptions[taskName].perform();
|
2022-05-04 12:30:37 +03:00
|
|
|
|
|
|
|
// perform any post-save cleanup for the editor
|
2022-05-10 12:04:14 +03:00
|
|
|
yield this.args.afterPublish(result);
|
2022-05-04 12:30:37 +03:00
|
|
|
|
|
|
|
// if emailed, wait until it has been submitted so we can show a failure message if needed
|
2022-05-05 17:59:34 +03:00
|
|
|
if (willEmail && this.publishOptions.post.email) {
|
2022-05-04 12:30:37 +03:00
|
|
|
yield this.confirmEmailTask.perform();
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2022-05-10 12:04:14 +03:00
|
|
|
// used by the non-publish "Save" button shown for scheduled/published posts
|
|
|
|
@task({group: 'saveButtonTaskGroup'})
|
|
|
|
*saveTask() {
|
|
|
|
yield this.args.saveTask.perform();
|
|
|
|
this.saveButtonTimeoutTask.perform();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@task({group: 'saveButtonTaskGroup'})
|
|
|
|
*saveButtonTimeoutTask() {
|
|
|
|
yield timeout(envConfig.environment === 'test' ? 1 : SHOW_SAVE_STATUS_DURATION);
|
|
|
|
}
|
|
|
|
|
|
|
|
@taskGroup saveButtonTaskGroup;
|
|
|
|
|
2022-05-04 12:30:37 +03:00
|
|
|
@task
|
|
|
|
*confirmEmailTask() {
|
|
|
|
const post = this.publishOptions.post;
|
|
|
|
|
|
|
|
let pollTimeout = 0;
|
|
|
|
if (post.email && post.email.status !== 'submitted') {
|
|
|
|
while (pollTimeout < CONFIRM_EMAIL_MAX_POLL_LENGTH) {
|
|
|
|
yield timeout(CONFIRM_EMAIL_POLL_LENGTH);
|
|
|
|
pollTimeout += CONFIRM_EMAIL_POLL_LENGTH;
|
|
|
|
|
|
|
|
yield post.reload();
|
|
|
|
|
|
|
|
if (post.email.status === 'submitted') {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (post.email.status === 'failed') {
|
|
|
|
throw new EmailFailedError(post.email.error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2022-05-05 17:59:34 +03:00
|
|
|
|
|
|
|
@task
|
|
|
|
*revertToDraftTask() {
|
2022-05-10 13:22:36 +03:00
|
|
|
try {
|
|
|
|
yield this.publishTask.perform({taskName: 'revertToDraftTask'});
|
|
|
|
|
|
|
|
const postType = capitalize(this.args.post.displayName);
|
|
|
|
this.notifications.showNotification(`${postType} successfully reverted to a draft.`, {type: 'success'});
|
|
|
|
|
|
|
|
return true;
|
|
|
|
} catch (e) {
|
|
|
|
this.notifications.showAPIError(error);
|
|
|
|
}
|
2022-05-05 17:59:34 +03:00
|
|
|
}
|
2022-04-20 20:41:29 +03:00
|
|
|
}
|