Skip to content

Commit a06001e

Browse files
authored
Merge pull request #29363 from nextcloud/fair-use-push
2 parents 7e117da + 6f7ca34 commit a06001e

15 files changed

Lines changed: 285 additions & 52 deletions

File tree

apps/settings/lib/Controller/CheckSetupController.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
use OCP\ITempManager;
7979
use OCP\IURLGenerator;
8080
use OCP\Lock\ILockingProvider;
81+
use OCP\Notification\IManager;
8182
use OCP\Security\ISecureRandom;
8283
use Psr\Log\LoggerInterface;
8384
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@@ -114,6 +115,8 @@ class CheckSetupController extends Controller {
114115
private $connection;
115116
/** @var ITempManager */
116117
private $tempManager;
118+
/** @var IManager */
119+
private $manager;
117120

118121
public function __construct($AppName,
119122
IRequest $request,
@@ -131,7 +134,8 @@ public function __construct($AppName,
131134
ISecureRandom $secureRandom,
132135
IniGetWrapper $iniGetWrapper,
133136
IDBConnection $connection,
134-
ITempManager $tempManager) {
137+
ITempManager $tempManager,
138+
IManager $manager) {
135139
parent::__construct($AppName, $request);
136140
$this->config = $config;
137141
$this->clientService = $clientService;
@@ -148,6 +152,15 @@ public function __construct($AppName,
148152
$this->iniGetWrapper = $iniGetWrapper;
149153
$this->connection = $connection;
150154
$this->tempManager = $tempManager;
155+
$this->manager = $manager;
156+
}
157+
158+
/**
159+
* Check if is fair use of free push service
160+
* @return bool
161+
*/
162+
private function isFairUseOfFreePushService(): bool {
163+
return $this->manager->isFairUseOfFreePushService();
151164
}
152165

153166
/**
@@ -761,6 +774,7 @@ public function check() {
761774
'suggestedOverwriteCliURL' => $this->getSuggestedOverwriteCliURL(),
762775
'cronInfo' => $this->getLastCronInfo(),
763776
'cronErrors' => $this->getCronErrors(),
777+
'isFairUseOfFreePushService' => $this->isFairUseOfFreePushService(),
764778
'serverHasInternetConnectionProblems' => $this->hasInternetConnectivityProblems(),
765779
'isMemcacheConfigured' => $this->isMemcacheConfigured(),
766780
'memcacheDocs' => $this->urlGenerator->linkToDocs('admin-performance'),

apps/settings/lib/Settings/Personal/PersonalInfo.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
use OCP\IUserManager;
5353
use OCP\L10N\IFactory;
5454
use OC\Profile\ProfileManager;
55+
use OCP\Notification\IManager;
5556
use OCP\Settings\ISettings;
5657

5758
class PersonalInfo implements ISettings {
@@ -84,6 +85,9 @@ class PersonalInfo implements ISettings {
8485
/** @var IInitialState */
8586
private $initialStateService;
8687

88+
/** @var IManager */
89+
private $manager;
90+
8791
public function __construct(
8892
IConfig $config,
8993
IUserManager $userManager,
@@ -93,7 +97,8 @@ public function __construct(
9397
IAppManager $appManager,
9498
IFactory $l10nFactory,
9599
IL10N $l,
96-
IInitialState $initialStateService
100+
IInitialState $initialStateService,
101+
IManager $manager
97102
) {
98103
$this->config = $config;
99104
$this->userManager = $userManager;
@@ -104,6 +109,7 @@ public function __construct(
104109
$this->l10nFactory = $l10nFactory;
105110
$this->l = $l;
106111
$this->initialStateService = $initialStateService;
112+
$this->manager = $manager;
107113
}
108114

109115
public function getForm(): TemplateResponse {
@@ -160,6 +166,7 @@ public function getForm(): TemplateResponse {
160166
'twitterScope' => $account->getProperty(IAccountManager::PROPERTY_TWITTER)->getScope(),
161167
'twitterVerification' => $account->getProperty(IAccountManager::PROPERTY_TWITTER)->getVerified(),
162168
'groups' => $this->getGroups($user),
169+
'isFairUseOfFreePushService' => $this->isFairUseOfFreePushService()
163170
] + $messageParameters + $languageParameters + $localeParameters;
164171

165172
$personalInfoParameters = [
@@ -190,6 +197,14 @@ public function getForm(): TemplateResponse {
190197
return new TemplateResponse('settings', 'settings/personal/personal.info', $parameters, '');
191198
}
192199

200+
/**
201+
* Check if is fair use of free push service
202+
* @return boolean
203+
*/
204+
private function isFairUseOfFreePushService(): bool {
205+
return $this->manager->isFairUseOfFreePushService();
206+
}
207+
193208
/**
194209
* returns the primary biography in an
195210
* associative array

apps/settings/templates/settings/personal/personal.info.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@
3535
'vue-settings-personal-info',
3636
]);
3737
?>
38+
<?php if (!$_['isFairUseOfFreePushService']) : ?>
39+
<div class="section">
40+
<div class="warning">
41+
<?php p($l->t('This community release of Nextcloud is unsupported and instant notifications are unavailable.')); ?>
42+
</div>
43+
</div>
44+
<?php endif; ?>
3845

3946
<div id="personal-settings" data-federation-enabled="<?php p($_['federationEnabled'] ? 'true' : 'false') ?>"
4047
data-lookup-server-upload-enabled="<?php p($_['lookupServerUploadEnabled'] ? 'true' : 'false') ?>">

build/psalm-baseline.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4253,6 +4253,7 @@
42534253
</ParamNameMismatch>
42544254
</file>
42554255
<file src="lib/private/Notification/Manager.php">
4256+
<InvalidCatch occurrences="3"/>
42564257
<TypeDoesNotContainType occurrences="2">
42574258
<code>!($notification instanceof INotification)</code>
42584259
<code>!($notification instanceof INotification)</code>

core/Controller/LoginController.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,15 @@
4646
use OCP\Defaults;
4747
use OCP\IConfig;
4848
use OCP\IInitialStateService;
49+
use OCP\IL10N;
4950
use OCP\ILogger;
5051
use OCP\IRequest;
5152
use OCP\ISession;
5253
use OCP\IURLGenerator;
5354
use OCP\IUser;
5455
use OCP\IUserManager;
5556
use OCP\IUserSession;
57+
use OCP\Notification\IManager;
5658
use OCP\Util;
5759

5860
class LoginController extends Controller {
@@ -81,6 +83,10 @@ class LoginController extends Controller {
8183
private $initialStateService;
8284
/** @var WebAuthnManager */
8385
private $webAuthnManager;
86+
/** @var IManager */
87+
private $manager;
88+
/** @var IL10N */
89+
private $l10n;
8490

8591
public function __construct(?string $appName,
8692
IRequest $request,
@@ -94,7 +100,9 @@ public function __construct(?string $appName,
94100
Throttler $throttler,
95101
Chain $loginChain,
96102
IInitialStateService $initialStateService,
97-
WebAuthnManager $webAuthnManager) {
103+
WebAuthnManager $webAuthnManager,
104+
IManager $manager,
105+
IL10N $l10n) {
98106
parent::__construct($appName, $request);
99107
$this->userManager = $userManager;
100108
$this->config = $config;
@@ -107,6 +115,8 @@ public function __construct(?string $appName,
107115
$this->loginChain = $loginChain;
108116
$this->initialStateService = $initialStateService;
109117
$this->webAuthnManager = $webAuthnManager;
118+
$this->manager = $manager;
119+
$this->l10n = $l10n;
110120
}
111121

112122
/**
@@ -153,6 +163,12 @@ public function showLoginForm(string $user = null, string $redirect_url = null):
153163
}
154164

155165
$loginMessages = $this->session->get('loginMessages');
166+
if (!$this->manager->isFairUseOfFreePushService()) {
167+
if (!is_array($loginMessages)) {
168+
$loginMessages = [[], []];
169+
}
170+
$loginMessages[1][] = $this->l10n->t('This community release of Nextcloud is unsupported and instant notifications are unavailable.');
171+
}
156172
if (is_array($loginMessages)) {
157173
[$errors, $messages] = $loginMessages;
158174
$this->initialStateService->provideInitialState('core', 'loginMessages', $messages);

core/js/setupchecks.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,12 @@
254254
type: OC.SetupChecks.MESSAGE_TYPE_ERROR
255255
});
256256
}
257+
if (!data.isFairUseOfFreePushService) {
258+
messages.push({
259+
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 have been disabled to avoid overloading our free service. Learn more about the benefits of Nextcloud Enterprise at nextcloud.com/enterprise.'),
260+
type: OC.SetupChecks.MESSAGE_TYPE_ERROR
261+
});
262+
}
257263
if (data.serverHasInternetConnectionProblems) {
258264
messages.push({
259265
msg: t('core', 'This server has no working internet connection: Multiple endpoints could not be reached. This means that some of the features like mounting external storage, notifications about updates or installation of third-party apps will not work. Accessing files remotely and sending of notification emails might not work, either. Establish a connection from this server to the internet to enjoy all features.'),

core/js/tests/specs/setupchecksSpec.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ describe('OC.SetupChecks tests', function() {
230230
hasValidTransactionIsolationLevel: true,
231231
suggestedOverwriteCliURL: '',
232232
isRandomnessSecure: true,
233+
isFairUseOfFreePushService: true,
233234
serverHasInternetConnectionProblems: true,
234235
memcacheDocs: 'https://docs.nextcloud.com/server/go.php?to=admin-performance',
235236
forwardedForHeadersWorking: true,
@@ -287,6 +288,7 @@ describe('OC.SetupChecks tests', function() {
287288
hasValidTransactionIsolationLevel: true,
288289
suggestedOverwriteCliURL: '',
289290
isRandomnessSecure: true,
291+
isFairUseOfFreePushService: true,
290292
serverHasInternetConnectionProblems: true,
291293
memcacheDocs: 'https://docs.nextcloud.com/server/go.php?to=admin-performance',
292294
forwardedForHeadersWorking: true,
@@ -345,6 +347,7 @@ describe('OC.SetupChecks tests', function() {
345347
hasValidTransactionIsolationLevel: true,
346348
suggestedOverwriteCliURL: '',
347349
isRandomnessSecure: true,
350+
isFairUseOfFreePushService: true,
348351
serverHasInternetConnectionProblems: true,
349352
isMemcacheConfigured: true,
350353
forwardedForHeadersWorking: true,
@@ -401,6 +404,7 @@ describe('OC.SetupChecks tests', function() {
401404
suggestedOverwriteCliURL: '',
402405
isRandomnessSecure: false,
403406
securityDocs: 'https://docs.nextcloud.com/myDocs.html',
407+
isFairUseOfFreePushService: true,
404408
serverHasInternetConnectionProblems: false,
405409
isMemcacheConfigured: true,
406410
forwardedForHeadersWorking: true,
@@ -455,6 +459,7 @@ describe('OC.SetupChecks tests', function() {
455459
suggestedOverwriteCliURL: '',
456460
isRandomnessSecure: true,
457461
securityDocs: 'https://docs.nextcloud.com/myDocs.html',
462+
isFairUseOfFreePushService: true,
458463
serverHasInternetConnectionProblems: false,
459464
isMemcacheConfigured: true,
460465
forwardedForHeadersWorking: true,
@@ -509,6 +514,7 @@ describe('OC.SetupChecks tests', function() {
509514
suggestedOverwriteCliURL: '',
510515
isRandomnessSecure: true,
511516
securityDocs: 'https://docs.nextcloud.com/myDocs.html',
517+
isFairUseOfFreePushService: true,
512518
serverHasInternetConnectionProblems: false,
513519
isMemcacheConfigured: true,
514520
forwardedForHeadersWorking: true,
@@ -564,6 +570,7 @@ describe('OC.SetupChecks tests', function() {
564570
hasValidTransactionIsolationLevel: true,
565571
suggestedOverwriteCliURL: '',
566572
isRandomnessSecure: true,
573+
isFairUseOfFreePushService: true,
567574
serverHasInternetConnectionProblems: false,
568575
isMemcacheConfigured: true,
569576
forwardedForHeadersWorking: false,
@@ -618,6 +625,7 @@ describe('OC.SetupChecks tests', function() {
618625
hasValidTransactionIsolationLevel: true,
619626
suggestedOverwriteCliURL: '',
620627
isRandomnessSecure: true,
628+
isFairUseOfFreePushService: true,
621629
serverHasInternetConnectionProblems: false,
622630
isMemcacheConfigured: true,
623631
forwardedForHeadersWorking: true,
@@ -672,6 +680,7 @@ describe('OC.SetupChecks tests', function() {
672680
hasValidTransactionIsolationLevel: true,
673681
suggestedOverwriteCliURL: '',
674682
isRandomnessSecure: true,
683+
isFairUseOfFreePushService: true,
675684
serverHasInternetConnectionProblems: false,
676685
isMemcacheConfigured: true,
677686
forwardedForHeadersWorking: true,
@@ -747,6 +756,7 @@ describe('OC.SetupChecks tests', function() {
747756
suggestedOverwriteCliURL: '',
748757
isRandomnessSecure: true,
749758
securityDocs: 'https://docs.nextcloud.com/myDocs.html',
759+
isFairUseOfFreePushService: true,
750760
serverHasInternetConnectionProblems: false,
751761
isMemcacheConfigured: true,
752762
forwardedForHeadersWorking: true,
@@ -802,6 +812,7 @@ describe('OC.SetupChecks tests', function() {
802812
suggestedOverwriteCliURL: '',
803813
isRandomnessSecure: true,
804814
securityDocs: 'https://docs.nextcloud.com/myDocs.html',
815+
isFairUseOfFreePushService: true,
805816
serverHasInternetConnectionProblems: false,
806817
isMemcacheConfigured: true,
807818
forwardedForHeadersWorking: true,
@@ -857,6 +868,7 @@ describe('OC.SetupChecks tests', function() {
857868
suggestedOverwriteCliURL: '',
858869
isRandomnessSecure: true,
859870
securityDocs: 'https://docs.nextcloud.com/myDocs.html',
871+
isFairUseOfFreePushService: true,
860872
serverHasInternetConnectionProblems: false,
861873
isMemcacheConfigured: true,
862874
forwardedForHeadersWorking: true,
@@ -912,6 +924,7 @@ describe('OC.SetupChecks tests', function() {
912924
suggestedOverwriteCliURL: '',
913925
isRandomnessSecure: true,
914926
securityDocs: 'https://docs.nextcloud.com/myDocs.html',
927+
isFairUseOfFreePushService: true,
915928
serverHasInternetConnectionProblems: false,
916929
isMemcacheConfigured: true,
917930
forwardedForHeadersWorking: true,
@@ -967,6 +980,7 @@ describe('OC.SetupChecks tests', function() {
967980
suggestedOverwriteCliURL: '',
968981
isRandomnessSecure: true,
969982
securityDocs: 'https://docs.nextcloud.com/myDocs.html',
983+
isFairUseOfFreePushService: true,
970984
serverHasInternetConnectionProblems: false,
971985
isMemcacheConfigured: true,
972986
forwardedForHeadersWorking: true,
@@ -1025,6 +1039,7 @@ describe('OC.SetupChecks tests', function() {
10251039
suggestedOverwriteCliURL: '',
10261040
isRandomnessSecure: true,
10271041
securityDocs: 'https://docs.nextcloud.com/myDocs.html',
1042+
isFairUseOfFreePushService: true,
10281043
serverHasInternetConnectionProblems: false,
10291044
isMemcacheConfigured: true,
10301045
forwardedForHeadersWorking: true,
@@ -1080,6 +1095,7 @@ describe('OC.SetupChecks tests', function() {
10801095
suggestedOverwriteCliURL: '',
10811096
isRandomnessSecure: true,
10821097
securityDocs: 'https://docs.nextcloud.com/myDocs.html',
1098+
isFairUseOfFreePushService: true,
10831099
serverHasInternetConnectionProblems: false,
10841100
isMemcacheConfigured: true,
10851101
forwardedForHeadersWorking: true,
@@ -1132,6 +1148,7 @@ describe('OC.SetupChecks tests', function() {
11321148
suggestedOverwriteCliURL: '',
11331149
isRandomnessSecure: true,
11341150
securityDocs: 'https://docs.nextcloud.com/myDocs.html',
1151+
isFairUseOfFreePushService: true,
11351152
serverHasInternetConnectionProblems: false,
11361153
isMemcacheConfigured: true,
11371154
forwardedForHeadersWorking: true,
@@ -1186,6 +1203,7 @@ describe('OC.SetupChecks tests', function() {
11861203
suggestedOverwriteCliURL: '',
11871204
isRandomnessSecure: true,
11881205
securityDocs: 'https://docs.nextcloud.com/myDocs.html',
1206+
isFairUseOfFreePushService: true,
11891207
serverHasInternetConnectionProblems: false,
11901208
isMemcacheConfigured: true,
11911209
forwardedForHeadersWorking: true,
@@ -1240,6 +1258,7 @@ describe('OC.SetupChecks tests', function() {
12401258
suggestedOverwriteCliURL: '',
12411259
isRandomnessSecure: true,
12421260
securityDocs: 'https://docs.nextcloud.com/myDocs.html',
1261+
isFairUseOfFreePushService: true,
12431262
serverHasInternetConnectionProblems: false,
12441263
isMemcacheConfigured: true,
12451264
forwardedForHeadersWorking: true,

0 commit comments

Comments
 (0)