From 67541f21f6e4ee304d20cbf6510528e16d1e4ed6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Thu, 18 Jan 2024 15:53:03 +0100 Subject: [PATCH 1/2] Migrate fair use of free push service check to new SetupCheck API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- .../composer/composer/autoload_classmap.php | 1 + .../composer/composer/autoload_static.php | 1 + apps/settings/lib/AppInfo/Application.php | 4 + .../lib/Controller/CheckSetupController.php | 19 ----- .../SetupChecks/FairUseOfFreePushService.php | 79 +++++++++++++++++++ .../Controller/CheckSetupControllerTest.php | 6 -- core/js/setupchecks.js | 9 --- core/js/tests/specs/setupchecksSpec.js | 8 -- 8 files changed, 85 insertions(+), 42 deletions(-) create mode 100644 apps/settings/lib/SetupChecks/FairUseOfFreePushService.php diff --git a/apps/settings/composer/composer/autoload_classmap.php b/apps/settings/composer/composer/autoload_classmap.php index 6e641fab4c64f..866c27f0f25a8 100644 --- a/apps/settings/composer/composer/autoload_classmap.php +++ b/apps/settings/composer/composer/autoload_classmap.php @@ -88,6 +88,7 @@ '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 9b775f4358b70..99dd68250c126 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 0cb8d6771e844..6c6b430fdb3cd 100644 --- a/apps/settings/lib/AppInfo/Application.php +++ b/apps/settings/lib/AppInfo/Application.php @@ -60,6 +60,7 @@ 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 @@ public function register(IRegistrationContext $context): void { $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 323c673b0d094..8008351838556 100644 --- a/apps/settings/lib/Controller/CheckSetupController.php +++ b/apps/settings/lib/Controller/CheckSetupController.php @@ -56,7 +56,6 @@ 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 @@ public function __construct($AppName, IL10N $l10n, Checker $checker, LoggerInterface $logger, - IManager $manager, ISetupCheckManager $setupCheckManager, ) { parent::__construct($AppName, $request); @@ -92,7 +88,6 @@ public function __construct($AppName, $this->l10n = $l10n; $this->checker = $checker; $this->logger = $logger; - $this->manager = $manager; $this->setupCheckManager = $setupCheckManager; } @@ -105,19 +100,6 @@ public function setupCheckManager(): DataResponse { 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 @@ public function getFailedIntegrityCheckFiles(): DataDisplayResponse { 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 0000000000000..431d1be4d6aa8 --- /dev/null +++ b/apps/settings/lib/SetupChecks/FairUseOfFreePushService.php @@ -0,0 +1,79 @@ + + * + * @author Côme Chilliet + * + * @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 . + * + */ +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 c83273b467d8d..924a76fa4f55a 100644 --- a/apps/settings/tests/Controller/CheckSetupControllerTest.php +++ b/apps/settings/tests/Controller/CheckSetupControllerTest.php @@ -44,7 +44,6 @@ 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 @@ protected function setUp(): void { $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 @@ protected function setUp(): void { $this->l10n, $this->checker, $this->logger, - $this->notificationManager, $this->setupCheckManager, ]) ->setMethods([ @@ -170,7 +165,6 @@ public function testCheck() { [ 'reverseProxyDocs' => 'reverse-proxy-doc-link', 'reverseProxyGeneratedURL' => 'https://server/index.php', - 'isFairUseOfFreePushService' => false, 'generic' => [], ] ); diff --git a/core/js/setupchecks.js b/core/js/setupchecks.js index 7864169dd2b0a..7400d02d30d38 100644 --- a/core/js/setupchecks.js +++ b/core/js/setupchecks.js @@ -180,15 +180,6 @@ 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}', '') - .replace('{linkend}', ''), - 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}.') diff --git a/core/js/tests/specs/setupchecksSpec.js b/core/js/tests/specs/setupchecksSpec.js index b2e1baa618b7a..9ac31ce8acb9a 100644 --- a/core/js/tests/specs/setupchecksSpec.js +++ b/core/js/tests/specs/setupchecksSpec.js @@ -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: { From 3be505f9c25926ea75421e91b3609f60b8617e95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Thu, 25 Jan 2024 15:23:54 +0100 Subject: [PATCH 2/2] Rename to "Push service" and enable on all instances to avoid trouble MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- .../composer/composer/autoload_classmap.php | 2 +- .../composer/composer/autoload_static.php | 2 +- apps/settings/lib/AppInfo/Application.php | 6 ++---- ...rUseOfFreePushService.php => PushService.php} | 16 ++++++++++++---- 4 files changed, 16 insertions(+), 10 deletions(-) rename apps/settings/lib/SetupChecks/{FairUseOfFreePushService.php => PushService.php} (80%) diff --git a/apps/settings/composer/composer/autoload_classmap.php b/apps/settings/composer/composer/autoload_classmap.php index 866c27f0f25a8..0d8e177c1fde2 100644 --- a/apps/settings/composer/composer/autoload_classmap.php +++ b/apps/settings/composer/composer/autoload_classmap.php @@ -88,7 +88,6 @@ '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', @@ -107,6 +106,7 @@ 'OCA\\Settings\\SetupChecks\\PhpOpcacheSetup' => $baseDir . '/../lib/SetupChecks/PhpOpcacheSetup.php', 'OCA\\Settings\\SetupChecks\\PhpOutdated' => $baseDir . '/../lib/SetupChecks/PhpOutdated.php', 'OCA\\Settings\\SetupChecks\\PhpOutputBuffering' => $baseDir . '/../lib/SetupChecks/PhpOutputBuffering.php', + 'OCA\\Settings\\SetupChecks\\PushService' => $baseDir . '/../lib/SetupChecks/PushService.php', 'OCA\\Settings\\SetupChecks\\RandomnessSecure' => $baseDir . '/../lib/SetupChecks/RandomnessSecure.php', 'OCA\\Settings\\SetupChecks\\ReadOnlyConfig' => $baseDir . '/../lib/SetupChecks/ReadOnlyConfig.php', 'OCA\\Settings\\SetupChecks\\SupportedDatabase' => $baseDir . '/../lib/SetupChecks/SupportedDatabase.php', diff --git a/apps/settings/composer/composer/autoload_static.php b/apps/settings/composer/composer/autoload_static.php index 99dd68250c126..1b95d35a9063f 100644 --- a/apps/settings/composer/composer/autoload_static.php +++ b/apps/settings/composer/composer/autoload_static.php @@ -103,7 +103,6 @@ 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', @@ -122,6 +121,7 @@ class ComposerStaticInitSettings 'OCA\\Settings\\SetupChecks\\PhpOpcacheSetup' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpOpcacheSetup.php', 'OCA\\Settings\\SetupChecks\\PhpOutdated' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpOutdated.php', 'OCA\\Settings\\SetupChecks\\PhpOutputBuffering' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpOutputBuffering.php', + 'OCA\\Settings\\SetupChecks\\PushService' => __DIR__ . '/..' . '/../lib/SetupChecks/PushService.php', 'OCA\\Settings\\SetupChecks\\RandomnessSecure' => __DIR__ . '/..' . '/../lib/SetupChecks/RandomnessSecure.php', 'OCA\\Settings\\SetupChecks\\ReadOnlyConfig' => __DIR__ . '/..' . '/../lib/SetupChecks/ReadOnlyConfig.php', 'OCA\\Settings\\SetupChecks\\SupportedDatabase' => __DIR__ . '/..' . '/../lib/SetupChecks/SupportedDatabase.php', diff --git a/apps/settings/lib/AppInfo/Application.php b/apps/settings/lib/AppInfo/Application.php index 6c6b430fdb3cd..35e5009f1e872 100644 --- a/apps/settings/lib/AppInfo/Application.php +++ b/apps/settings/lib/AppInfo/Application.php @@ -60,7 +60,6 @@ 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; @@ -79,6 +78,7 @@ use OCA\Settings\SetupChecks\PhpOpcacheSetup; use OCA\Settings\SetupChecks\PhpOutdated; use OCA\Settings\SetupChecks\PhpOutputBuffering; +use OCA\Settings\SetupChecks\PushService; use OCA\Settings\SetupChecks\RandomnessSecure; use OCA\Settings\SetupChecks\ReadOnlyConfig; use OCA\Settings\SetupChecks\SupportedDatabase; @@ -210,9 +210,7 @@ public function register(IRegistrationContext $context): void { $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->registerSetupCheck(PushService::class); $context->registerUserMigrator(AccountMigrator::class); } diff --git a/apps/settings/lib/SetupChecks/FairUseOfFreePushService.php b/apps/settings/lib/SetupChecks/PushService.php similarity index 80% rename from apps/settings/lib/SetupChecks/FairUseOfFreePushService.php rename to apps/settings/lib/SetupChecks/PushService.php index 431d1be4d6aa8..3f9f99380e880 100644 --- a/apps/settings/lib/SetupChecks/FairUseOfFreePushService.php +++ b/apps/settings/lib/SetupChecks/PushService.php @@ -25,22 +25,26 @@ */ namespace OCA\Settings\SetupChecks; +use OCP\AppFramework\Utility\ITimeFactory; use OCP\IConfig; use OCP\IL10N; use OCP\Notification\IManager; use OCP\SetupCheck\ISetupCheck; use OCP\SetupCheck\SetupResult; +use OCP\Support\Subscription\IRegistry; -class FairUseOfFreePushService implements ISetupCheck { +class PushService implements ISetupCheck { public function __construct( private IL10N $l10n, private IConfig $config, private IManager $notificationsManager, + private IRegistry $subscriptionRegistry, + private ITimeFactory $timeFactory, ) { } public function getName(): string { - return $this->l10n->t('Free push service'); + return $this->l10n->t('Push service'); } public function getCategory(): string { @@ -52,7 +56,7 @@ public function getCategory(): string { */ private function isFairUseOfFreePushService(): bool { $rateLimitReached = (int) $this->config->getAppValue('notifications', 'rate_limit_reached', '0'); - if ($rateLimitReached >= (time() - 7 * 24 * 3600)) { + if ($rateLimitReached >= ($this->timeFactory->now()->getTimestamp() - 7 * 24 * 3600)) { // Notifications app is showing a message already return true; } @@ -60,8 +64,12 @@ private function isFairUseOfFreePushService(): bool { } public function run(): SetupResult { + if ($this->subscriptionRegistry->delegateHasValidSubscription()) { + return SetupResult::success($this->l10n->t('Valid enterprise license')); + } + if ($this->isFairUseOfFreePushService()) { - return SetupResult::success(); + return SetupResult::success($this->l10n->t('Free push service')); } return SetupResult::error(