Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions apps/settings/lib/Controller/CheckSetupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,20 @@ protected function isReadOnlyConfig(): bool {
return \OC_Helper::isReadOnlyConfigEnabled();
}

protected function wasEmailTestSuccessful(): bool {
// Handle the case that the configuration was set before the check was introduced or it was only set via command line and not from the UI
if ($this->config->getAppValue('core', 'emailTestSuccessful', '') === '' && $this->config->getSystemValue('mail_domain', '') === '') {
return false;
}

// The mail test was unsuccessful or the config was changed using the UI without verifying with a testmail, hence return false
if ($this->config->getAppValue('core', 'emailTestSuccessful', '') === '0') {
return false;
}

return true;
}

protected function hasValidTransactionIsolationLevel(): bool {
try {
if ($this->db->getDatabasePlatform() instanceof SqlitePlatform) {
Expand Down Expand Up @@ -809,6 +823,7 @@ public function check() {
'isGetenvServerWorking' => !empty(getenv('PATH')),
'isReadOnlyConfig' => $this->isReadOnlyConfig(),
'hasValidTransactionIsolationLevel' => $this->hasValidTransactionIsolationLevel(),
'wasEmailTestSuccessful' => $this->wasEmailTestSuccessful(),
'hasFileinfoInstalled' => $this->hasFileinfoInstalled(),
'hasWorkingFileLocking' => $this->hasWorkingFileLocking(),
'suggestedOverwriteCliURL' => $this->getSuggestedOverwriteCliURL(),
Expand Down
17 changes: 16 additions & 1 deletion apps/settings/lib/Controller/MailSettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use OCP\IConfig;
use OCP\IL10N;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\IUserSession;
use OCP\Mail\IMailer;

Expand All @@ -46,25 +47,30 @@ class MailSettingsController extends Controller {
private $userSession;
/** @var IMailer */
private $mailer;
/** @var IURLGenerator */
private $urlGenerator;

/**
* @param string $appName
* @param IRequest $request
* @param IL10N $l10n
* @param IConfig $config
* @param IUserSession $userSession
* @param IURLGenerator $urlGenerator,
* @param IMailer $mailer
*/
public function __construct($appName,
IRequest $request,
IL10N $l10n,
IConfig $config,
IUserSession $userSession,
IURLGenerator $urlGenerator,
IMailer $mailer) {
parent::__construct($appName, $request);
$this->l10n = $l10n;
$this->config = $config;
$this->userSession = $userSession;
$this->urlGenerator = $urlGenerator;
$this->mailer = $mailer;
}

Expand Down Expand Up @@ -107,6 +113,8 @@ public function setMailSettings($mail_domain,

$this->config->setSystemValues($configs);

$this->config->setAppValue('core', 'emailTestSuccessful', '0');

return new DataResponse();
}

Expand All @@ -130,6 +138,8 @@ public function storeCredentials($mail_smtpname, $mail_smtppassword) {
'mail_smtppassword' => $mail_smtppassword,
]);

$this->config->setAppValue('core', 'emailTestSuccessful', '0');

return new DataResponse();
}

Expand Down Expand Up @@ -159,14 +169,19 @@ public function sendTestMail() {
$message->useTemplate($template);
$errors = $this->mailer->send($message);
if (!empty($errors)) {
$this->config->setAppValue('core', 'emailTestSuccessful', '0');
throw new \RuntimeException($this->l10n->t('Email could not be sent. Check your mail server log'));
}
// Store the successful config in the app config
$this->config->setAppValue('core', 'emailTestSuccessful', '1');
return new DataResponse();
} catch (\Exception $e) {
$this->config->setAppValue('core', 'emailTestSuccessful', '0');
return new DataResponse($this->l10n->t('A problem occurred while sending the email. Please revise your settings. (Error: %s)', [$e->getMessage()]), Http::STATUS_BAD_REQUEST);
}
}

return new DataResponse($this->l10n->t('You need to set your user email before being able to send test emails.'), Http::STATUS_BAD_REQUEST);
$this->config->setAppValue('core', 'emailTestSuccessful', '0');
return new DataResponse($this->l10n->t('You need to set your user email before being able to send test emails. Go to %s for that.', [$this->urlGenerator->linkToRouteAbsolute('settings.PersonalSettings.index')]), Http::STATUS_BAD_REQUEST);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
</form>

<br />
<em><?php p($l->t('Test email settings')); ?></em>
<em><?php p($l->t('Test and verify email settings')); ?></em>
<input type="submit" name="sendtestemail" id="sendtestemail" value="<?php p($l->t('Send email')); ?>"/>
<span id="sendtestmail_msg" class="msg"></span>
</div>
6 changes: 6 additions & 0 deletions apps/settings/tests/Controller/CheckSetupControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ protected function setUp(): void {
])
->setMethods([
'isReadOnlyConfig',
'wasEmailTestSuccessful',
'hasValidTransactionIsolationLevel',
'hasFileinfoInstalled',
'hasWorkingFileLocking',
Expand Down Expand Up @@ -496,6 +497,10 @@ public function testCheck() {
->expects($this->once())
->method('isReadOnlyConfig')
->willReturn(false);
$this->checkSetupController
->expects($this->once())
->method('wasEmailTestSuccessful')
->willReturn(false);
$this->checkSetupController
->expects($this->once())
->method('hasValidTransactionIsolationLevel')
Expand Down Expand Up @@ -594,6 +599,7 @@ public function testCheck() {
[
'isGetenvServerWorking' => true,
'isReadOnlyConfig' => false,
'wasEmailTestSuccessful' => false,
'hasValidTransactionIsolationLevel' => true,
'hasFileinfoInstalled' => true,
'hasWorkingFileLocking' => true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
use OCP\IUserSession;
use OCP\Mail\IEMailTemplate;
use OCP\Mail\IMailer;
use OCP\IURLGenerator;

/**
* @package Tests\Settings\Controller
Expand All @@ -52,6 +53,8 @@ class MailSettingsControllerTest extends \Test\TestCase {
private $mailer;
/** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */
private $l;
/** @var IURLGenerator */
private $urlGenerator;

/** @var MailSettingsController */
private $mailController;
Expand All @@ -63,6 +66,7 @@ protected function setUp(): void {
$this->config = $this->createMock(IConfig::class);
$this->userSession = $this->createMock(IUserSession::class);
$this->mailer = $this->createMock(IMailer::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
/** @var IRequest|\PHPUnit\Framework\MockObject\MockObject $request */
$request = $this->createMock(IRequest::class);
$this->mailController = new MailSettingsController(
Expand All @@ -71,6 +75,7 @@ protected function setUp(): void {
$this->l,
$this->config,
$this->userSession,
$this->urlGenerator,
$this->mailer,
'no-reply@nextcloud.com'
);
Expand Down Expand Up @@ -170,7 +175,7 @@ public function testSendTestMail() {
// Ensure that it fails when no mail address has been specified
$response = $this->mailController->sendTestMail();
$this->assertSame(Http::STATUS_BAD_REQUEST, $response->getStatus());
$this->assertSame('You need to set your user email before being able to send test emails.', $response->getData());
$this->assertSame('You need to set your user email before being able to send test emails. Go to for that.', $response->getData());

// If no exception is thrown it should work
$this->config
Expand Down
8 changes: 8 additions & 0 deletions core/js/setupchecks.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,14 @@
type: OC.SetupChecks.MESSAGE_TYPE_INFO
});
}
if (!data.wasEmailTestSuccessful) {
messages.push({
msg: t('core', 'You have not set or verified your email server configuration, yet. Please head over to the {mailSettingsStart} Basic settings {mailSettingsEnd} in order to set them. Afterwards, use the "Send email" button below the form to verify your settings.',)
.replace('{mailSettingsStart} ', '<a href="' + OC.generateUrl('/settings/admin') + '">')
.replace(' {mailSettingsEnd}', '</a>'),
type: OC.SetupChecks.MESSAGE_TYPE_INFO
});
}
if (!data.hasValidTransactionIsolationLevel) {
messages.push({
msg: t('core', 'Your database does not run with "READ COMMITTED" transaction isolation level. This can cause problems when multiple actions are executed in parallel.'),
Expand Down
Loading