aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCôme Chilliet <come.chilliet@nextcloud.com>2023-10-26 14:45:05 +0200
committerCôme Chilliet <come.chilliet@nextcloud.com>2023-11-07 12:14:02 +0100
commit5957a2bf6bfbb89c7c6b689e3eef89b7072fe3cf (patch)
treedf20b4279431ea0c612d664572322083637e4d8e
parent506f3961ecf6616bac81f2c56d5e20d58ab435c6 (diff)
downloadnextcloud-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>
-rw-r--r--apps/settings/composer/composer/autoload_classmap.php1
-rw-r--r--apps/settings/composer/composer/autoload_static.php1
-rw-r--r--apps/settings/lib/AppInfo/Application.php2
-rw-r--r--apps/settings/lib/Controller/CheckSetupController.php15
-rw-r--r--apps/settings/lib/SetupChecks/EmailTestSuccessful.php76
-rw-r--r--apps/settings/tests/Controller/CheckSetupControllerTest.php6
-rw-r--r--core/js/setupchecks.js8
-rw-r--r--core/js/tests/specs/setupchecksSpec.js87
8 files changed, 80 insertions, 116 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,
diff --git a/core/js/setupchecks.js b/core/js/setupchecks.js
index e94c334db66..04eed184c90 100644
--- a/core/js/setupchecks.js
+++ b/core/js/setupchecks.js
@@ -180,14 +180,6 @@
var afterCall = function(data, statusText, xhr) {
var messages = [];
if (xhr.status === 200 && data) {
- 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.'),
diff --git a/core/js/tests/specs/setupchecksSpec.js b/core/js/tests/specs/setupchecksSpec.js
index 982cb254daa..14f8d95e962 100644
--- a/core/js/tests/specs/setupchecksSpec.js
+++ b/core/js/tests/specs/setupchecksSpec.js
@@ -224,7 +224,6 @@ describe('OC.SetupChecks tests', function() {
},
JSON.stringify({
hasFileinfoInstalled: true,
- wasEmailTestSuccessful: true,
hasWorkingFileLocking: true,
hasDBFileLocking: false,
hasValidTransactionIsolationLevel: true,
@@ -292,7 +291,6 @@ describe('OC.SetupChecks tests', function() {
},
JSON.stringify({
hasFileinfoInstalled: true,
- wasEmailTestSuccessful: true,
hasWorkingFileLocking: true,
hasDBFileLocking: false,
hasValidTransactionIsolationLevel: true,
@@ -360,7 +358,6 @@ describe('OC.SetupChecks tests', function() {
},
JSON.stringify({
hasFileinfoInstalled: true,
- wasEmailTestSuccessful: true,
hasWorkingFileLocking: true,
hasDBFileLocking: false,
hasValidTransactionIsolationLevel: true,
@@ -424,7 +421,6 @@ describe('OC.SetupChecks tests', function() {
},
JSON.stringify({
hasFileinfoInstalled: true,
- wasEmailTestSuccessful: true,
hasWorkingFileLocking: true,
hasDBFileLocking: false,
hasValidTransactionIsolationLevel: true,
@@ -487,7 +483,6 @@ describe('OC.SetupChecks tests', function() {
},
JSON.stringify({
hasFileinfoInstalled: true,
- wasEmailTestSuccessful: true,
hasWorkingFileLocking: true,
hasDBFileLocking: false,
hasValidTransactionIsolationLevel: true,
@@ -540,69 +535,6 @@ describe('OC.SetupChecks tests', function() {
});
});
- it('should return an info if the mail server config was not set or verified, yet', function(done) {
- var async = OC.SetupChecks.checkSetup();
-
- suite.server.requests[0].respond(
- 200,
- {
- 'Content-Type': 'application/json'
- },
- JSON.stringify({
- hasFileinfoInstalled: true,
- wasEmailTestSuccessful: false,
- hasWorkingFileLocking: true,
- hasDBFileLocking: false,
- hasValidTransactionIsolationLevel: true,
- suggestedOverwriteCliURL: '',
- isRandomnessSecure: true,
- securityDocs: 'https://docs.nextcloud.com/myDocs.html',
- isFairUseOfFreePushService: true,
- isMemcacheConfigured: true,
- forwardedForHeadersWorking: true,
- isCorrectMemcachedPHPModuleInstalled: true,
- hasPassedCodeIntegrityCheck: true,
- OpcacheSetupRecommendations: [],
- isSettimelimitAvailable: true,
- hasFreeTypeSupport: true,
- missingIndexes: [],
- missingPrimaryKeys: [],
- missingColumns: [],
- cronErrors: [],
- cronInfo: {
- diffInSeconds: 0
- },
- isMemoryLimitSufficient: true,
- appDirsWithDifferentOwner: [],
- isImagickEnabled: true,
- areWebauthnExtensionsEnabled: true,
- is64bit: true,
- pendingBigIntConversionColumns: [],
- isMysqlUsedWithoutUTF8MB4: false,
- isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true,
- reverseProxyGeneratedURL: 'https://server',
- temporaryDirectoryWritable: true,
- generic: {
- network: {
- "Internet connectivity": {
- severity: "success",
- description: null,
- linkToDoc: null
- }
- },
- },
- })
- );
-
- async.done(function( data, s, x ){
- expect(data).toEqual([{
- msg: 'You have not set or verified your email server configuration, yet. Please head over to the <a href="http://localhost/index.php/settings/admin">Basic settings</a> in order to set them. Afterwards, use the "Send email" button below the form to verify your settings.',
- type: OC.SetupChecks.MESSAGE_TYPE_INFO
- }]);
- done();
- });
- });
-
it('should return an info if transactional file locking is not set up', function(done) {
var async = OC.SetupChecks.checkSetup();
@@ -613,7 +545,6 @@ describe('OC.SetupChecks tests', function() {
},
JSON.stringify({
hasFileinfoInstalled: true,
- wasEmailTestSuccessful: true,
hasWorkingFileLocking: false,
hasDBFileLocking: false,
hasValidTransactionIsolationLevel: true,
@@ -676,7 +607,6 @@ describe('OC.SetupChecks tests', function() {
},
JSON.stringify({
hasFileinfoInstalled: true,
- wasEmailTestSuccessful: true,
hasWorkingFileLocking: true,
hasDBFileLocking: true,
hasValidTransactionIsolationLevel: true,
@@ -739,7 +669,6 @@ describe('OC.SetupChecks tests', function() {
},
JSON.stringify({
hasFileinfoInstalled: true,
- wasEmailTestSuccessful: true,
hasWorkingFileLocking: true,
hasDBFileLocking: false,
hasValidTransactionIsolationLevel: true,
@@ -804,7 +733,6 @@ describe('OC.SetupChecks tests', function() {
},
JSON.stringify({
hasFileinfoInstalled: true,
- wasEmailTestSuccessful: true,
hasWorkingFileLocking: true,
hasDBFileLocking: false,
hasValidTransactionIsolationLevel: true,
@@ -867,7 +795,6 @@ describe('OC.SetupChecks tests', function() {
},
JSON.stringify({
hasFileinfoInstalled: true,
- wasEmailTestSuccessful: true,
hasWorkingFileLocking: true,
hasDBFileLocking: false,
hasValidTransactionIsolationLevel: true,
@@ -932,7 +859,6 @@ describe('OC.SetupChecks tests', function() {
},
JSON.stringify({
hasFileinfoInstalled: true,
- wasEmailTestSuccessful: true,
hasWorkingFileLocking: true,
hasDBFileLocking: false,
hasValidTransactionIsolationLevel: true,
@@ -995,7 +921,6 @@ describe('OC.SetupChecks tests', function() {
},
JSON.stringify({
hasFileinfoInstalled: true,
- wasEmailTestSuccessful: true,
hasWorkingFileLocking: true,
hasDBFileLocking: false,
hasValidTransactionIsolationLevel: true,
@@ -1078,7 +1003,6 @@ describe('OC.SetupChecks tests', function() {
},
JSON.stringify({
hasFileinfoInstalled: true,
- wasEmailTestSuccessful: true,
hasWorkingFileLocking: true,
hasDBFileLocking: false,
hasValidTransactionIsolationLevel: true,
@@ -1148,7 +1072,6 @@ describe('OC.SetupChecks tests', function() {
},
JSON.stringify({
hasFileinfoInstalled: true,
- wasEmailTestSuccessful: true,
hasWorkingFileLocking: true,
hasDBFileLocking: false,
hasValidTransactionIsolationLevel: true,
@@ -1211,7 +1134,6 @@ describe('OC.SetupChecks tests', function() {
},
JSON.stringify({
hasFileinfoInstalled: true,
- wasEmailTestSuccessful: true,
hasWorkingFileLocking: true,
hasDBFileLocking: false,
hasValidTransactionIsolationLevel: true,
@@ -1274,7 +1196,6 @@ describe('OC.SetupChecks tests', function() {
},
JSON.stringify({
hasFileinfoInstalled: true,
- wasEmailTestSuccessful: true,
hasWorkingFileLocking: true,
hasDBFileLocking: false,
hasValidTransactionIsolationLevel: true,
@@ -1341,7 +1262,6 @@ describe('OC.SetupChecks tests', function() {
},
JSON.stringify({
hasFileinfoInstalled: true,
- wasEmailTestSuccessful: true,
hasWorkingFileLocking: true,
hasDBFileLocking: false,
hasValidTransactionIsolationLevel: true,
@@ -1405,7 +1325,6 @@ describe('OC.SetupChecks tests', function() {
},
JSON.stringify({
hasFileinfoInstalled: true,
- wasEmailTestSuccessful: true,
hasWorkingFileLocking: true,
hasDBFileLocking: false,
hasValidTransactionIsolationLevel: true,
@@ -1466,7 +1385,6 @@ describe('OC.SetupChecks tests', function() {
},
JSON.stringify({
hasFileinfoInstalled: true,
- wasEmailTestSuccessful: true,
hasWorkingFileLocking: true,
hasDBFileLocking: false,
hasValidTransactionIsolationLevel: true,
@@ -1530,7 +1448,6 @@ describe('OC.SetupChecks tests', function() {
},
JSON.stringify({
hasFileinfoInstalled: true,
- wasEmailTestSuccessful: true,
hasWorkingFileLocking: true,
hasDBFileLocking: false,
hasValidTransactionIsolationLevel: true,
@@ -1594,7 +1511,6 @@ describe('OC.SetupChecks tests', function() {
},
JSON.stringify({
hasFileinfoInstalled: true,
- wasEmailTestSuccessful: true,
hasWorkingFileLocking: true,
hasDBFileLocking: false,
hasValidTransactionIsolationLevel: true,
@@ -1657,7 +1573,6 @@ describe('OC.SetupChecks tests', function() {
},
JSON.stringify({
hasFileinfoInstalled: true,
- wasEmailTestSuccessful: true,
hasWorkingFileLocking: true,
hasDBFileLocking: false,
hasValidTransactionIsolationLevel: true,
@@ -1720,7 +1635,6 @@ describe('OC.SetupChecks tests', function() {
},
JSON.stringify({
hasFileinfoInstalled: true,
- wasEmailTestSuccessful: true,
hasWorkingFileLocking: true,
hasDBFileLocking: false,
hasValidTransactionIsolationLevel: true,
@@ -1790,7 +1704,6 @@ describe('OC.SetupChecks tests', function() {
},
JSON.stringify({
hasFileinfoInstalled: true,
- wasEmailTestSuccessful: true,
hasWorkingFileLocking: true,
hasDBFileLocking: false,
hasValidTransactionIsolationLevel: true,