mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-29 07:09:48 +03:00
491c5abdc9
no issue So far, only owners or Admins were allowed to control the send email setting while publishing/scheduling a post. This change allows Editors to see the setting as well and toggle as needed. No changes on the API side were needed.
92 lines
3.2 KiB
JavaScript
92 lines
3.2 KiB
JavaScript
import Component from '@ember/component';
|
|
import moment from 'moment';
|
|
import {computed} from '@ember/object';
|
|
import {equal, or} from '@ember/object/computed';
|
|
import {isEmpty} from '@ember/utils';
|
|
import {inject as service} from '@ember/service';
|
|
|
|
export default Component.extend({
|
|
feature: service(),
|
|
settings: service(),
|
|
session: service(),
|
|
post: null,
|
|
saveType: null,
|
|
|
|
// used to set minDate in datepicker
|
|
_minDate: null,
|
|
_publishedAtBlogTZ: null,
|
|
|
|
'data-test-publishmenu-draft': true,
|
|
|
|
disableEmailOption: equal('memberCount', 0),
|
|
showSendEmail: or('session.user.isOwner', 'session.user.isAdmin', 'session.user.isEditor'),
|
|
|
|
canSendEmail: computed('feature.labs.members', 'post.{displayName,email}', function () {
|
|
let membersEnabled = this.feature.get('labs.members');
|
|
let mailgunIsConfigured = this.get('settings.bulkEmailSettings.isEnabled');
|
|
let isPost = this.post.displayName === 'post';
|
|
let hasSentEmail = !!this.post.email;
|
|
|
|
return membersEnabled && mailgunIsConfigured && isPost && !hasSentEmail;
|
|
}),
|
|
|
|
didInsertElement() {
|
|
this.post.set('publishedAtBlogTZ', this.get('post.publishedAtUTC'));
|
|
this.send('setSaveType', 'publish');
|
|
},
|
|
|
|
actions: {
|
|
setSaveType(type) {
|
|
if (this.saveType !== type) {
|
|
let hasDateError = !isEmpty(this.get('post.errors').errorsFor('publishedAtBlogDate'));
|
|
let hasTimeError = !isEmpty(this.get('post.errors').errorsFor('publishedAtBlogTime'));
|
|
let minDate = this._getMinDate();
|
|
|
|
this.set('_minDate', minDate);
|
|
this.setSaveType(type);
|
|
|
|
// when publish: switch to now to avoid validation errors
|
|
// when schedule: switch to last valid or new minimum scheduled date
|
|
if (type === 'publish') {
|
|
if (!hasDateError && !hasTimeError) {
|
|
this._publishedAtBlogTZ = this.get('post.publishedAtBlogTZ');
|
|
} else {
|
|
this._publishedAtBlogTZ = this.get('post.publishedAtUTC');
|
|
}
|
|
|
|
this.post.set('publishedAtBlogTZ', this.get('post.publishedAtUTC'));
|
|
} else {
|
|
if (!this._publishedAtBlogTZ || moment(this._publishedAtBlogTZ).isBefore(minDate)) {
|
|
this.post.set('publishedAtBlogTZ', minDate);
|
|
} else {
|
|
this.post.set('publishedAtBlogTZ', this._publishedAtBlogTZ);
|
|
}
|
|
}
|
|
|
|
this.post.validate();
|
|
}
|
|
},
|
|
|
|
setDate(date) {
|
|
let post = this.post;
|
|
let dateString = moment(date).format('YYYY-MM-DD');
|
|
|
|
post.set('publishedAtBlogDate', dateString);
|
|
return post.validate();
|
|
},
|
|
|
|
setTime(time) {
|
|
let post = this.post;
|
|
|
|
post.set('publishedAtBlogTime', time);
|
|
return post.validate();
|
|
}
|
|
},
|
|
|
|
// API only accepts dates at least 2 mins in the future, default the
|
|
// scheduled date 5 mins in the future to avoid immediate validation errors
|
|
_getMinDate() {
|
|
return moment.utc().add(5, 'minutes');
|
|
}
|
|
});
|