Prevent activating email without body
[MAILPOET-2366]
This commit is contained in:
committed by
Jack Kitterhing
parent
e56a654b2b
commit
35c9973c85
@@ -189,7 +189,7 @@ class NewsletterListNotification extends React.Component {
|
||||
// force refresh of listing so that groups are updated
|
||||
this.forceUpdate();
|
||||
}).fail((response) => {
|
||||
MailPoet.Notice.error(MailPoet.I18n.t('postNotificationActivationFailed'));
|
||||
MailPoet.Notice.showApiErrorNotice(response);
|
||||
|
||||
// reset value to actual newsletter's status
|
||||
e.target.value = response.status;
|
||||
|
@@ -184,7 +184,7 @@ class NewsletterListWelcome extends React.Component {
|
||||
// force refresh of listing so that groups are updated
|
||||
this.forceUpdate();
|
||||
}).fail((response) => {
|
||||
MailPoet.Notice.error(MailPoet.I18n.t('welcomeEmailActivationFailed'));
|
||||
MailPoet.Notice.showApiErrorNotice(response);
|
||||
|
||||
// reset value to actual newsletter's status
|
||||
e.target.value = response.status;
|
||||
|
@@ -344,6 +344,17 @@ class Newsletter extends Model {
|
||||
}
|
||||
|
||||
function setStatus($status = null) {
|
||||
if ($status === self::STATUS_ACTIVE) {
|
||||
if (!$this->body || empty(json_decode($this->body))) {
|
||||
$this->setError(
|
||||
Helpers::replaceLinkTags(
|
||||
__('This is an empty email without any content and it cannot be sent. Please update [link]the email[/link].'),
|
||||
'admin.php?page=mailpoet-newsletter-editor&id=' . $this->id
|
||||
)
|
||||
);
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
if (in_array($status, [
|
||||
self::STATUS_DRAFT,
|
||||
self::STATUS_SCHEDULED,
|
||||
|
@@ -899,6 +899,7 @@ class NewsletterTest extends \MailPoetTest {
|
||||
foreach ($newsletters_with_activation as $type) {
|
||||
$newsletter = Newsletter::createOrUpdate([
|
||||
'type' => $type,
|
||||
'body' => '["x", "y"]',
|
||||
]);
|
||||
$task = ScheduledTask::createOrUpdate([
|
||||
'status' => ScheduledTask::STATUS_PAUSED,
|
||||
@@ -914,6 +915,17 @@ class NewsletterTest extends \MailPoetTest {
|
||||
}
|
||||
}
|
||||
|
||||
function testBlocksActivationOfEmptyNewsletter() {
|
||||
$newsletter = Newsletter::createOrUpdate([
|
||||
'type' => Newsletter::TYPE_NOTIFICATION,
|
||||
'body' => '[]',
|
||||
'status' => Newsletter::STATUS_DRAFT,
|
||||
]);
|
||||
$newsletter = $newsletter->setStatus(Newsletter::STATUS_ACTIVE);
|
||||
expect($newsletter->status)->equals(Newsletter::STATUS_DRAFT);
|
||||
expect($newsletter->getErrors())->notEmpty();
|
||||
}
|
||||
|
||||
function _after() {
|
||||
\ORM::raw_execute('TRUNCATE ' . NewsletterOption::$_table);
|
||||
\ORM::raw_execute('TRUNCATE ' . Newsletter::$_table);
|
||||
|
Reference in New Issue
Block a user