]> source.dussan.org Git - nextcloud-server.git/commitdiff
Migrate overwrite.cli.url setup check to new API
authorCôme Chilliet <come.chilliet@nextcloud.com>
Mon, 15 Jan 2024 12:54:26 +0000 (13:54 +0100)
committerCôme Chilliet <91878298+come-nc@users.noreply.github.com>
Tue, 16 Jan 2024 08:05:40 +0000 (09:05 +0100)
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
apps/settings/composer/composer/autoload_classmap.php
apps/settings/composer/composer/autoload_static.php
apps/settings/lib/AppInfo/Application.php
apps/settings/lib/Controller/CheckSetupController.php
apps/settings/lib/SetupChecks/OverwriteCliUrl.php [new file with mode: 0644]
apps/settings/tests/Controller/CheckSetupControllerTest.php
core/js/setupchecks.js
core/js/tests/specs/setupchecksSpec.js

index 45640278a97de897da37366ed04ff48ca014c343..bfd2901fed54e67a70dd3dffa84977d92846c22f 100644 (file)
@@ -93,6 +93,7 @@ return array(
     'OCA\\Settings\\SetupChecks\\LegacySSEKeyFormat' => $baseDir . '/../lib/SetupChecks/LegacySSEKeyFormat.php',
     'OCA\\Settings\\SetupChecks\\MaintenanceWindowStart' => $baseDir . '/../lib/SetupChecks/MaintenanceWindowStart.php',
     'OCA\\Settings\\SetupChecks\\MemcacheConfigured' => $baseDir . '/../lib/SetupChecks/MemcacheConfigured.php',
+    'OCA\\Settings\\SetupChecks\\OverwriteCliUrl' => $baseDir . '/../lib/SetupChecks/OverwriteCliUrl.php',
     'OCA\\Settings\\SetupChecks\\PhpDefaultCharset' => $baseDir . '/../lib/SetupChecks/PhpDefaultCharset.php',
     'OCA\\Settings\\SetupChecks\\PhpFreetypeSupport' => $baseDir . '/../lib/SetupChecks/PhpFreetypeSupport.php',
     'OCA\\Settings\\SetupChecks\\PhpGetEnv' => $baseDir . '/../lib/SetupChecks/PhpGetEnv.php',
index bf48c7ee4507fbe122696418fd7ae5025fd37091..51c5bb04be9e0faae5b1cb3a0308b7b325fac2e1 100644 (file)
@@ -108,6 +108,7 @@ class ComposerStaticInitSettings
         'OCA\\Settings\\SetupChecks\\LegacySSEKeyFormat' => __DIR__ . '/..' . '/../lib/SetupChecks/LegacySSEKeyFormat.php',
         'OCA\\Settings\\SetupChecks\\MaintenanceWindowStart' => __DIR__ . '/..' . '/../lib/SetupChecks/MaintenanceWindowStart.php',
         'OCA\\Settings\\SetupChecks\\MemcacheConfigured' => __DIR__ . '/..' . '/../lib/SetupChecks/MemcacheConfigured.php',
+        'OCA\\Settings\\SetupChecks\\OverwriteCliUrl' => __DIR__ . '/..' . '/../lib/SetupChecks/OverwriteCliUrl.php',
         'OCA\\Settings\\SetupChecks\\PhpDefaultCharset' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpDefaultCharset.php',
         'OCA\\Settings\\SetupChecks\\PhpFreetypeSupport' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpFreetypeSupport.php',
         'OCA\\Settings\\SetupChecks\\PhpGetEnv' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpGetEnv.php',
index f8796a90dbe3d0ef07532f9d401c8ccad8b7ec2d..8b2e9e12a1eedea8744d131169ea725975f76c92 100644 (file)
@@ -65,6 +65,7 @@ use OCA\Settings\SetupChecks\JavaScriptModules;
 use OCA\Settings\SetupChecks\LegacySSEKeyFormat;
 use OCA\Settings\SetupChecks\MaintenanceWindowStart;
 use OCA\Settings\SetupChecks\MemcacheConfigured;
+use OCA\Settings\SetupChecks\OverwriteCliUrl;
 use OCA\Settings\SetupChecks\PhpDefaultCharset;
 use OCA\Settings\SetupChecks\PhpFreetypeSupport;
 use OCA\Settings\SetupChecks\PhpGetEnv;
@@ -184,6 +185,7 @@ class Application extends App implements IBootstrap {
                $context->registerSetupCheck(LegacySSEKeyFormat::class);
                $context->registerSetupCheck(MaintenanceWindowStart::class);
                $context->registerSetupCheck(MemcacheConfigured::class);
+               $context->registerSetupCheck(OverwriteCliUrl::class);
                $context->registerSetupCheck(PhpDefaultCharset::class);
                $context->registerSetupCheck(PhpFreetypeSupport::class);
                $context->registerSetupCheck(PhpGetEnv::class);
index eb6664c5e472d04ff4b509eb64118d18044a7996..c7f1f59ba7d888c7114886af36bf359296cb4207 100644 (file)
@@ -302,18 +302,6 @@ Raw output
                );
        }
 
