From 1593322397c02c84976657faac9d134d561565a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Thu, 21 Nov 2019 15:47:11 +0100 Subject: [PATCH] Load apps dav plugins on the old webdav route MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- apps/dav/appinfo/v1/publicwebdav.php | 3 ++- apps/dav/appinfo/v1/webdav.php | 3 ++- .../dav/lib/Connector/Sabre/ServerFactory.php | 23 +++++++++++++++++-- .../Sabre/RequestTest/RequestTestCase.php | 3 ++- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/apps/dav/appinfo/v1/publicwebdav.php b/apps/dav/appinfo/v1/publicwebdav.php index 37fcebe605..ff64a205ef 100644 --- a/apps/dav/appinfo/v1/publicwebdav.php +++ b/apps/dav/appinfo/v1/publicwebdav.php @@ -52,7 +52,8 @@ $serverFactory = new OCA\DAV\Connector\Sabre\ServerFactory( \OC::$server->getMountManager(), \OC::$server->getTagManager(), \OC::$server->getRequest(), - \OC::$server->getPreviewManager() + \OC::$server->getPreviewManager(), + \OC::$server->getEventDispatcher() ); $requestUri = \OC::$server->getRequest()->getRequestUri(); diff --git a/apps/dav/appinfo/v1/webdav.php b/apps/dav/appinfo/v1/webdav.php index d6dc9aa9b4..e2de6bd818 100644 --- a/apps/dav/appinfo/v1/webdav.php +++ b/apps/dav/appinfo/v1/webdav.php @@ -44,7 +44,8 @@ $serverFactory = new \OCA\DAV\Connector\Sabre\ServerFactory( \OC::$server->getMountManager(), \OC::$server->getTagManager(), \OC::$server->getRequest(), - \OC::$server->getPreviewManager() + \OC::$server->getPreviewManager(), + \OC::$server->getEventDispatcher() ); // Backends diff --git a/apps/dav/lib/Connector/Sabre/ServerFactory.php b/apps/dav/lib/Connector/Sabre/ServerFactory.php index 1821638189..f1745dbd91 100644 --- a/apps/dav/lib/Connector/Sabre/ServerFactory.php +++ b/apps/dav/lib/Connector/Sabre/ServerFactory.php @@ -30,6 +30,7 @@ namespace OCA\DAV\Connector\Sabre; use OC\Files\Node\Folder; +use OCA\DAV\AppInfo\PluginManager; use OCA\DAV\Files\BrowserErrorPagePlugin; use OCP\Files\Mount\IMountManager; use OCP\IConfig; @@ -39,7 +40,9 @@ use OCP\IPreview; use OCP\IRequest; use OCP\ITagManager; use OCP\IUserSession; +use OCP\SabrePluginEvent; use Sabre\DAV\Auth\Plugin; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; class ServerFactory { /** @var IConfig */ @@ -58,6 +61,8 @@ class ServerFactory { private $request; /** @var IPreview */ private $previewManager; + /** @var EventDispatcherInterface */ + private $eventDispatcher; /** * @param IConfig $config @@ -77,7 +82,8 @@ class ServerFactory { IMountManager $mountManager, ITagManager $tagManager, IRequest $request, - IPreview $previewManager + IPreview $previewManager, + EventDispatcherInterface $eventDispatcher ) { $this->config = $config; $this->logger = $logger; @@ -87,6 +93,7 @@ class ServerFactory { $this->tagManager = $tagManager; $this->request = $request; $this->previewManager = $previewManager; + $this->eventDispatcher = $eventDispatcher; } /** @@ -134,7 +141,7 @@ class ServerFactory { $server->on('beforeMethod', function () use ($server, $objectTree, $viewCallBack) { // ensure the skeleton is copied $userFolder = \OC::$server->getUserFolder(); - + /** @var \OC\Files\View $view */ $view = $viewCallBack($server); if ($userFolder instanceof Folder && $userFolder->getPath() === $view->getRoot()) { @@ -195,6 +202,18 @@ class ServerFactory { ); } $server->addPlugin(new \OCA\DAV\Connector\Sabre\CopyEtagHeaderPlugin()); + + // Load dav plugins from apps + $event = new SabrePluginEvent($server); + $this->eventDispatcher->dispatch($event); + $pluginManager = new PluginManager( + \OC::$server, + \OC::$server->getAppManager() + ); + foreach ($pluginManager->getAppPlugins() as $appPlugin) { + $server->addPlugin($appPlugin); + } + }, 30); // priority 30: after auth (10) and acl(20), before lock(50) and handling the request return $server; } diff --git a/apps/dav/tests/unit/Connector/Sabre/RequestTest/RequestTestCase.php b/apps/dav/tests/unit/Connector/Sabre/RequestTest/RequestTestCase.php index b7d88b2208..b921e0fea5 100644 --- a/apps/dav/tests/unit/Connector/Sabre/RequestTest/RequestTestCase.php +++ b/apps/dav/tests/unit/Connector/Sabre/RequestTest/RequestTestCase.php @@ -67,7 +67,8 @@ abstract class RequestTestCase extends TestCase { $this->getMockBuilder(IRequest::class) ->disableOriginalConstructor() ->getMock(), - \OC::$server->getPreviewManager() + \OC::$server->getPreviewManager(), + \OC::$server->getEventDispatcher() ); }