aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorCôme Chilliet <come.chilliet@nextcloud.com>2024-01-18 15:53:03 +0100
committerCôme Chilliet <come.chilliet@nextcloud.com>2024-03-18 11:11:06 +0100
commit44c0b7d9b4fefa96cab08d506556a71440680e42 (patch)
tree3aa15e41e04f5c1e40354bc63d9462d80087ed0d /apps
parentb92024efa09eb362a9626e1d4a57171948545713 (diff)
downloadnextcloud-server-44c0b7d9b4fefa96cab08d506556a71440680e42.tar.gz
nextcloud-server-44c0b7d9b4fefa96cab08d506556a71440680e42.zip
Migrate fair use of free push service check to new SetupCheck API
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'apps')
-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.php4
-rw-r--r--apps/settings/lib/Controller/CheckSetupController.php19
-rw-r--r--apps/settings/lib/SetupChecks/FairUseOfFreePushService.php79
-rw-r--r--apps/settings/tests/Controller/CheckSetupControllerTest.php6
6 files changed, 85 insertions, 25 deletions
diff --git a/apps/settings/composer/composer/autoload_classmap.php b/apps/settings/composer/composer/autoload_classmap.php
index 6e641fab4c6..866c27f0f25 100644
--- a/apps/settings/composer/composer/autoload_classmap.php
+++ b/apps/settings/composer/composer/autoload_classmap.php
@@ -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',
diff --git a/apps/settings/composer/composer/autoload_static.php b/apps/settings/composer/composer/autoload_static.php
index 9b775f4358b..99dd68250c1 100644
--- a/apps/settings/composer/composer/autoload_static.php
+++ b/apps/settings/composer/composer/autoload_static.php
@@ -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',
diff --git a/apps/settings/lib/AppInfo/Application.php b/apps/settings/lib/AppInfo/Application.php
index 42905cf4cd9..11c7b9a0374 100644
--- a/apps/settings/lib/AppInfo/Application.php
+++ b/apps/settings/lib/AppInfo/Application.php
@@ -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;
@@ -205,6 +206,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);
}
diff --git a/apps/settings/lib/Controller/CheckSetupController.php b/apps/settings/lib/Controller/CheckSetupController.php
index 323c673b0d0..80083518385 100644
--- a/apps/settings/lib/Controller/CheckSetupController.php
+++ b/apps/settings/lib/Controller/CheckSetupController.php
@@ -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;
}
@@ -106,19 +101,6 @@ class CheckSetupController extends Controller {
}
/**
- * 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
* @AuthorizedAdminSetting(settings=OCA\Settings\Settings\Admin\Overview)
@@ -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
index 00000000000..431d1be4d6a
--- /dev/null
+++ b/apps/settings/lib/SetupChecks/FairUseOfFreePushService.php
@@ -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',
+ ],
+ ],
+ );
+ }
+}
diff --git a/apps/settings/tests/Controller/CheckSetupControllerTest.php b/apps/settings/tests/Controller/CheckSetupControllerTest.php
index c83273b467d..924a76fa4f5 100644
--- a/apps/settings/tests/Controller/CheckSetupControllerTest.php
+++ b/apps/settings/tests/Controller/CheckSetupControllerTest.php
@@ -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' => [],
]
);