Skip to content

Commit 7bd60d2

Browse files
authored
Merge pull request #1041 from nextcloud/backport/1018/stable27
[stable27] Revert "Temporarily disable the DAV plugin until clients work"
2 parents 2ebb21a + c60b0da commit 7bd60d2

File tree

4 files changed

+39
-18
lines changed

4 files changed

+39
-18
lines changed

lib/AppInfo/Application.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use OCA\Registration\Events\ShowFormEvent;
2929
use OCA\Registration\Events\ValidateFormEvent;
3030
use OCA\TermsOfService\Checker;
31+
use OCA\TermsOfService\Dav\CheckPlugin;
3132
use OCA\TermsOfService\Filesystem\StorageWrapper;
3233
use OCA\TermsOfService\Listener\RegistrationIntegration;
3334
use OCA\TermsOfService\Listener\UserDeletedListener;
@@ -74,19 +75,18 @@ public function register(IRegistrationContext $context): void {
7475
public function boot(IBootContext $context): void {
7576
Util::connectHook('OC_Filesystem', 'preSetup', $this, 'addStorageWrapper');
7677

77-
// FIXME currently disabled until we made sure all clients (Talk and files on Android and iOS, as well as desktop) handle this gracefully
78-
// $eventDispatcher = $context->getServerContainer()->get(IEventDispatcher::class);
79-
// $eventDispatcher->addListener('OCA\DAV\Connector\Sabre::addPlugin', function (SabrePluginEvent $event) use ($context) {
80-
// $eventServer = $event->getServer();
81-
//
82-
// if ($eventServer !== null) {
83-
// // We have to register the CheckPlugin here and not info.xml,
84-
// // because info.xml plugins are loaded, after the
85-
// // beforeMethod:* hook has already been emitted.
86-
// $plugin = $context->getAppContainer()->get(CheckPlugin::class);
87-
// $eventServer->addPlugin($plugin);
88-
// }
89-
// });
78+
$eventDispatcher = $context->getServerContainer()->get(IEventDispatcher::class);
79+
$eventDispatcher->addListener('OCA\DAV\Connector\Sabre::addPlugin', function (SabrePluginEvent $event) use ($context) {
80+
$eventServer = $event->getServer();
81+
82+
if ($eventServer !== null) {
83+
// We have to register the CheckPlugin here and not info.xml,
84+
// because info.xml plugins are loaded, after the
85+
// beforeMethod:* hook has already been emitted.
86+
$plugin = $context->getAppContainer()->get(CheckPlugin::class);
87+
$eventServer->addPlugin($plugin);
88+
}
89+
});
9090

9191
$context->injectFn([$this, 'registerNotifier']);
9292
$context->injectFn([$this, 'createNotificationOnFirstLogin']);

lib/Checker.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use OCP\IConfig;
2828
use OCP\IRequest;
2929
use OCP\ISession;
30+
use OCP\IURLGenerator;
3031
use OCP\IUser;
3132
use OCP\IUserManager;
3233
use OCP\IL10N;
@@ -55,6 +56,8 @@ class Checker {
5556
private $logger;
5657
/** @var array */
5758
private $termsCache = [];
59+
/** @var IURLGenerator */
60+
private $url;
5861

5962
public function __construct(
6063
?string $userId,
@@ -66,7 +69,8 @@ public function __construct(
6669
CountryDetector $countryDetector,
6770
IConfig $config,
6871
IL10N $l10n,
69-
LoggerInterface $logger
72+
LoggerInterface $logger,
73+
IURLGenerator $url
7074
) {
7175
$this->userId = $userId;
7276
$this->request = $request;
@@ -78,10 +82,11 @@ public function __construct(
7882
$this->config = $config;
7983
$this->l10n = $l10n;
8084
$this->logger = $logger;
85+
$this->url = $url;
8186
}
8287

8388
public function getForbiddenMessage(): string {
84-
return $this->l10n->t('Terms of service are not signed');
89+
return $this->url->getBaseUrl();
8590
}
8691

8792
/**

lib/Dav/CheckPlugin.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@
2828

2929
use Sabre\DAV\Server;
3030
use Sabre\DAV\ServerPlugin;
31-
use Sabre\DAV\Exception\Forbidden;
3231
use Sabre\HTTP\RequestInterface;
3332
use Sabre\HTTP\ResponseInterface;
3433

3534
use OCA\TermsOfService\AppInfo\Application;
3635
use OCA\TermsOfService\Checker;
36+
use OCA\TermsOfService\TermsNotSignedException;
37+
3738

3839
class CheckPlugin extends ServerPlugin {
3940
/** @var Server */
@@ -68,9 +69,9 @@ public function initialize(Server $server) {
6869
*/
6970
public function checkToS(RequestInterface $request, ResponseInterface $response) {
7071
// we instantiate the checker here to make sure sabre auth backend was triggered
71-
$checker = \OC::$server->get(Checker::class);
72+
$checker = \OCP\Server::get(Checker::class);
7273
if (!$checker->currentUserHasSigned()) {
73-
throw new Forbidden($checker->getForbiddenMessage());
74+
throw new TermsNotSignedException($checker->getForbiddenMessage());
7475
}
7576
return true;
7677
}

lib/TermsNotSignedException.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCA\TermsOfService;
11+
12+
use Sabre\DAV\Exception\Forbidden;
13+
14+
class TermsNotSignedException extends Forbidden {
15+
}

0 commit comments

Comments
 (0)