diff options
author | Côme Chilliet <come.chilliet@nextcloud.com> | 2023-10-26 14:45:05 +0200 |
---|---|---|
committer | Côme Chilliet <come.chilliet@nextcloud.com> | 2023-11-07 12:14:02 +0100 |
commit | 5957a2bf6bfbb89c7c6b689e3eef89b7072fe3cf (patch) | |
tree | df20b4279431ea0c612d664572322083637e4d8e /apps/settings | |
parent | 506f3961ecf6616bac81f2c56d5e20d58ab435c6 (diff) | |
download | nextcloud-server-5957a2bf6bfbb89c7c6b689e3eef89b7072fe3cf.tar.gz nextcloud-server-5957a2bf6bfbb89c7c6b689e3eef89b7072fe3cf.zip |
Migrate email test to new SetupCheck API
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'apps/settings')
6 files changed, 80 insertions, 21 deletions
diff --git a/apps/settings/composer/composer/autoload_classmap.php b/apps/settings/composer/composer/autoload_classmap.php index d5c0995bb46..8626e190ff6 100644 --- a/apps/settings/composer/composer/autoload_classmap.php +++ b/apps/settings/composer/composer/autoload_classmap.php @@ -75,6 +75,7 @@ return array( 'OCA\\Settings\\Settings\\Personal\\ServerDevNotice' => $baseDir . '/../lib/Settings/Personal/ServerDevNotice.php', 'OCA\\Settings\\SetupChecks\\CheckUserCertificates' => $baseDir . '/../lib/SetupChecks/CheckUserCertificates.php', 'OCA\\Settings\\SetupChecks\\DefaultPhoneRegionSet' => $baseDir . '/../lib/SetupChecks/DefaultPhoneRegionSet.php', + 'OCA\\Settings\\SetupChecks\\EmailTestSuccessful' => $baseDir . '/../lib/SetupChecks/EmailTestSuccessful.php', 'OCA\\Settings\\SetupChecks\\InternetConnectivity' => $baseDir . '/../lib/SetupChecks/InternetConnectivity.php', 'OCA\\Settings\\SetupChecks\\LegacySSEKeyFormat' => $baseDir . '/../lib/SetupChecks/LegacySSEKeyFormat.php', 'OCA\\Settings\\SetupChecks\\PhpDefaultCharset' => $baseDir . '/../lib/SetupChecks/PhpDefaultCharset.php', diff --git a/apps/settings/composer/composer/autoload_static.php b/apps/settings/composer/composer/autoload_static.php index bf141287ddf..76b2d357cda 100644 --- a/apps/settings/composer/composer/autoload_static.php +++ b/apps/settings/composer/composer/autoload_static.php @@ -90,6 +90,7 @@ class ComposerStaticInitSettings 'OCA\\Settings\\Settings\\Personal\\ServerDevNotice' => __DIR__ . '/..' . '/../lib/Settings/Personal/ServerDevNotice.php', 'OCA\\Settings\\SetupChecks\\CheckUserCertificates' => __DIR__ . '/..' . '/../lib/SetupChecks/CheckUserCertificates.php', 'OCA\\Settings\\SetupChecks\\DefaultPhoneRegionSet' => __DIR__ . '/..' . '/../lib/SetupChecks/DefaultPhoneRegionSet.php', + 'OCA\\Settings\\SetupChecks\\EmailTestSuccessful' => __DIR__ . '/..' . '/../lib/SetupChecks/EmailTestSuccessful.php', 'OCA\\Settings\\SetupChecks\\InternetConnectivity' => __DIR__ . '/..' . '/../lib/SetupChecks/InternetConnectivity.php', 'OCA\\Settings\\SetupChecks\\LegacySSEKeyFormat' => __DIR__ . '/..' . '/../lib/SetupChecks/LegacySSEKeyFormat.php', 'OCA\\Settings\\SetupChecks\\PhpDefaultCharset' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpDefaultCharset.php', diff --git a/apps/settings/lib/AppInfo/Application.php b/apps/settings/lib/AppInfo/Application.php index 7fa20a6a187..3f6333017c4 100644 --- a/apps/settings/lib/AppInfo/Application.php +++ b/apps/settings/lib/AppInfo/Application.php @@ -50,6 +50,7 @@ use OCA\Settings\Search\SectionSearch; use OCA\Settings\Search\UserSearch; use OCA\Settings\SetupChecks\CheckUserCertificates; use OCA\Settings\SetupChecks\DefaultPhoneRegionSet; +use OCA\Settings\SetupChecks\EmailTestSuccessful; use OCA\Settings\SetupChecks\InternetConnectivity; use OCA\Settings\SetupChecks\LegacySSEKeyFormat; use OCA\Settings\SetupChecks\PhpDefaultCharset; @@ -150,6 +151,7 @@ class Application extends App implements IBootstrap { }); $context->registerSetupCheck(CheckUserCertificates::class); $context->registerSetupCheck(DefaultPhoneRegionSet::class); + $context->registerSetupCheck(EmailTestSuccessful::class); $context->registerSetupCheck(InternetConnectivity::class); $context->registerSetupCheck(LegacySSEKeyFormat::class); $context->registerSetupCheck(PhpDefaultCharset::class); diff --git a/apps/settings/lib/Controller/CheckSetupController.php b/apps/settings/lib/Controller/CheckSetupController.php index 4463228fc71..b5d20598cbd 100644 --- a/apps/settings/lib/Controller/CheckSetupController.php +++ b/apps/settings/lib/Controller/CheckSetupController.php @@ -564,20 +564,6 @@ Raw output return str_contains($this->config->getSystemValue('dbtype'), 'sqlite'); } - 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->connection->getDatabaseProvider() === IDBConnection::PLATFORM_SQLITE) { @@ -814,7 +800,6 @@ Raw output return new DataResponse( [ 'hasValidTransactionIsolationLevel' => $this->hasValidTransactionIsolationLevel(), - 'wasEmailTestSuccessful' => $this->wasEmailTestSuccessful(), 'hasFileinfoInstalled' => $this->hasFileinfoInstalled(), 'hasWorkingFileLocking' => $this->hasWorkingFileLocking(), 'hasDBFileLocking' => $this->hasDBFileLocking(), diff --git a/apps/settings/lib/SetupChecks/EmailTestSuccessful.php b/apps/settings/lib/SetupChecks/EmailTestSuccessful.php new file mode 100644 index 00000000000..cced7866fc7 --- /dev/null +++ b/apps/settings/lib/SetupChecks/EmailTestSuccessful.php @@ -0,0 +1,76 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright Copyright (c) 2023 Côme Chilliet <come.chilliet@nextcloud.com> + * + * @author Côme Chilliet <come.chilliet@nextcloud.com> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OCA\Settings\SetupChecks; + +use OCP\IConfig; +use OCP\IL10N; +use OCP\IURLGenerator; +use OCP\SetupCheck\ISetupCheck; +use OCP\SetupCheck\SetupResult; + +class EmailTestSuccessful implements ISetupCheck { + public function __construct( + private IL10N $l10n, + private IConfig $config, + private IURLGenerator $urlGenerator, + ) { + } + + public function getName(): string { + return $this->l10n->t('Email test'); + } + + public function getCategory(): string { + return 'config'; + } + + 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; + } + + public function run(): SetupResult { + if ($this->wasEmailTestSuccessful()) { + return SetupResult::success($this->l10n->t('Email test was successfully sent')); + } else { + // If setup check could link to settings pages, this one should link to OC.generateUrl('/settings/admin') + return SetupResult::info( + $this->l10n->t('You have not set or verified your email server configuration, yet. Please head over to the "Basic settings" in order to set them. Afterwards, use the "Send email" button below the form to verify your settings.'), + $this->urlGenerator->linkToDocs('admin-email') + ); + } + } +} diff --git a/apps/settings/tests/Controller/CheckSetupControllerTest.php b/apps/settings/tests/Controller/CheckSetupControllerTest.php index 80cb1ec9ea1..586b59132ee 100644 --- a/apps/settings/tests/Controller/CheckSetupControllerTest.php +++ b/apps/settings/tests/Controller/CheckSetupControllerTest.php @@ -189,7 +189,6 @@ class CheckSetupControllerTest extends TestCase { $this->setupCheckManager, ]) ->setMethods([ - 'wasEmailTestSuccessful', 'hasValidTransactionIsolationLevel', 'hasFileinfoInstalled', 'hasWorkingFileLocking', @@ -380,10 +379,6 @@ class CheckSetupControllerTest extends TestCase { ->willReturn(false); $this->checkSetupController ->expects($this->once()) - ->method('wasEmailTestSuccessful') - ->willReturn(false); - $this->checkSetupController - ->expects($this->once()) ->method('hasValidTransactionIsolationLevel') ->willReturn(true); $this->checkSetupController @@ -489,7 +484,6 @@ class CheckSetupControllerTest extends TestCase { $expected = new DataResponse( [ - 'wasEmailTestSuccessful' => false, 'hasValidTransactionIsolationLevel' => true, 'hasFileinfoInstalled' => true, 'hasWorkingFileLocking' => true, |