Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Temporarily disable the DAV plugin until clients work" #1018

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use OCA\Registration\Events\ShowFormEvent;
use OCA\Registration\Events\ValidateFormEvent;
use OCA\TermsOfService\Checker;
use OCA\TermsOfService\Dav\CheckPlugin;
use OCA\TermsOfService\Filesystem\StorageWrapper;
use OCA\TermsOfService\Listener\RegistrationIntegration;
use OCA\TermsOfService\Listener\UserDeletedListener;
Expand All @@ -28,6 +29,7 @@
use OCP\IUser;
use OCP\IUserSession;
use OCP\Notification\IManager;
use OCP\SabrePluginEvent;
use OCP\User\Events\UserDeletedEvent;
use OCP\User\Events\UserFirstTimeLoggedInEvent;
use OCP\Util;
Expand Down Expand Up @@ -56,19 +58,18 @@ public function register(IRegistrationContext $context): void {
public function boot(IBootContext $context): void {
Util::connectHook('OC_Filesystem', 'preSetup', $this, 'addStorageWrapper');

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

if ($eventServer !== null) {
// We have to register the CheckPlugin here and not info.xml,
// because info.xml plugins are loaded, after the
// beforeMethod:* hook has already been emitted.
$plugin = $context->getAppContainer()->get(CheckPlugin::class);
$eventServer->addPlugin($plugin);
}
});

$context->injectFn([$this, 'registerNotifier']);
$context->injectFn([$this, 'createNotificationOnFirstLogin']);
Expand Down
9 changes: 7 additions & 2 deletions lib/Checker.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use OCP\IConfig;
use OCP\IRequest;
use OCP\ISession;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserSession;
use OCP\IL10N;
Expand All @@ -38,6 +39,8 @@ class Checker {
private $logger;
/** @var array */
private $termsCache = [];
/** @var IURLGenerator */
private $url;

public function __construct(
IRequest $request,
Expand All @@ -48,7 +51,8 @@ public function __construct(
CountryDetector $countryDetector,
IConfig $config,
IL10N $l10n,
LoggerInterface $logger
LoggerInterface $logger,
IURLGenerator $url
) {
$this->request = $request;
$this->userSession = $userSession;
Expand All @@ -59,10 +63,11 @@ public function __construct(
$this->config = $config;
$this->l10n = $l10n;
$this->logger = $logger;
$this->url = $url;
}

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

/**
Expand Down
7 changes: 4 additions & 3 deletions lib/Dav/CheckPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@

use Sabre\DAV\Server;
use Sabre\DAV\ServerPlugin;
use Sabre\DAV\Exception\Forbidden;
use Sabre\HTTP\RequestInterface;
use Sabre\HTTP\ResponseInterface;

use OCA\TermsOfService\AppInfo\Application;
use OCA\TermsOfService\Checker;
use OCA\TermsOfService\TermsNotSignedException;


class CheckPlugin extends ServerPlugin {
/** @var Server */
Expand Down Expand Up @@ -51,9 +52,9 @@ public function initialize(Server $server) {
*/
public function checkToS(RequestInterface $request, ResponseInterface $response) {
// we instantiate the checker here to make sure sabre auth backend was triggered
$checker = \OC::$server->get(Checker::class);
$checker = \OCP\Server::get(Checker::class);
if (!$checker->currentUserHasSigned()) {
throw new Forbidden($checker->getForbiddenMessage());
throw new TermsNotSignedException($checker->getForbiddenMessage());
}
return true;
}
Expand Down
15 changes: 15 additions & 0 deletions lib/TermsNotSignedException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\TermsOfService;

use Sabre\DAV\Exception\Forbidden;

class TermsNotSignedException extends Forbidden {
}
1 change: 1 addition & 0 deletions vendor-bin/psalm/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
},
"require-dev": {
"nextcloud/ocp": "dev-stable28",
"sabre/dav": "^4.1",
"vimeo/psalm": "^5.6"
}
}
Loading
Loading