mirror of
https://github.com/nextcloud/server.git
synced 2026-04-15 22:11:17 -04:00
Migrate email test to new SetupCheck API
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
parent
506f3961ec
commit
5957a2bf6b
8 changed files with 80 additions and 116 deletions
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
|
|
|
|||
76
apps/settings/lib/SetupChecks/EmailTestSuccessful.php
Normal file
76
apps/settings/lib/SetupChecks/EmailTestSuccessful.php
Normal file
|
|
@ -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')
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -189,7 +189,6 @@ class CheckSetupControllerTest extends TestCase {
|
|||
$this->setupCheckManager,
|
||||
])
|
||||
->setMethods([
|
||||
'wasEmailTestSuccessful',
|
||||
'hasValidTransactionIsolationLevel',
|
||||
'hasFileinfoInstalled',
|
||||
'hasWorkingFileLocking',
|
||||
|
|
@ -378,10 +377,6 @@ class CheckSetupControllerTest extends TestCase {
|
|||
$this->checkSetupController
|
||||
->method('isSqliteUsed')
|
||||
->willReturn(false);
|
||||
$this->checkSetupController
|
||||
->expects($this->once())
|
||||
->method('wasEmailTestSuccessful')
|
||||
->willReturn(false);
|
||||
$this->checkSetupController
|
||||
->expects($this->once())
|
||||
->method('hasValidTransactionIsolationLevel')
|
||||
|
|
@ -489,7 +484,6 @@ class CheckSetupControllerTest extends TestCase {
|
|||
|
||||
$expected = new DataResponse(
|
||||
[
|
||||
'wasEmailTestSuccessful' => false,
|
||||
'hasValidTransactionIsolationLevel' => true,
|
||||
'hasFileinfoInstalled' => true,
|
||||
'hasWorkingFileLocking' => true,
|
||||
|
|
|
|||
|
|
@ -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.'),
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in a new issue