mirror of
https://github.com/nextcloud/server.git
synced 2026-02-18 18:28:50 -05:00
Migrate fair use of free push service check to new SetupCheck API
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
parent
7c79521cbe
commit
67541f21f6
8 changed files with 85 additions and 42 deletions
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
|
|
|
|||
79
apps/settings/lib/SetupChecks/FairUseOfFreePushService.php
Normal file
79
apps/settings/lib/SetupChecks/FairUseOfFreePushService.php
Normal file
|
|
@ -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',
|
||||
],
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -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' => [],
|
||||
]
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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}', '<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}.')
|
||||
|
|
|
|||
|
|
@ -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: {
|
||||
|
|
|
|||
Loading…
Reference in a new issue