Add MailerLog error reset on successful authorization email validation
[MAILPOET-2022]
This commit is contained in:
committed by
M. Shull
parent
01dcdd0262
commit
61c3630add
@ -3,6 +3,8 @@
|
|||||||
namespace MailPoet\Services;
|
namespace MailPoet\Services;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use MailPoet\Mailer\MailerError;
|
||||||
|
use MailPoet\Mailer\MailerLog;
|
||||||
use MailPoet\Models\Newsletter;
|
use MailPoet\Models\Newsletter;
|
||||||
use MailPoet\Settings\SettingsController;
|
use MailPoet\Settings\SettingsController;
|
||||||
|
|
||||||
@ -27,6 +29,7 @@ class AuthorizedEmailsController {
|
|||||||
$authorized_emails_release_date = new Carbon('2019-03-06');
|
$authorized_emails_release_date = new Carbon('2019-03-06');
|
||||||
if (!Bridge::isMPSendingServiceEnabled() || $installed_at < $authorized_emails_release_date) {
|
if (!Bridge::isMPSendingServiceEnabled() || $installed_at < $authorized_emails_release_date) {
|
||||||
$this->settings->set(self::AUTHORIZED_EMAIL_ADDRESSES_ERROR_SETTING, null);
|
$this->settings->set(self::AUTHORIZED_EMAIL_ADDRESSES_ERROR_SETTING, null);
|
||||||
|
$this->updateMailerLog();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,6 +44,7 @@ class AuthorizedEmailsController {
|
|||||||
$result = $this->validateAddressesInSettings($authorized_emails, $result);
|
$result = $this->validateAddressesInSettings($authorized_emails, $result);
|
||||||
$result = $this->validateAddressesInScheduledAndAutomaticEmails($authorized_emails, $result);
|
$result = $this->validateAddressesInScheduledAndAutomaticEmails($authorized_emails, $result);
|
||||||
$this->settings->set(self::AUTHORIZED_EMAIL_ADDRESSES_ERROR_SETTING, $result ?: null);
|
$this->settings->set(self::AUTHORIZED_EMAIL_ADDRESSES_ERROR_SETTING, $result ?: null);
|
||||||
|
$this->updateMailerLog($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onSettingsSave($settings) {
|
function onSettingsSave($settings) {
|
||||||
@ -96,6 +100,19 @@ class AuthorizedEmailsController {
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array|null $error
|
||||||
|
*/
|
||||||
|
private function updateMailerLog(array $error = null) {
|
||||||
|
if ($error) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$mailer_log_error = MailerLog::getError();
|
||||||
|
if ($mailer_log_error && $mailer_log_error['operation'] === MailerError::OPERATION_AUTHORIZATION) {
|
||||||
|
MailerLog::resumeSending();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private function validateAuthorizedEmail($authorized_emails, $email) {
|
private function validateAuthorizedEmail($authorized_emails, $email) {
|
||||||
return in_array(strtolower($email), $authorized_emails, true);
|
return in_array(strtolower($email), $authorized_emails, true);
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,8 @@ namespace MailPoet\Test\Services;
|
|||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Codeception\Stub\Expected;
|
use Codeception\Stub\Expected;
|
||||||
use MailPoet\Mailer\Mailer;
|
use MailPoet\Mailer\Mailer;
|
||||||
|
use MailPoet\Mailer\MailerError;
|
||||||
|
use MailPoet\Mailer\MailerLog;
|
||||||
use MailPoet\Models\Newsletter;
|
use MailPoet\Models\Newsletter;
|
||||||
use MailPoet\Models\Setting;
|
use MailPoet\Models\Setting;
|
||||||
use MailPoet\Services\AuthorizedEmailsController;
|
use MailPoet\Services\AuthorizedEmailsController;
|
||||||
@ -118,6 +120,45 @@ class AuthorizedEmailsControllerTest extends \MailPoetTest {
|
|||||||
expect($error)->null();
|
expect($error)->null();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testItResetsUnauthorizedErrorInMailerLog() {
|
||||||
|
$log = MailerLog::setError(MailerLog::getMailerLog(), MailerError::OPERATION_AUTHORIZATION, 'message');
|
||||||
|
MailerLog::updateMailerLog($log);
|
||||||
|
$this->settings->set('installed_at', new Carbon());
|
||||||
|
$this->settings->set('sender.address', 'auth@email.com');
|
||||||
|
$this->settings->set('signup_confirmation.from.address', 'auth@email.com');
|
||||||
|
$this->setMailPoetSendingMethod();
|
||||||
|
$controller = $this->getController($authorized_emails_from_api = ['auth@email.com']);
|
||||||
|
$controller->checkAuthorizedEmailAddresses();
|
||||||
|
$error = MailerLog::getError();
|
||||||
|
expect($error)->null();
|
||||||
|
}
|
||||||
|
|
||||||
|
function testItDoesNotResetOtherErrorInMailerLog() {
|
||||||
|
$log = MailerLog::setError(MailerLog::getMailerLog(), MailerError::OPERATION_SEND, 'message');
|
||||||
|
MailerLog::updateMailerLog($log);
|
||||||
|
$this->settings->set('installed_at', new Carbon());
|
||||||
|
$this->settings->set('sender.address', 'auth@email.com');
|
||||||
|
$this->settings->set('signup_confirmation.from.address', 'auth@email.com');
|
||||||
|
$this->setMailPoetSendingMethod();
|
||||||
|
$controller = $this->getController($authorized_emails_from_api = ['auth@email.com']);
|
||||||
|
$controller->checkAuthorizedEmailAddresses();
|
||||||
|
$error = MailerLog::getError();
|
||||||
|
expect($error['operation'])->equals(MailerError::OPERATION_SEND);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testItDoesNotResetMailerLogItErrorPersists() {
|
||||||
|
$log = MailerLog::setError(MailerLog::getMailerLog(), MailerError::OPERATION_AUTHORIZATION, 'message');
|
||||||
|
MailerLog::updateMailerLog($log);
|
||||||
|
$this->settings->set('installed_at', new Carbon());
|
||||||
|
$this->settings->set('sender.address', 'invalid@email.com');
|
||||||
|
$this->settings->set('signup_confirmation.from.address', 'invalid@email.com');
|
||||||
|
$this->setMailPoetSendingMethod();
|
||||||
|
$controller = $this->getController($authorized_emails_from_api = ['auth@email.com']);
|
||||||
|
$controller->checkAuthorizedEmailAddresses();
|
||||||
|
$error = MailerLog::getError();
|
||||||
|
expect($error['operation'])->equals(MailerError::OPERATION_AUTHORIZATION);
|
||||||
|
}
|
||||||
|
|
||||||
private function checkUnauthorizedInNewsletter($type, $status) {
|
private function checkUnauthorizedInNewsletter($type, $status) {
|
||||||
$newsletter = Newsletter::createOrUpdate([
|
$newsletter = Newsletter::createOrUpdate([
|
||||||
'subject' => 'Subject',
|
'subject' => 'Subject',
|
||||||
|
Reference in New Issue
Block a user