Skip to content

Commit d4f9d9b

Browse files
committed
Migrate fair use of free push service check to new SetupCheck API
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
1 parent 200804e commit d4f9d9b

File tree

8 files changed

+85
-42
lines changed

8 files changed

+85
-42
lines changed

apps/settings/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
'OCA\\Settings\\SetupChecks\\DatabasePendingBigIntConversions' => $baseDir . '/../lib/SetupChecks/DatabasePendingBigIntConversions.php',
8989
'OCA\\Settings\\SetupChecks\\DefaultPhoneRegionSet' => $baseDir . '/../lib/SetupChecks/DefaultPhoneRegionSet.php',
9090
'OCA\\Settings\\SetupChecks\\EmailTestSuccessful' => $baseDir . '/../lib/SetupChecks/EmailTestSuccessful.php',
91+
'OCA\\Settings\\SetupChecks\\FairUseOfFreePushService' => $baseDir . '/../lib/SetupChecks/FairUseOfFreePushService.php',
9192
'OCA\\Settings\\SetupChecks\\FileLocking' => $baseDir . '/../lib/SetupChecks/FileLocking.php',
9293
'OCA\\Settings\\SetupChecks\\ForwardedForHeaders' => $baseDir . '/../lib/SetupChecks/ForwardedForHeaders.php',
9394
'OCA\\Settings\\SetupChecks\\InternetConnectivity' => $baseDir . '/../lib/SetupChecks/InternetConnectivity.php',

apps/settings/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ class ComposerStaticInitSettings
103103
'OCA\\Settings\\SetupChecks\\DatabasePendingBigIntConversions' => __DIR__ . '/..' . '/../lib/SetupChecks/DatabasePendingBigIntConversions.php',
104104
'OCA\\Settings\\SetupChecks\\DefaultPhoneRegionSet' => __DIR__ . '/..' . '/../lib/SetupChecks/DefaultPhoneRegionSet.php',
105105
'OCA\\Settings\\SetupChecks\\EmailTestSuccessful' => __DIR__ . '/..' . '/../lib/SetupChecks/EmailTestSuccessful.php',
106+
'OCA\\Settings\\SetupChecks\\FairUseOfFreePushService' => __DIR__ . '/..' . '/../lib/SetupChecks/FairUseOfFreePushService.php',
106107
'OCA\\Settings\\SetupChecks\\FileLocking' => __DIR__ . '/..' . '/../lib/SetupChecks/FileLocking.php',
107108
'OCA\\Settings\\SetupChecks\\ForwardedForHeaders' => __DIR__ . '/..' . '/../lib/SetupChecks/ForwardedForHeaders.php',
108109
'OCA\\Settings\\SetupChecks\\InternetConnectivity' => __DIR__ . '/..' . '/../lib/SetupChecks/InternetConnectivity.php',

apps/settings/lib/AppInfo/Application.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
use OCA\Settings\SetupChecks\DatabasePendingBigIntConversions;
6161
use OCA\Settings\SetupChecks\DefaultPhoneRegionSet;
6262
use OCA\Settings\SetupChecks\EmailTestSuccessful;
63+
use OCA\Settings\SetupChecks\FairUseOfFreePushService;
6364
use OCA\Settings\SetupChecks\FileLocking;
6465
use OCA\Settings\SetupChecks\ForwardedForHeaders;
6566
use OCA\Settings\SetupChecks\InternetConnectivity;
@@ -207,6 +208,9 @@ public function register(IRegistrationContext $context): void {
207208
$context->registerSetupCheck(SystemIs64bit::class);
208209
$context->registerSetupCheck(TempSpaceAvailable::class);
209210
$context->registerSetupCheck(TransactionIsolation::class);
211+
if (!\OCP\Server::get(\OCP\Support\Subscription\IRegistry::class)->delegateHasValidSubscription()) {
212+
$context->registerSetupCheck(FairUseOfFreePushService::class);
213+
}
210214

211215
$context->registerUserMigrator(AccountMigrator::class);
212216
}

apps/settings/lib/Controller/CheckSetupController.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
use OCP\IL10N;
5757
use OCP\IRequest;
5858
use OCP\IURLGenerator;
59-
use OCP\Notification\IManager;
6059
use OCP\SetupCheck\ISetupCheckManager;
6160
use Psr\Log\LoggerInterface;
6261