-       protected function getSuggestedOverwriteCliURL(): string {
-               $currentOverwriteCliUrl = $this->config->getSystemValue('overwrite.cli.url', '');
-               $suggestedOverwriteCliUrl = $this->request->getServerProtocol() . '://' . $this->request->getInsecureServerHost() . \OC::$WEBROOT;
-
-               // Check correctness by checking if it is a valid URL
-               if (filter_var($currentOverwriteCliUrl, FILTER_VALIDATE_URL)) {
-                       $suggestedOverwriteCliUrl = '';
-               }
-
-               return $suggestedOverwriteCliUrl;
-       }
-
        protected function getLastCronInfo(): array {
                $lastCronRun = (int)$this->config->getAppValue('core', 'lastcron', '0');
                return [
@@ -400,7 +388,6 @@ Raw output
        public function check() {
                return new DataResponse(
                        [
-                               'suggestedOverwriteCliURL' => $this->getSuggestedOverwriteCliURL(),
                                'cronInfo' => $this->getLastCronInfo(),
                                'cronErrors' => $this->getCronErrors(),
                                'isFairUseOfFreePushService' => $this->isFairUseOfFreePushService(),
diff --git a/apps/settings/lib/SetupChecks/OverwriteCliUrl.php b/apps/settings/lib/SetupChecks/OverwriteCliUrl.php
new file mode 100644 (file)
index 0000000..39c2211
--- /dev/null
@@ -0,0 +1,81 @@
+<?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\IRequest;
+use OCP\SetupCheck\ISetupCheck;
+use OCP\SetupCheck\SetupResult;
+
+class OverwriteCliUrl implements ISetupCheck {
+       public function __construct(
+               private IL10N $l10n,
+               private IConfig $config,
+               private IRequest $request,
+       ) {
+       }
+
+       public function getCategory(): string {
+               return 'config';
+       }
+
+       public function getName(): string {
+               return $this->l10n->t('Overwrite cli URL');
+       }
+
+       public function run(): SetupResult {
+               $currentOverwriteCliUrl = $this->config->getSystemValue('overwrite.cli.url', '');
+               $suggestedOverwriteCliUrl = $this->request->getServerProtocol() . '://' . $this->request->getInsecureServerHost() . \OC::$WEBROOT;
+
+               // Check correctness by checking if it is a valid URL
+               if (filter_var($currentOverwriteCliUrl, FILTER_VALIDATE_URL)) {
+                       if ($currentOverwriteCliUrl == $suggestedOverwriteCliUrl) {
+                               return SetupResult::success(
+                                       $this->l10n->t(
+                                               'The "overwrite.cli.url" option in your config.php is correctly set to "%s".',
+                                               [$currentOverwriteCliUrl]
+                                       )
+                               );
+                       } else {
+                               return SetupResult::success(
+                                       $this->l10n->t(
+                                               'The "overwrite.cli.url" option in your config.php is set to "%s" which is a correct URL. Suggested URL is "%s".',
+                                               [$currentOverwriteCliUrl, $suggestedOverwriteCliUrl]
+                                       )
+                               );
+                       }
+               } else {
+                       return SetupResult::warning(
+                               $this->l10n->t(
+                                       'Please make sure to set the "overwrite.cli.url" option in your config.php file to the URL that your users mainly use to access this Nextcloud. Suggestion: "%s". Otherwise there might be problems with the URL generation via cron. (It is possible though that the suggested URL is not the URL that your users mainly use to access this Nextcloud. Best is to double check this in any case.)',
+                                       [$suggestedOverwriteCliUrl]
+                               )
+                       );
+               }
+       }
+}
index b8f97b60bd51039c857bb0af2cb9c8c4c8f049d8..022094100cbb03706c6c0c688cddf4e3b480c0a2 100644 (file)
@@ -220,7 +220,6 @@ class CheckSetupControllerTest extends TestCase {
 
                $expected = new DataResponse(
                        [
-                               'suggestedOverwriteCliURL' => '',
                                'cronInfo' => [
                                        'diffInSeconds' => 123,
                                        'relativeTime' => '2 hours ago',
index 99e289e5e54e04114c7b8e3fb0575f4e9e269f67..8a70b6b81073e59818e7c59204b53c4dd56e3a8f 100644 (file)
                        var afterCall = function(data, statusText, xhr) {
                                var messages = [];
                                if (xhr.status === 200 && data) {
-                                       if (data.suggestedOverwriteCliURL !== '') {
-                                               messages.push({
-                                                       msg: t('core', 'Please make sure to set the "overwrite.cli.url" option in your config.php file to the URL that your users mainly use to access this Nextcloud. Suggestion: "{suggestedOverwriteCliURL}". Otherwise there might be problems with the URL generation via cron. (It is possible though that the suggested URL is not the URL that your users mainly use to access this Nextcloud. Best is to double check this in any case.)', {suggestedOverwriteCliURL: data.suggestedOverwriteCliURL}),
-                                                       type: OC.SetupChecks.MESSAGE_TYPE_WARNING
-                                               });
-                                       }
                                        if (data.cronErrors.length > 0) {
                                                var listOfCronErrors = "";
                                                data.cronErrors.forEach(function(element){
index 5e879974fc93882bcef2c705b19fb04d60e07f49..7ed100d863b56db92996b7e0a803aabb4b5593d4 100644 (file)
@@ -223,7 +223,6 @@ describe('OC.SetupChecks tests', function() {
                                        'Content-Type': 'application/json'
                                },
                                JSON.stringify({
-                                       suggestedOverwriteCliURL: '',
                                        isFairUseOfFreePushService: true,
                                        isCorrectMemcachedPHPModuleInstalled: true,
                                        isSettimelimitAvailable: true,
@@ -268,7 +267,6 @@ describe('OC.SetupChecks tests', function() {
                                        'Content-Type': 'application/json'
                                },
                                JSON.stringify({
-                                       suggestedOverwriteCliURL: '',
                                        isFairUseOfFreePushService: true,
                                        isCorrectMemcachedPHPModuleInstalled: true,
                                        isSettimelimitAvailable: true,
@@ -313,7 +311,6 @@ describe('OC.SetupChecks tests', function() {
                                        'Content-Type': 'application/json',
                                },
                                JSON.stringify({
-                                       suggestedOverwriteCliURL: '',
                                        isFairUseOfFreePushService: true,
                                        isCorrectMemcachedPHPModuleInstalled: true,
                                        isSettimelimitAvailable: true,
@@ -358,7 +355,6 @@ describe('OC.SetupChecks tests', function() {
                                        'Content-Type': 'application/json',
                                },
                                JSON.stringify({
-                                       suggestedOverwriteCliURL: '',
                                        isFairUseOfFreePushService: true,
                                        isCorrectMemcachedPHPModuleInstalled: false,
                                        isSettimelimitAvailable: true,
@@ -401,7 +397,6 @@ describe('OC.SetupChecks tests', function() {
                                        'Content-Type': 'application/json',
                                },
                                JSON.stringify({
-                                       suggestedOverwriteCliURL: '',
                                        isFairUseOfFreePushService: true,
                                        reverseProxyDocs: 'https://docs.nextcloud.com/foo/bar.html',
                                        isCorrectMemcachedPHPModuleInstalled: true,
@@ -445,7 +440,6 @@ describe('OC.SetupChecks tests', function() {
                                        'Content-Type': 'application/json',
                                },
                                JSON.stringify({
-                                       suggestedOverwriteCliURL: '',
                                        isFairUseOfFreePushService: true,
                                        reverseProxyDocs: 'https://docs.nextcloud.com/foo/bar.html',
                                        isCorrectMemcachedPHPModuleInstalled: true,
@@ -521,7 +515,6 @@ describe('OC.SetupChecks tests', function() {
                                        'Content-Type': 'application/json',
                                },
                                JSON.stringify({
-                                       suggestedOverwriteCliURL: '',
                                        isFairUseOfFreePushService: true,
                                        isCorrectMemcachedPHPModuleInstalled: true,
                                        isSettimelimitAvailable: true,
@@ -571,7 +564,6 @@ describe('OC.SetupChecks tests', function() {
                                        'Content-Type': 'application/json',
                                },
                                JSON.stringify({
-                                       suggestedOverwriteCliURL: '',
                                        isFairUseOfFreePushService: true,
                                        isCorrectMemcachedPHPModuleInstalled: true,
                                        isSettimelimitAvailable: true,
@@ -618,7 +610,6 @@ describe('OC.SetupChecks tests', function() {
                                        'Content-Type': 'application/json',
                                },
                                JSON.stringify({
-                                       suggestedOverwriteCliURL: '',
                                        isFairUseOfFreePushService: true,
                                        isCorrectMemcachedPHPModuleInstalled: true,
                                        isSettimelimitAvailable: true,
@@ -662,7 +653,6 @@ describe('OC.SetupChecks tests', function() {
                                        'Content-Type': 'application/json',
                                },
                                JSON.stringify({
-                                       suggestedOverwriteCliURL: '',
                                        isFairUseOfFreePushService: true,
                                        isCorrectMemcachedPHPModuleInstalled: true,
                                        isSettimelimitAvailable: true,
@@ -703,7 +693,6 @@ describe('OC.SetupChecks tests', function() {
                                        'Content-Type': 'application/json',
                                },
                                JSON.stringify({
-                                       suggestedOverwriteCliURL: '',
                                        isFairUseOfFreePushService: true,
                                        isCorrectMemcachedPHPModuleInstalled: true,
                                        isSettimelimitAvailable: true,
@@ -746,7 +735,6 @@ describe('OC.SetupChecks tests', function() {
                                        'Content-Type': 'application/json',
                                },
                                JSON.stringify({
-                                       suggestedOverwriteCliURL: '',
                                        isFairUseOfFreePushService: true,
                                        isCorrectMemcachedPHPModuleInstalled: true,
                                        isSettimelimitAvailable: true,
@@ -789,7 +777,6 @@ describe('OC.SetupChecks tests', function() {
                                        'Content-Type': 'application/json',
                                },
                                JSON.stringify({
-                                       suggestedOverwriteCliURL: '',
                                        isFairUseOfFreePushService: true,
                                        isCorrectMemcachedPHPModuleInstalled: true,
                                        isSettimelimitAvailable: true,
@@ -839,7 +826,6 @@ describe('OC.SetupChecks tests', function() {
                                        'Content-Type': 'application/json',
                                },
                                JSON.stringify({
-                                       suggestedOverwriteCliURL: '',
                                        isFairUseOfFreePushService: true,
                                        isCorrectMemcachedPHPModuleInstalled: true,
                                        isSettimelimitAvailable: true,