]> source.dussan.org Git - nextcloud-server.git/commitdiff
Migrate fair use of free push service check to new SetupCheck API
authorCôme Chilliet <come.chilliet@nextcloud.com>
Thu, 18 Jan 2024 14:53:03 +0000 (15:53 +0100)
committerCôme Chilliet <come.chilliet@nextcloud.com>
Thu, 25 Jan 2024 12:05:59 +0000 (13: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/FairUseOfFreePushService.php [new file with mode: 0644]
apps/settings/tests/Controller/CheckSetupControllerTest.php
core/js/setupchecks.js
core/js/tests/specs/setupchecksSpec.js

index 6e641fab4c64f5cbe0ce75b3ab1d90fe6ad7ba95..866c27f0f25a84c240843b1163c463a341e03283 100644 (file)
@@ -88,6 +88,7 @@ return array(
     'OCA\\Settings\\SetupChecks\\DatabasePendingBigIntConversions' => $baseDir . '/../lib/SetupChecks/DatabasePendingBigIntConversions.php',
     'OCA\\Settings\\SetupChecks\\DefaultPhoneRegionSet' => $baseDir . '/../lib/SetupChecks/DefaultPhoneRegionSet.php',
     'OCA\\Settings\\SetupChecks\\EmailTestSuccessful' => $baseDir . '/../lib/SetupChecks/EmailTestSuccessful.php',
+    'OCA\\Settings\\SetupChecks\\FairUseOfFreePushService' => $baseDir . '/../lib/SetupChecks/FairUseOfFreePushService.php',
     'OCA\\Settings\\SetupChecks\\FileLocking' => $baseDir . '/../lib/SetupChecks/FileLocking.php',
     'OCA\\Settings\\SetupChecks\\ForwardedForHeaders' => $baseDir . '/../lib/SetupChecks/ForwardedForHeaders.php',
     'OCA\\Settings\\SetupChecks\\InternetConnectivity' => $baseDir . '/../lib/SetupChecks/InternetConnectivity.php',
index 9b775f4358b702a2899ee9bcc83f1cc015716d99..99dd68250c126ee26509e8960f9e895955e64f23 100644 (file)
@@ -103,6 +103,7 @@ class ComposerStaticInitSettings
         'OCA\\Settings\\SetupChecks\\DatabasePendingBigIntConversions' => __DIR__ . '/..' . '/../lib/SetupChecks/DatabasePendingBigIntConversions.php',
         'OCA\\Settings\\SetupChecks\\DefaultPhoneRegionSet' => __DIR__ . '/..' . '/../lib/SetupChecks/DefaultPhoneRegionSet.php',
         'OCA\\Settings\\SetupChecks\\EmailTestSuccessful' => __DIR__ . '/..' . '/../lib/SetupChecks/EmailTestSuccessful.php',
+        'OCA\\Settings\\SetupChecks\\FairUseOfFreePushService' => __DIR__ . '/..' . '/../lib/SetupChecks/FairUseOfFreePushService.php',
         'OCA\\Settings\\SetupChecks\\FileLocking' => __DIR__ . '/..' . '/../lib/SetupChecks/FileLocking.php',
         'OCA\\Settings\\SetupChecks\\ForwardedForHeaders' => __DIR__ . '/..' . '/../lib/SetupChecks/ForwardedForHeaders.php',
         'OCA\\Settings\\SetupChecks\\InternetConnectivity' => __DIR__ . '/..' . '/../lib/SetupChecks/InternetConnectivity.php',
index 0cb8d6771e84434ea0d56e987c8e965943a452e4..6c6b430fdb3cdce63270667e8c1a653ac053dca6 100644 (file)
@@ -60,6 +60,7 @@ use OCA\Settings\SetupChecks\DatabaseHasMissingPrimaryKeys;
 use OCA\Settings\SetupChecks\DatabasePendingBigIntConversions;
 use OCA\Settings\SetupChecks\DefaultPhoneRegionSet;
 use OCA\Settings\SetupChecks\EmailTestSuccessful;
+use OCA\Settings\SetupChecks\FairUseOfFreePushService;
 use OCA\Settings\SetupChecks\FileLocking;
 use OCA\Settings\SetupChecks\ForwardedForHeaders;
 use OCA\Settings\SetupChecks\InternetConnectivity;
@@ -209,6 +210,9 @@ class Application extends App implements IBootstrap {
                $context->registerSetupCheck(SystemIs64bit::class);
                $context->registerSetupCheck(TempSpaceAvailable::class);
                $context->registerSetupCheck(TransactionIsolation::class);
+               if (!\OCP\Server::get(\OCP\Support\Subscription\IRegistry::class)->delegateHasValidSubscription()) {
+                       $context->registerSetupCheck(FairUseOfFreePushService::class);
+               }
 
                $context->registerUserMigrator(AccountMigrator::class);
        }
index 323c673b0d094e8b4dda26975b570d6ae82f65ac..8008351838556c35945c9d07b0c22f3439886415 100644 (file)
@@ -56,7 +56,6 @@ use OCP\IConfig;
 use OCP\IL10N;
 use OCP\IRequest;
 use OCP\IURLGenerator;
-use OCP\Notification\IManager;
 use OCP\SetupCheck\ISetupCheckManager;
 use Psr\Log\LoggerInterface;
 
@@ -72,8 +71,6 @@ class CheckSetupController extends Controller {
        private $checker;
        /** @var LoggerInterface */
        private $logger;
-       /** @var IManager */
-       private $manager;
        private ISetupCheckManager $setupCheckManager;
 
        public function __construct($AppName,
@@ -83,7 +80,6 @@ class CheckSetupController extends Controller {
                IL10N $l10n,
                Checker $checker,
                LoggerInterface $logger,
-               IManager $manager,
                ISetupCheckManager $setupCheckManager,
        ) {
                parent::__construct($AppName, $request);
@@ -92,7 +88,6 @@ class CheckSetupController extends Controller {
                $this->l10n = $l10n;
                $this->checker = $checker;
                $this->logger = $logger;
-               $this->manager = $manager;
                $this->setupCheckManager = $setupCheckManager;
        }
 
@@ -105,19 +100,6 @@ class CheckSetupController extends Controller {
                return new DataResponse($this->setupCheckManager->runAll());
        }
 
-       /**
-        * Check if is fair use of free push service
-        * @return bool
-        */
-       private function isFairUseOfFreePushService(): bool {
-               $rateLimitReached = (int) $this->config->getAppValue('notifications', 'rate_limit_reached', '0');
-               if ($rateLimitReached >= (time() - 7 * 24 * 3600)) {
-                       // Notifications app is showing a message already
-                       return true;
-               }
-               return $this->manager->isFairUseOfFreePushService();
-       }
-
        /**
         * @NoCSRFRequired
         * @return RedirectResponse
@@ -194,7 +176,6 @@ Raw output
        public function check() {
                return new DataResponse(
                        [
-                               'isFairUseOfFreePushService' => $this->isFairUseOfFreePushService(),
                                'reverseProxyDocs' => $this->urlGenerator->linkToDocs('admin-reverse-proxy'),
                                'reverseProxyGeneratedURL' => $this->urlGenerator->getAbsoluteURL('index.php'),
                                'generic' => $this->setupCheckManager->runAll(),
diff --git a/apps/settings/lib/SetupChecks/FairUseOfFreePushService.php b/apps/settings/lib/SetupChecks/FairUseOfFreePushService.php
new file mode 100644 (file)
index 0000000..431d1be
--- /dev/null
@@ -0,0 +1,79 @@
+<?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\Notification\IManager;
+use OCP\SetupCheck\ISetupCheck;
+use OCP\SetupCheck\SetupResult;
+
+class FairUseOfFreePushService implements ISetupCheck {
+       public function __construct(
+               private IL10N $l10n,
+               private IConfig $config,
+               private IManager $notificationsManager,
+       ) {
+       }
+
+       public function getName(): string {
+               return $this->l10n->t('Free push service');
+       }
+
+       public function getCategory(): string {
+               return 'system';
+       }
+
+       /**
+        * Check if is fair use of free push service
+        */
+       private function isFairUseOfFreePushService(): bool {
+               $rateLimitReached = (int) $this->config->getAppValue('notifications', 'rate_limit_reached', '0');
+               if ($rateLimitReached >= (time() - 7 * 24 * 3600)) {
+                       // Notifications app is showing a message already
+                       return true;
+               }
+               return $this->notificationsManager->isFairUseOfFreePushService();
+       }
+
+       public function run(): SetupResult {
+               if ($this->isFairUseOfFreePushService()) {
+                       return SetupResult::success();
+               }
+
+               return SetupResult::error(
+                       $this->l10n->t('This is the unsupported community build of Nextcloud. Given the size of this instance, performance, reliability and scalability cannot be guaranteed. Push notifications are limited to avoid overloading our free service. Learn more about the benefits of Nextcloud Enterprise at {link}.'),
+                       descriptionParameters:[
+                               'link' => [
+                                       'type' => 'highlight',
+                                       'id' => 'link',
+                                       'name' => 'https://nextcloud.com/enterprise',
+                                       'link' => 'https://nextcloud.com/enterprise',
+                               ],
+                       ],
+               );
+       }
+}
index c83273b467d8dea81ef69bf93afc6b1370eae19c..924a76fa4f55ae28be76660445518cd34a221698 100644 (file)
@@ -44,7 +44,6 @@ use OCP\IConfig;
 use OCP\IL10N;
 use OCP\IRequest;
 use OCP\IURLGenerator;
-use OCP\Notification\IManager;
 use OCP\SetupCheck\ISetupCheckManager;
 use PHPUnit\Framework\MockObject\MockObject;
 use Psr\Log\LoggerInterface;
@@ -71,8 +70,6 @@ class CheckSetupControllerTest extends TestCase {
        private $logger;
        /** @var Checker|\PHPUnit\Framework\MockObject\MockObject */
        private $checker;
-       /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
-       private $notificationManager;
        /** @var ISetupCheckManager|MockObject */
        private $setupCheckManager;
 
@@ -95,7 +92,6 @@ class CheckSetupControllerTest extends TestCase {
                $this->checker = $this->getMockBuilder('\OC\IntegrityCheck\Checker')
                                ->disableOriginalConstructor()->getMock();
                $this->logger = $this->getMockBuilder(LoggerInterface::class)->getMock();
-               $this->notificationManager = $this->getMockBuilder(IManager::class)->getMock();
                $this->setupCheckManager = $this->createMock(ISetupCheckManager::class);
                $this->checkSetupController = $this->getMockBuilder(CheckSetupController::class)
                        ->setConstructorArgs([
@@ -106,7 +102,6 @@ class CheckSetupControllerTest extends TestCase {
                                $this->l10n,
                                $this->checker,
                                $this->logger,
-                               $this->notificationManager,
                                $this->setupCheckManager,
                        ])
                        ->setMethods([
@@ -170,7 +165,6 @@ class CheckSetupControllerTest extends TestCase {
                        [
                                'reverseProxyDocs' => 'reverse-proxy-doc-link',
                                'reverseProxyGeneratedURL' => 'https://server/index.php',
-                               'isFairUseOfFreePushService' => false,
                                'generic' => [],
                        ]
                );
index 7864169dd2b0a9393476db64a975fda3ecf3d238..7400d02d30d38dee8a8d1bb3e3c4558913c5c3c6 100644 (file)
                        var afterCall = function(data, statusText, xhr) {
                                var messages = [];
                                if (xhr.status === 200 && data) {
-                                       if (!data.isFairUseOfFreePushService) {
-                                               messages.push({
-                                                       msg: t('core', 'This is the unsupported community build of Nextcloud. Given the size of this instance, performance, reliability and scalability cannot be guaranteed. Push notifications are limited to avoid overloading our free service. Learn more about the benefits of Nextcloud Enterprise at {linkstart}https://nextcloud.com/enterprise{linkend}.')
-                                                               .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="https://nextcloud.com/enterprise">')
-                                                               .replace('{linkend}', '</a>'),
-                                                       type: OC.SetupChecks.MESSAGE_TYPE_ERROR
-                                               });
-                                       }
-
                                        if (window.location.protocol === 'https:' && data.reverseProxyGeneratedURL.split('/')[0] !== 'https:') {
                                                messages.push({
                                                        msg: t('core', 'You are accessing your instance over a secure connection, however your instance is generating insecure URLs. This most likely means that you are behind a reverse proxy and the overwrite config variables are not set correctly. Please read {linkstart}the documentation page about this ↗{linkend}.')
index b2e1baa618b7ab9c2c698916bb89df61e2ea3e98..9ac31ce8acb9a2ad6c6cc46395f31b45dd3fb789 100644 (file)
@@ -223,7 +223,6 @@ describe('OC.SetupChecks tests', function() {
                                        'Content-Type': 'application/json'
                                },
                                JSON.stringify({
-                                       isFairUseOfFreePushService: true,
                                        reverseProxyGeneratedURL: 'https://server',
                                        generic: {
                                                network: {
@@ -257,7 +256,6 @@ describe('OC.SetupChecks tests', function() {
                                        'Content-Type': 'application/json'
                                },
                                JSON.stringify({
-                                       isFairUseOfFreePushService: true,
                                        reverseProxyGeneratedURL: 'https://server',
                                        generic: {
                                                network: {
@@ -291,7 +289,6 @@ describe('OC.SetupChecks tests', function() {
                                        'Content-Type': 'application/json',
                                },
                                JSON.stringify({
-                                       isFairUseOfFreePushService: true,
                                        reverseProxyGeneratedURL: 'https://server',
                                        generic: {
                                                network: {
@@ -325,7 +322,6 @@ describe('OC.SetupChecks tests', function() {
                                        'Content-Type': 'application/json',
                                },
                                JSON.stringify({
-                                       isFairUseOfFreePushService: true,
                                        reverseProxyDocs: 'https://docs.nextcloud.com/foo/bar.html',
                                        reverseProxyGeneratedURL: 'https://server',
                                        generic: {
@@ -390,7 +386,6 @@ describe('OC.SetupChecks tests', function() {
                                        'Content-Type': 'application/json',
                                },
                                JSON.stringify({
-                                       isFairUseOfFreePushService: true,
                                        reverseProxyGeneratedURL: 'https://server',
                                        generic: {
                                                network: {
@@ -433,7 +428,6 @@ describe('OC.SetupChecks tests', function() {
                                        'Content-Type': 'application/json',
                                },
                                JSON.stringify({
-                                       isFairUseOfFreePushService: true,
                                        reverseProxyDocs: 'https://docs.nextcloud.com/foo/bar.html',
                                        reverseProxyGeneratedURL: 'http://server',
                                        generic: {
@@ -466,7 +460,6 @@ describe('OC.SetupChecks tests', function() {
                                        'Content-Type': 'application/json',
                                },
                                JSON.stringify({
-                                       isFairUseOfFreePushService: true,
                                        reverseProxyDocs: 'https://docs.nextcloud.com/foo/bar.html',
                                        reverseProxyGeneratedURL: 'http://server',
                                        generic: {
@@ -496,7 +489,6 @@ describe('OC.SetupChecks tests', function() {
                                        'Content-Type': 'application/json',
                                },
                                JSON.stringify({
-                                       isFairUseOfFreePushService: true,
                                        reverseProxyGeneratedURL: 'https://server',
                                        generic: {
                                                network: {