@@ -72,8 +71,6 @@ class CheckSetupController extends Controller {
7271
private $checker;
7372
/** @var LoggerInterface */
7473
private $logger;
75-
/** @var IManager */
76-
private $manager;
7774
private ISetupCheckManager $setupCheckManager;
7875

7976
public function __construct($AppName,
@@ -83,7 +80,6 @@ public function __construct($AppName,
8380
IL10N $l10n,
8481
Checker $checker,
8582
LoggerInterface $logger,
86-
IManager $manager,
8783
ISetupCheckManager $setupCheckManager,
8884
) {
8985
parent::__construct($AppName, $request);
@@ -92,7 +88,6 @@ public function __construct($AppName,
9288
$this->l10n = $l10n;
9389
$this->checker = $checker;
9490
$this->logger = $logger;
95-
$this->manager = $manager;
9691
$this->setupCheckManager = $setupCheckManager;
9792
}
9893

@@ -105,19 +100,6 @@ public function setupCheckManager(): DataResponse {
105100
return new DataResponse($this->setupCheckManager->runAll());
106101
}
107102

108-
/**
109-
* Check if is fair use of free push service
110-
* @return bool
111-
*/
112-
private function isFairUseOfFreePushService(): bool {
113-
$rateLimitReached = (int) $this->config->getAppValue('notifications', 'rate_limit_reached', '0');
114-
if ($rateLimitReached >= (time() - 7 * 24 * 3600)) {
115-
// Notifications app is showing a message already
116-
return true;
117-
}
118-
return $this->manager->isFairUseOfFreePushService();
119-
}
120-
121103
/**
122104
* @NoCSRFRequired
123105
* @return RedirectResponse
@@ -194,7 +176,6 @@ public function getFailedIntegrityCheckFiles(): DataDisplayResponse {
194176
public function check() {
195177
return new DataResponse(
196178
[
197-
'isFairUseOfFreePushService' => $this->isFairUseOfFreePushService(),
198179
'reverseProxyDocs' => $this->urlGenerator->linkToDocs('admin-reverse-proxy'),
199180
'reverseProxyGeneratedURL' => $this->urlGenerator->getAbsoluteURL('index.php'),
200181
'generic' => $this->setupCheckManager->runAll(),
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright Copyright (c) 2023 Côme Chilliet <come.chilliet@nextcloud.com>
7+
*
8+
* @author Côme Chilliet <come.chilliet@nextcloud.com>
9+
*
10+
* @license GNU AGPL version 3 or any later version
11+
*
12+
* This program is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License as
14+
* published by the Free Software Foundation, either version 3 of the
15+
* License, or (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU Affero General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU Affero General Public License
23+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24+
*
25+
*/
26+
namespace OCA\Settings\SetupChecks;
27+
28+
use OCP\IConfig;
29+
use OCP\IL10N;
30+
use OCP\Notification\IManager;
31+
use OCP\SetupCheck\ISetupCheck;
32+
use OCP\SetupCheck\SetupResult;
33+
34+
class FairUseOfFreePushService implements ISetupCheck {
35+
public function __construct(
36+
private IL10N $l10n,
37+
private IConfig $config,
38+
private IManager $notificationsManager,
39+
) {
40+
}
41+
42+
public function getName(): string {
43+
return $this->l10n->t('Free push service');
44+
}
45+
46+
public function getCategory(): string {
47+
return 'system';
48+
}
49+
50+
/**
51+
* Check if is fair use of free push service
52+
*/
53+
private function isFairUseOfFreePushService(): bool {
54+
$rateLimitReached = (int) $this->config->getAppValue('notifications', 'rate_limit_reached', '0');
55+
if ($rateLimitReached >= (time() - 7 * 24 * 3600)) {
56+
// Notifications app is showing a message already
57+
return true;
58+
}
59+
return $this->notificationsManager->isFairUseOfFreePushService();
60+
}
61+
62+
public function run(): SetupResult {
63+
if ($this->isFairUseOfFreePushService()) {
64+
return SetupResult::success();
65+
}
66+
67+
return SetupResult::error(
68+
$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}.'),
69+
descriptionParameters:[
70+
'link' => [
71+
'type' => 'highlight',
72+
'id' => 'link',
73+
'name' => 'https://nextcloud.com/enterprise',
74+
'link' => 'https://nextcloud.com/enterprise',
75+
],
76+
],
77+
);
78+
}
79+
}

apps/settings/tests/Controller/CheckSetupControllerTest.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
use OCP\IL10N;
4545
use OCP\IRequest;
4646
use OCP\IURLGenerator;
47-
use OCP\Notification\IManager;
4847
use OCP\SetupCheck\ISetupCheckManager;
4948
use PHPUnit\Framework\MockObject\MockObject;
5049
use Psr\Log\LoggerInterface;
@@ -71,8 +70,6 @@ class CheckSetupControllerTest extends TestCase {
7170
private $logger;
7271
/** @var Checker|\PHPUnit\Framework\MockObject\MockObject */
7372
private $checker;
74-
/** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
75-
private $notificationManager;
7673
/** @var ISetupCheckManager|MockObject */
7774
private $setupCheckManager;
7875

@@ -102,7 +99,6 @@ protected function setUp(): void {
10299
$this->checker = $this->getMockBuilder('\OC\IntegrityCheck\Checker')
103100
->disableOriginalConstructor()->getMock();
104101
$this->logger = $this->getMockBuilder(LoggerInterface::class)->getMock();
105-
$this->notificationManager = $this->getMockBuilder(IManager::class)->getMock();
106102
$this->setupCheckManager = $this->createMock(ISetupCheckManager::class);
107103
$this->checkSetupController = $this->getMockBuilder(CheckSetupController::class)
108104
->setConstructorArgs([
@@ -113,7 +109,6 @@ protected function setUp(): void {
113109
$this->l10n,
114110
$this->checker,
115111
$this->logger,
116-
$this->notificationManager,
117112
$this->setupCheckManager,
118113
])
119114
->setMethods([
@@ -199,7 +194,6 @@ public function testCheck() {
199194
[
200195
'reverseProxyDocs' => 'reverse-proxy-doc-link',
201196
'reverseProxyGeneratedURL' => 'https://server/index.php',
202-
'isFairUseOfFreePushService' => false,
203197
'generic' => [],
204198
]
205199
);

core/js/setupchecks.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -180,15 +180,6 @@
180180
var afterCall = function(data, statusText, xhr) {
181181
var messages = [];
182182
if (xhr.status === 200 && data) {
183-
if (!data.isFairUseOfFreePushService) {
184-
messages.push({
185-
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}.')
186-
.replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="https://nextcloud.com/enterprise">')
187-
.replace('{linkend}', '</a>'),
188-
type: OC.SetupChecks.MESSAGE_TYPE_ERROR
189-
});
190-
}
191-
192183
if (window.location.protocol === 'https:' && data.reverseProxyGeneratedURL.split('/')[0] !== 'https:') {
193184
messages.push({
194185
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}.')

core/js/tests/specs/setupchecksSpec.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,6 @@ describe('OC.SetupChecks tests', function() {
223223
'Content-Type': 'application/json'
224224
},
225225
JSON.stringify({
226-
isFairUseOfFreePushService: true,
227226
reverseProxyGeneratedURL: 'https://server',
228227
generic: {
229228
network: {
@@ -257,7 +256,6 @@ describe('OC.SetupChecks tests', function() {
257256
'Content-Type': 'application/json'
258257
},
259258
JSON.stringify({
260-
isFairUseOfFreePushService: true,
261259
reverseProxyGeneratedURL: 'https://server',
262260
generic: {
263261
network: {
@@ -291,7 +289,6 @@ describe('OC.SetupChecks tests', function() {
291289
'Content-Type': 'application/json',
292290
},
293291
JSON.stringify({
294-
isFairUseOfFreePushService: true,
295292
reverseProxyGeneratedURL: 'https://server',
296293
generic: {
297294
network: {
@@ -325,7 +322,6 @@ describe('OC.SetupChecks tests', function() {
325322
'Content-Type': 'application/json',
326323
},
327324
JSON.stringify({
328-
isFairUseOfFreePushService: true,
329325
reverseProxyDocs: 'https://docs.nextcloud.com/foo/bar.html',
330326
reverseProxyGeneratedURL: 'https://server',
331327
generic: {
@@ -390,7 +386,6 @@ describe('OC.SetupChecks tests', function() {
390386
'Content-Type': 'application/json',
391387
},
392388
JSON.stringify({
393-
isFairUseOfFreePushService: true,
394389
reverseProxyGeneratedURL: 'https://server',
395390
generic: {
396391
network: {
@@ -433,7 +428,6 @@ describe('OC.SetupChecks tests', function() {
433428
'Content-Type': 'application/json',
434429
},
435430
JSON.stringify({
436-
isFairUseOfFreePushService: true,
437431
reverseProxyDocs: 'https://docs.nextcloud.com/foo/bar.html',
438432
reverseProxyGeneratedURL: 'http://server',
439433
generic: {
@@ -466,7 +460,6 @@ describe('OC.SetupChecks tests', function() {
466460
'Content-Type': 'application/json',
467461
},
468462
JSON.stringify({
469-
isFairUseOfFreePushService: true,
470463
reverseProxyDocs: 'https://docs.nextcloud.com/foo/bar.html',
471464
reverseProxyGeneratedURL: 'http://server',
472465
generic: {
@@ -496,7 +489,6 @@ describe('OC.SetupChecks tests', function() {
496489
'Content-Type': 'application/json',
497490
},
498491
JSON.stringify({
499-
isFairUseOfFreePushService: true,
500492
reverseProxyGeneratedURL: 'https://server',
501493
generic: {
502494
network: {

0 commit comments

Comments
 (0)