Completed
Push — master ( 1c518a...24c6a1 )
by John
30:27 queued 07:45
created
apps/dav/appinfo/v2/publicremote.php 1 patch
Indentation   +72 added lines, -72 removed lines patch added patch discarded remove patch
@@ -52,26 +52,26 @@  discard block
 block discarded – undo
52 52
 
53 53
 // Backends
54 54
 $authBackend = new PublicAuth(
55
-	$request,
56
-	Server::get(IManager::class),
57
-	$session,
58
-	Server::get(IThrottler::class),
59
-	Server::get(LoggerInterface::class)
55
+    $request,
56
+    Server::get(IManager::class),
57
+    $session,
58
+    Server::get(IThrottler::class),
59
+    Server::get(LoggerInterface::class)
60 60
 );
61 61
 $authPlugin = new \Sabre\DAV\Auth\Plugin($authBackend);
62 62
 
63 63
 $l10nFactory = Server::get(IFactory::class);
64 64
 $serverFactory = new ServerFactory(
65
-	Server::get(IConfig::class),
66
-	Server::get(LoggerInterface::class),
67
-	Server::get(IDBConnection::class),
68
-	Server::get(IUserSession::class),
69
-	Server::get(IMountManager::class),
70
-	Server::get(ITagManager::class),
71
-	$request,
72
-	Server::get(IPreview::class),
73
-	$eventDispatcher,
74
-	$l10nFactory->get('dav'),
65
+    Server::get(IConfig::class),
66
+    Server::get(LoggerInterface::class),
67
+    Server::get(IDBConnection::class),
68
+    Server::get(IUserSession::class),
69
+    Server::get(IMountManager::class),
70
+    Server::get(ITagManager::class),
71
+    $request,
72
+    Server::get(IPreview::class),
73
+    $eventDispatcher,
74
+    $l10nFactory->get('dav'),
75 75
 );
76 76
 
77 77
 
@@ -80,63 +80,63 @@  discard block
 block discarded – undo
80 80
 
81 81
 /** @var string $baseuri defined in public.php */
82 82
 $server = $serverFactory->createServer(true, $baseuri, $requestUri, $authPlugin, function (\Sabre\DAV\Server $server) use ($authBackend, $linkCheckPlugin, $filesDropPlugin) {
83
-	// GET must be allowed for e.g. showing images and allowing Zip downloads
84
-	if ($server->httpRequest->getMethod() !== 'GET') {
85
-		// If this is *not* a GET request we only allow access to public DAV from AJAX or when Server2Server is allowed
86
-		$isAjax = in_array('XMLHttpRequest', explode(',', $_SERVER['HTTP_X_REQUESTED_WITH'] ?? ''));
87
-		$federatedShareProvider = Server::get(FederatedShareProvider::class);
88
-		if ($federatedShareProvider->isOutgoingServer2serverShareEnabled() === false && $isAjax === false) {
89
-			// this is what is thrown when trying to access a non-existing share
90
-			throw new NotAuthenticated();
91
-		}
92
-	}
93
-
94
-	$share = $authBackend->getShare();
95
-	$owner = $share->getShareOwner();
96
-	$isReadable = $share->getPermissions() & Constants::PERMISSION_READ;
97
-	$fileId = $share->getNodeId();
98
-
99
-	// FIXME: should not add storage wrappers outside of preSetup, need to find a better way
100
-	/** @psalm-suppress InternalMethod */
101
-	$previousLog = Filesystem::logWarningWhenAddingStorageWrapper(false);
102
-
103
-	/** @psalm-suppress MissingClosureParamType */
104
-	Filesystem::addStorageWrapper('sharePermissions', function ($mountPoint, $storage) use ($share) {
105
-		return new PermissionsMask(['storage' => $storage, 'mask' => $share->getPermissions() | Constants::PERMISSION_SHARE]);
106
-	});
107
-
108
-	/** @psalm-suppress MissingClosureParamType */
109
-	Filesystem::addStorageWrapper('shareOwner', function ($mountPoint, $storage) use ($share) {
110
-		return new PublicOwnerWrapper(['storage' => $storage, 'owner' => $share->getShareOwner()]);
111
-	});
112
-
113
-	// Ensure that also private shares have the `getShare` method
114
-	/** @psalm-suppress MissingClosureParamType */
115
-	Filesystem::addStorageWrapper('getShare', function ($mountPoint, $storage) use ($share) {
116
-		return new PublicShareWrapper(['storage' => $storage, 'share' => $share]);
117
-	}, 0);
118
-
119
-	/** @psalm-suppress InternalMethod */
120
-	Filesystem::logWarningWhenAddingStorageWrapper($previousLog);
121
-
122
-	$rootFolder = Server::get(IRootFolder::class);
123
-	$userFolder = $rootFolder->getUserFolder($owner);
124
-	$node = $userFolder->getFirstNodeById($fileId);
125
-	if (!$node) {
126
-		throw new NotFound();
127
-	}
128
-	$linkCheckPlugin->setFileInfo($node);
129
-
130
-	// If not readable (files_drop) enable the filesdrop plugin
131
-	if (!$isReadable) {
132
-		$filesDropPlugin->enable();
133
-	}
134
-
135
-	$view = new View($node->getPath());
136
-	$filesDropPlugin->setView($view);
137
-	$filesDropPlugin->setShare($share);
138
-
139
-	return $view;
83
+    // GET must be allowed for e.g. showing images and allowing Zip downloads
84
+    if ($server->httpRequest->getMethod() !== 'GET') {
85
+        // If this is *not* a GET request we only allow access to public DAV from AJAX or when Server2Server is allowed
86
+        $isAjax = in_array('XMLHttpRequest', explode(',', $_SERVER['HTTP_X_REQUESTED_WITH'] ?? ''));
87
+        $federatedShareProvider = Server::get(FederatedShareProvider::class);
88
+        if ($federatedShareProvider->isOutgoingServer2serverShareEnabled() === false && $isAjax === false) {
89
+            // this is what is thrown when trying to access a non-existing share
90
+            throw new NotAuthenticated();
91
+        }
92
+    }
93
+
94
+    $share = $authBackend->getShare();
95
+    $owner = $share->getShareOwner();
96
+    $isReadable = $share->getPermissions() & Constants::PERMISSION_READ;
97
+    $fileId = $share->getNodeId();
98
+
99
+    // FIXME: should not add storage wrappers outside of preSetup, need to find a better way
100
+    /** @psalm-suppress InternalMethod */
101
+    $previousLog = Filesystem::logWarningWhenAddingStorageWrapper(false);
102
+
103
+    /** @psalm-suppress MissingClosureParamType */
104
+    Filesystem::addStorageWrapper('sharePermissions', function ($mountPoint, $storage) use ($share) {
105
+        return new PermissionsMask(['storage' => $storage, 'mask' => $share->getPermissions() | Constants::PERMISSION_SHARE]);
106
+    });
107
+
108
+    /** @psalm-suppress MissingClosureParamType */
109
+    Filesystem::addStorageWrapper('shareOwner', function ($mountPoint, $storage) use ($share) {
110
+        return new PublicOwnerWrapper(['storage' => $storage, 'owner' => $share->getShareOwner()]);
111
+    });
112
+
113
+    // Ensure that also private shares have the `getShare` method
114
+    /** @psalm-suppress MissingClosureParamType */
115
+    Filesystem::addStorageWrapper('getShare', function ($mountPoint, $storage) use ($share) {
116
+        return new PublicShareWrapper(['storage' => $storage, 'share' => $share]);
117
+    }, 0);
118
+
119
+    /** @psalm-suppress InternalMethod */
120
+    Filesystem::logWarningWhenAddingStorageWrapper($previousLog);
121
+
122
+    $rootFolder = Server::get(IRootFolder::class);
123
+    $userFolder = $rootFolder->getUserFolder($owner);
124
+    $node = $userFolder->getFirstNodeById($fileId);
125
+    if (!$node) {
126
+        throw new NotFound();
127
+    }
128
+    $linkCheckPlugin->setFileInfo($node);
129
+
130
+    // If not readable (files_drop) enable the filesdrop plugin
131
+    if (!$isReadable) {
132
+        $filesDropPlugin->enable();
133
+    }
134
+
135
+    $view = new View($node->getPath());
136
+    $filesDropPlugin->setView($view);
137
+    $filesDropPlugin->setShare($share);
138
+
139
+    return $view;
140 140
 });
141 141
 
142 142
 $server->addPlugin($linkCheckPlugin);
Please login to merge, or discard this patch.
apps/dav/appinfo/v1/publicwebdav.php 1 patch
Indentation   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -40,10 +40,10 @@  discard block
 block discarded – undo
40 40
 
41 41
 // Backends
42 42
 $authBackend = new LegacyPublicAuth(
43
-	Server::get(IRequest::class),
44
-	Server::get(\OCP\Share\IManager::class),
45
-	Server::get(ISession::class),
46
-	Server::get(IThrottler::class)
43
+    Server::get(IRequest::class),
44
+    Server::get(\OCP\Share\IManager::class),
45
+    Server::get(ISession::class),
46
+    Server::get(IThrottler::class)
47 47
 );
48 48
 $authPlugin = new \Sabre\DAV\Auth\Plugin($authBackend);
49 49
 
@@ -51,16 +51,16 @@  discard block
 block discarded – undo
51 51
 $eventDispatcher = Server::get(IEventDispatcher::class);
52 52
 
53 53
 $serverFactory = new ServerFactory(
54
-	Server::get(IConfig::class),
55
-	Server::get(LoggerInterface::class),
56
-	Server::get(IDBConnection::class),
57
-	Server::get(IUserSession::class),
58
-	Server::get(IMountManager::class),
59
-	Server::get(ITagManager::class),
60
-	Server::get(IRequest::class),
61
-	Server::get(IPreview::class),
62
-	$eventDispatcher,
63
-	\OC::$server->getL10N('dav')
54
+    Server::get(IConfig::class),
55
+    Server::get(LoggerInterface::class),
56
+    Server::get(IDBConnection::class),
57
+    Server::get(IUserSession::class),
58
+    Server::get(IMountManager::class),
59
+    Server::get(ITagManager::class),
60
+    Server::get(IRequest::class),
61
+    Server::get(IPreview::class),
62
+    $eventDispatcher,
63
+    \OC::$server->getL10N('dav')
64 64
 );
65 65
 
66 66
 $requestUri = Server::get(IRequest::class)->getRequestUri();
@@ -69,47 +69,47 @@  discard block
 block discarded – undo
69 69
 $filesDropPlugin = new FilesDropPlugin();
70 70
 
71 71
 $server = $serverFactory->createServer(false, $baseuri, $requestUri, $authPlugin, function (\Sabre\DAV\Server $server) use ($authBackend, $linkCheckPlugin, $filesDropPlugin) {
72
-	$isAjax = in_array('XMLHttpRequest', explode(',', $_SERVER['HTTP_X_REQUESTED_WITH'] ?? ''));
73
-	/** @var FederatedShareProvider $shareProvider */
74
-	$federatedShareProvider = Server::get(FederatedShareProvider::class);
75
-	if ($federatedShareProvider->isOutgoingServer2serverShareEnabled() === false && !$isAjax) {
76
-		// this is what is thrown when trying to access a non-existing share
77
-		throw new \Sabre\DAV\Exception\NotAuthenticated();
78
-	}
79
-
80
-	$share = $authBackend->getShare();
81
-	$owner = $share->getShareOwner();
82
-	$isReadable = $share->getPermissions() & Constants::PERMISSION_READ;
83
-	$fileId = $share->getNodeId();
84
-
85
-	// FIXME: should not add storage wrappers outside of preSetup, need to find a better way
86
-	$previousLog = Filesystem::logWarningWhenAddingStorageWrapper(false);
87
-	Filesystem::addStorageWrapper('sharePermissions', function ($mountPoint, $storage) use ($share) {
88
-		return new PermissionsMask(['storage' => $storage, 'mask' => $share->getPermissions() | Constants::PERMISSION_SHARE]);
89
-	});
90
-	Filesystem::addStorageWrapper('shareOwner', function ($mountPoint, $storage) use ($share) {
91
-		return new PublicOwnerWrapper(['storage' => $storage, 'owner' => $share->getShareOwner()]);
92
-	});
93
-	Filesystem::logWarningWhenAddingStorageWrapper($previousLog);
94
-
95
-	$rootFolder = Server::get(IRootFolder::class);
96
-	$userFolder = $rootFolder->getUserFolder($owner);
97
-	$node = $userFolder->getFirstNodeById($fileId);
98
-	if (!$node) {
99
-		throw new \Sabre\DAV\Exception\NotFound();
100
-	}
101
-	$linkCheckPlugin->setFileInfo($node);
102
-
103
-	// If not readable (files_drop) enable the filesdrop plugin
104
-	if (!$isReadable) {
105
-		$filesDropPlugin->enable();
106
-	}
107
-
108
-	$view = new View($node->getPath());
109
-	$filesDropPlugin->setView($view);
110
-	$filesDropPlugin->setShare($share);
111
-
112
-	return $view;
72
+    $isAjax = in_array('XMLHttpRequest', explode(',', $_SERVER['HTTP_X_REQUESTED_WITH'] ?? ''));
73
+    /** @var FederatedShareProvider $shareProvider */
74
+    $federatedShareProvider = Server::get(FederatedShareProvider::class);
75
+    if ($federatedShareProvider->isOutgoingServer2serverShareEnabled() === false && !$isAjax) {
76
+        // this is what is thrown when trying to access a non-existing share
77
+        throw new \Sabre\DAV\Exception\NotAuthenticated();
78
+    }
79
+
80
+    $share = $authBackend->getShare();
81
+    $owner = $share->getShareOwner();
82
+    $isReadable = $share->getPermissions() & Constants::PERMISSION_READ;
83
+    $fileId = $share->getNodeId();
84
+
85
+    // FIXME: should not add storage wrappers outside of preSetup, need to find a better way
86
+    $previousLog = Filesystem::logWarningWhenAddingStorageWrapper(false);
87
+    Filesystem::addStorageWrapper('sharePermissions', function ($mountPoint, $storage) use ($share) {
88
+        return new PermissionsMask(['storage' => $storage, 'mask' => $share->getPermissions() | Constants::PERMISSION_SHARE]);
89
+    });
90
+    Filesystem::addStorageWrapper('shareOwner', function ($mountPoint, $storage) use ($share) {
91
+        return new PublicOwnerWrapper(['storage' => $storage, 'owner' => $share->getShareOwner()]);
92
+    });
93
+    Filesystem::logWarningWhenAddingStorageWrapper($previousLog);
94
+
95
+    $rootFolder = Server::get(IRootFolder::class);
96
+    $userFolder = $rootFolder->getUserFolder($owner);
97
+    $node = $userFolder->getFirstNodeById($fileId);
98
+    if (!$node) {
99
+        throw new \Sabre\DAV\Exception\NotFound();
100
+    }
101
+    $linkCheckPlugin->setFileInfo($node);
102
+
103
+    // If not readable (files_drop) enable the filesdrop plugin
104
+    if (!$isReadable) {
105
+        $filesDropPlugin->enable();
106
+    }
107
+
108
+    $view = new View($node->getPath());
109
+    $filesDropPlugin->setView($view);
110
+    $filesDropPlugin->setShare($share);
111
+
112
+    return $view;
113 113
 });
114 114
 
115 115
 $server->addPlugin($linkCheckPlugin);
Please login to merge, or discard this patch.
apps/dav/appinfo/v1/webdav.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
 
27 27
 // no php execution timeout for webdav
28 28
 if (!str_contains(@ini_get('disable_functions'), 'set_time_limit')) {
29
-	@set_time_limit(0);
29
+    @set_time_limit(0);
30 30
 }
31 31
 ignore_user_abort(true);
32 32
 
@@ -36,41 +36,41 @@  discard block
 block discarded – undo
36 36
 $dispatcher = Server::get(IEventDispatcher::class);
37 37
 
38 38
 $serverFactory = new ServerFactory(
39
-	Server::get(IConfig::class),
40
-	Server::get(LoggerInterface::class),
41
-	Server::get(IDBConnection::class),
42
-	Server::get(IUserSession::class),
43
-	Server::get(IMountManager::class),
44
-	Server::get(ITagManager::class),
45
-	Server::get(IRequest::class),
46
-	Server::get(IPreview::class),
47
-	$dispatcher,
48
-	\OC::$server->getL10N('dav')
39
+    Server::get(IConfig::class),
40
+    Server::get(LoggerInterface::class),
41
+    Server::get(IDBConnection::class),
42
+    Server::get(IUserSession::class),
43
+    Server::get(IMountManager::class),
44
+    Server::get(ITagManager::class),
45
+    Server::get(IRequest::class),
46
+    Server::get(IPreview::class),
47
+    $dispatcher,
48
+    \OC::$server->getL10N('dav')
49 49
 );
50 50
 
51 51
 // Backends
52 52
 $authBackend = new Auth(
53
-	Server::get(ISession::class),
54
-	Server::get(IUserSession::class),
55
-	Server::get(IRequest::class),
56
-	Server::get(\OC\Authentication\TwoFactorAuth\Manager::class),
57
-	Server::get(IThrottler::class),
58
-	'principals/'
53
+    Server::get(ISession::class),
54
+    Server::get(IUserSession::class),
55
+    Server::get(IRequest::class),
56
+    Server::get(\OC\Authentication\TwoFactorAuth\Manager::class),
57
+    Server::get(IThrottler::class),
58
+    'principals/'
59 59
 );
60 60
 $authPlugin = new \Sabre\DAV\Auth\Plugin($authBackend);
61 61
 $bearerAuthPlugin = new BearerAuth(
62
-	Server::get(IUserSession::class),
63
-	Server::get(ISession::class),
64
-	Server::get(IRequest::class),
65
-	Server::get(IConfig::class),
62
+    Server::get(IUserSession::class),
63
+    Server::get(ISession::class),
64
+    Server::get(IRequest::class),
65
+    Server::get(IConfig::class),
66 66
 );
67 67
 $authPlugin->addBackend($bearerAuthPlugin);
68 68
 
69 69
 $requestUri = Server::get(IRequest::class)->getRequestUri();
70 70
 
71 71
 $server = $serverFactory->createServer(false, $baseuri, $requestUri, $authPlugin, function () {
72
-	// use the view for the logged in user
73
-	return Filesystem::getView();
72
+    // use the view for the logged in user
73
+    return Filesystem::getView();
74 74
 });
75 75
 
76 76
 // allow setup of additional plugins
Please login to merge, or discard this patch.
apps/dav/tests/unit/Connector/Sabre/RequestTest/RequestTestCase.php 1 patch
Indentation   +117 added lines, -117 removed lines patch added patch discarded remove patch
@@ -27,121 +27,121 @@
 block discarded – undo
27 27
 use Test\Traits\UserTrait;
28 28
 
29 29
 abstract class RequestTestCase extends TestCase {
30
-	use UserTrait;
31
-	use MountProviderTrait;
32
-
33
-	/**
34
-	 * @var ServerFactory
35
-	 */
36
-	protected $serverFactory;
37
-
38
-	protected function getStream($string) {
39
-		$stream = fopen('php://temp', 'r+');
40
-		fwrite($stream, $string);
41
-		fseek($stream, 0);
42
-		return $stream;
43
-	}
44
-
45
-	protected function setUp(): void {
46
-		parent::setUp();
47
-
48
-		$this->serverFactory = new ServerFactory(
49
-			\OCP\Server::get(IConfig::class),
50
-			\OCP\Server::get(LoggerInterface::class),
51
-			\OCP\Server::get(IDBConnection::class),
52
-			\OCP\Server::get(IUserSession::class),
53
-			\OCP\Server::get(IMountManager::class),
54
-			\OCP\Server::get(ITagManager::class),
55
-			$this->getMockBuilder(IRequest::class)
56
-				->disableOriginalConstructor()
57
-				->getMock(),
58
-			\OCP\Server::get(IPreview::class),
59
-			\OCP\Server::get(IEventDispatcher::class),
60
-			\OC::$server->getL10N('dav')
61
-		);
62
-	}
63
-
64
-	protected function setupUser($name, $password) {
65
-		$this->createUser($name, $password);
66
-		$tmpFolder = \OCP\Server::get(ITempManager::class)->getTemporaryFolder();
67
-		$this->registerMount($name, '\OC\Files\Storage\Local', '/' . $name, ['datadir' => $tmpFolder]);
68
-		$this->loginAsUser($name);
69
-		return new View('/' . $name . '/files');
70
-	}
71
-
72
-	/**
73
-	 * @param View $view the view to run the webdav server against
74
-	 * @param string $user
75
-	 * @param string $password
76
-	 * @param string $method
77
-	 * @param string $url
78
-	 * @param resource|string|null $body
79
-	 * @param array|null $headers
80
-	 * @return \Sabre\HTTP\Response
81
-	 * @throws \Exception
82
-	 */
83
-	protected function request($view, $user, $password, $method, $url, $body = null, $headers = []) {
84
-		if (is_string($body)) {
85
-			$body = $this->getStream($body);
86
-		}
87
-		$this->logout();
88
-		$exceptionPlugin = new ExceptionPlugin('webdav', \OCP\Server::get(LoggerInterface::class));
89
-		$server = $this->getSabreServer($view, $user, $password, $exceptionPlugin);
90
-		$request = new Request($method, $url, $headers, $body);
91
-
92
-		// since sabre catches all exceptions we need to save them and throw them from outside the sabre server
93
-
94
-		$serverParams = [];
95
-		if (is_array($headers)) {
96
-			foreach ($headers as $header => $value) {
97
-				$serverParams['HTTP_' . strtoupper(str_replace('-', '_', $header))] = $value;
98
-			}
99
-		}
100
-		$ncRequest = new \OC\AppFramework\Http\Request([
101
-			'server' => $serverParams
102
-		], $this->createMock(IRequestId::class), $this->createMock(IConfig::class), null);
103
-
104
-		$this->overwriteService(IRequest::class, $ncRequest);
105
-
106
-		$result = $this->makeRequest($server, $request);
107
-
108
-		$this->restoreService(IRequest::class);
109
-
110
-		foreach ($exceptionPlugin->getExceptions() as $exception) {
111
-			throw $exception;
112
-		}
113
-		return $result;
114
-	}
115
-
116
-	/**
117
-	 * @param Server $server
118
-	 * @param Request $request
119
-	 * @return \Sabre\HTTP\Response
120
-	 */
121
-	protected function makeRequest(Server $server, Request $request) {
122
-		$sapi = new Sapi($request);
123
-		$server->sapi = $sapi;
124
-		$server->httpRequest = $request;
125
-		$server->exec();
126
-		return $sapi->getResponse();
127
-	}
128
-
129
-	/**
130
-	 * @param View $view
131
-	 * @param string $user
132
-	 * @param string $password
133
-	 * @param ExceptionPlugin $exceptionPlugin
134
-	 * @return Server
135
-	 */
136
-	protected function getSabreServer(View $view, $user, $password, ExceptionPlugin $exceptionPlugin) {
137
-		$authBackend = new Auth($user, $password);
138
-		$authPlugin = new \Sabre\DAV\Auth\Plugin($authBackend);
139
-
140
-		$server = $this->serverFactory->createServer(false, '/', 'dummy', $authPlugin, function () use ($view) {
141
-			return $view;
142
-		});
143
-		$server->addPlugin($exceptionPlugin);
144
-
145
-		return $server;
146
-	}
30
+    use UserTrait;
31
+    use MountProviderTrait;
32
+
33
+    /**
34
+     * @var ServerFactory
35
+     */
36
+    protected $serverFactory;
37
+
38
+    protected function getStream($string) {
39
+        $stream = fopen('php://temp', 'r+');
40
+        fwrite($stream, $string);
41
+        fseek($stream, 0);
42
+        return $stream;
43
+    }
44
+
45
+    protected function setUp(): void {
46
+        parent::setUp();
47
+
48
+        $this->serverFactory = new ServerFactory(
49
+            \OCP\Server::get(IConfig::class),
50
+            \OCP\Server::get(LoggerInterface::class),
51
+            \OCP\Server::get(IDBConnection::class),
52
+            \OCP\Server::get(IUserSession::class),
53
+            \OCP\Server::get(IMountManager::class),
54
+            \OCP\Server::get(ITagManager::class),
55
+            $this->getMockBuilder(IRequest::class)
56
+                ->disableOriginalConstructor()
57
+                ->getMock(),
58
+            \OCP\Server::get(IPreview::class),
59
+            \OCP\Server::get(IEventDispatcher::class),
60
+            \OC::$server->getL10N('dav')
61
+        );
62
+    }
63
+
64
+    protected function setupUser($name, $password) {
65
+        $this->createUser($name, $password);
66
+        $tmpFolder = \OCP\Server::get(ITempManager::class)->getTemporaryFolder();
67
+        $this->registerMount($name, '\OC\Files\Storage\Local', '/' . $name, ['datadir' => $tmpFolder]);
68
+        $this->loginAsUser($name);
69
+        return new View('/' . $name . '/files');
70
+    }
71
+
72
+    /**
73
+     * @param View $view the view to run the webdav server against
74
+     * @param string $user
75
+     * @param string $password
76
+     * @param string $method
77
+     * @param string $url
78
+     * @param resource|string|null $body
79
+     * @param array|null $headers
80
+     * @return \Sabre\HTTP\Response
81
+     * @throws \Exception
82
+     */
83
+    protected function request($view, $user, $password, $method, $url, $body = null, $headers = []) {
84
+        if (is_string($body)) {
85
+            $body = $this->getStream($body);
86
+        }
87
+        $this->logout();
88
+        $exceptionPlugin = new ExceptionPlugin('webdav', \OCP\Server::get(LoggerInterface::class));
89
+        $server = $this->getSabreServer($view, $user, $password, $exceptionPlugin);
90
+        $request = new Request($method, $url, $headers, $body);
91
+
92
+        // since sabre catches all exceptions we need to save them and throw them from outside the sabre server
93
+
94
+        $serverParams = [];
95
+        if (is_array($headers)) {
96
+            foreach ($headers as $header => $value) {
97
+                $serverParams['HTTP_' . strtoupper(str_replace('-', '_', $header))] = $value;
98
+            }
99
+        }
100
+        $ncRequest = new \OC\AppFramework\Http\Request([
101
+            'server' => $serverParams
102
+        ], $this->createMock(IRequestId::class), $this->createMock(IConfig::class), null);
103
+
104
+        $this->overwriteService(IRequest::class, $ncRequest);
105
+
106
+        $result = $this->makeRequest($server, $request);
107
+
108
+        $this->restoreService(IRequest::class);
109
+
110
+        foreach ($exceptionPlugin->getExceptions() as $exception) {
111
+            throw $exception;
112
+        }
113
+        return $result;
114
+    }
115
+
116
+    /**
117
+     * @param Server $server
118
+     * @param Request $request
119
+     * @return \Sabre\HTTP\Response
120
+     */
121
+    protected function makeRequest(Server $server, Request $request) {
122
+        $sapi = new Sapi($request);
123
+        $server->sapi = $sapi;
124
+        $server->httpRequest = $request;
125
+        $server->exec();
126
+        return $sapi->getResponse();
127
+    }
128
+
129
+    /**
130
+     * @param View $view
131
+     * @param string $user
132
+     * @param string $password
133
+     * @param ExceptionPlugin $exceptionPlugin
134
+     * @return Server
135
+     */
136
+    protected function getSabreServer(View $view, $user, $password, ExceptionPlugin $exceptionPlugin) {
137
+        $authBackend = new Auth($user, $password);
138
+        $authPlugin = new \Sabre\DAV\Auth\Plugin($authBackend);
139
+
140
+        $server = $this->serverFactory->createServer(false, '/', 'dummy', $authPlugin, function () use ($view) {
141
+            return $view;
142
+        });
143
+        $server->addPlugin($exceptionPlugin);
144
+
145
+        return $server;
146
+    }
147 147
 }
Please login to merge, or discard this patch.
apps/dav/tests/unit/CapabilitiesTest.php 1 patch
Indentation   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -14,66 +14,66 @@
 block discarded – undo
14 14
  * @package OCA\DAV\Tests\unit
15 15
  */
16 16
 class CapabilitiesTest extends TestCase {
17
-	public function testGetCapabilities(): void {
18
-		$config = $this->createMock(IConfig::class);
19
-		$config->expects($this->once())
20
-			->method('getSystemValueBool')
21
-			->with('bulkupload.enabled', $this->isType('bool'))
22
-			->willReturn(false);
23
-		$coordinator = $this->createMock(IAvailabilityCoordinator::class);
24
-		$coordinator->expects($this->once())
25
-			->method('isEnabled')
26
-			->willReturn(false);
27
-		$capabilities = new Capabilities($config, $coordinator);
28
-		$expected = [
29
-			'dav' => [
30
-				'chunking' => '1.0',
31
-				'public_shares_chunking' => true,
32
-			],
33
-		];
34
-		$this->assertSame($expected, $capabilities->getCapabilities());
35
-	}
17
+    public function testGetCapabilities(): void {
18
+        $config = $this->createMock(IConfig::class);
19
+        $config->expects($this->once())
20
+            ->method('getSystemValueBool')
21
+            ->with('bulkupload.enabled', $this->isType('bool'))
22
+            ->willReturn(false);
23
+        $coordinator = $this->createMock(IAvailabilityCoordinator::class);
24
+        $coordinator->expects($this->once())
25
+            ->method('isEnabled')
26
+            ->willReturn(false);
27
+        $capabilities = new Capabilities($config, $coordinator);
28
+        $expected = [
29
+            'dav' => [
30
+                'chunking' => '1.0',
31
+                'public_shares_chunking' => true,
32
+            ],
33
+        ];
34
+        $this->assertSame($expected, $capabilities->getCapabilities());
35
+    }
36 36
 
37
-	public function testGetCapabilitiesWithBulkUpload(): void {
38
-		$config = $this->createMock(IConfig::class);
39
-		$config->expects($this->once())
40
-			->method('getSystemValueBool')
41
-			->with('bulkupload.enabled', $this->isType('bool'))
42
-			->willReturn(true);
43
-		$coordinator = $this->createMock(IAvailabilityCoordinator::class);
44
-		$coordinator->expects($this->once())
45
-			->method('isEnabled')
46
-			->willReturn(false);
47
-		$capabilities = new Capabilities($config, $coordinator);
48
-		$expected = [
49
-			'dav' => [
50
-				'chunking' => '1.0',
51
-				'public_shares_chunking' => true,
52
-				'bulkupload' => '1.0',
53
-			],
54
-		];
55
-		$this->assertSame($expected, $capabilities->getCapabilities());
56
-	}
37
+    public function testGetCapabilitiesWithBulkUpload(): void {
38
+        $config = $this->createMock(IConfig::class);
39
+        $config->expects($this->once())
40
+            ->method('getSystemValueBool')
41
+            ->with('bulkupload.enabled', $this->isType('bool'))
42
+            ->willReturn(true);
43
+        $coordinator = $this->createMock(IAvailabilityCoordinator::class);
44
+        $coordinator->expects($this->once())
45
+            ->method('isEnabled')
46
+            ->willReturn(false);
47
+        $capabilities = new Capabilities($config, $coordinator);
48
+        $expected = [
49
+            'dav' => [
50
+                'chunking' => '1.0',
51
+                'public_shares_chunking' => true,
52
+                'bulkupload' => '1.0',
53
+            ],
54
+        ];
55
+        $this->assertSame($expected, $capabilities->getCapabilities());
56
+    }
57 57
 
58
-	public function testGetCapabilitiesWithAbsence(): void {
59
-		$config = $this->createMock(IConfig::class);
60
-		$config->expects($this->once())
61
-			->method('getSystemValueBool')
62
-			->with('bulkupload.enabled', $this->isType('bool'))
63
-			->willReturn(false);
64
-		$coordinator = $this->createMock(IAvailabilityCoordinator::class);
65
-		$coordinator->expects($this->once())
66
-			->method('isEnabled')
67
-			->willReturn(true);
68
-		$capabilities = new Capabilities($config, $coordinator);
69
-		$expected = [
70
-			'dav' => [
71
-				'chunking' => '1.0',
72
-				'public_shares_chunking' => true,
73
-				'absence-supported' => true,
74
-				'absence-replacement' => true,
75
-			],
76
-		];
77
-		$this->assertSame($expected, $capabilities->getCapabilities());
78
-	}
58
+    public function testGetCapabilitiesWithAbsence(): void {
59
+        $config = $this->createMock(IConfig::class);
60
+        $config->expects($this->once())
61
+            ->method('getSystemValueBool')
62
+            ->with('bulkupload.enabled', $this->isType('bool'))
63
+            ->willReturn(false);
64
+        $coordinator = $this->createMock(IAvailabilityCoordinator::class);
65
+        $coordinator->expects($this->once())
66
+            ->method('isEnabled')
67
+            ->willReturn(true);
68
+        $capabilities = new Capabilities($config, $coordinator);
69
+        $expected = [
70
+            'dav' => [
71
+                'chunking' => '1.0',
72
+                'public_shares_chunking' => true,
73
+                'absence-supported' => true,
74
+                'absence-replacement' => true,
75
+            ],
76
+        ];
77
+        $this->assertSame($expected, $capabilities->getCapabilities());
78
+    }
79 79
 }
Please login to merge, or discard this patch.
apps/dav/tests/unit/Files/Sharing/FilesDropPluginTest.php 1 patch
Indentation   +120 added lines, -120 removed lines patch added patch discarded remove patch
@@ -17,165 +17,165 @@
 block discarded – undo
17 17
 
18 18
 class FilesDropPluginTest extends TestCase {
19 19
 
20
-	/** @var View|\PHPUnit\Framework\MockObject\MockObject */
21
-	private $view;
20
+    /** @var View|\PHPUnit\Framework\MockObject\MockObject */
21
+    private $view;
22 22
 
23
-	/** @var IShare|\PHPUnit\Framework\MockObject\MockObject */
24
-	private $share;
23
+    /** @var IShare|\PHPUnit\Framework\MockObject\MockObject */
24
+    private $share;
25 25
 
26
-	/** @var Server|\PHPUnit\Framework\MockObject\MockObject */
27
-	private $server;
26
+    /** @var Server|\PHPUnit\Framework\MockObject\MockObject */
27
+    private $server;
28 28
 
29
-	/** @var FilesDropPlugin */
30
-	private $plugin;
29
+    /** @var FilesDropPlugin */
30
+    private $plugin;
31 31
 
32
-	/** @var RequestInterface|\PHPUnit\Framework\MockObject\MockObject */
33
-	private $request;
32
+    /** @var RequestInterface|\PHPUnit\Framework\MockObject\MockObject */
33
+    private $request;
34 34
 
35
-	/** @var ResponseInterface|\PHPUnit\Framework\MockObject\MockObject */
36
-	private $response;
35
+    /** @var ResponseInterface|\PHPUnit\Framework\MockObject\MockObject */
36
+    private $response;
37 37
 
38
-	protected function setUp(): void {
39
-		parent::setUp();
38
+    protected function setUp(): void {
39
+        parent::setUp();
40 40
 
41
-		$this->view = $this->createMock(View::class);
42
-		$this->share = $this->createMock(IShare::class);
43
-		$this->server = $this->createMock(Server::class);
44
-		$this->plugin = new FilesDropPlugin();
41
+        $this->view = $this->createMock(View::class);
42
+        $this->share = $this->createMock(IShare::class);
43
+        $this->server = $this->createMock(Server::class);
44
+        $this->plugin = new FilesDropPlugin();
45 45
 
46
-		$this->request = $this->createMock(RequestInterface::class);
47
-		$this->response = $this->createMock(ResponseInterface::class);
46
+        $this->request = $this->createMock(RequestInterface::class);
47
+        $this->response = $this->createMock(ResponseInterface::class);
48 48
 
49
-		$this->response->expects($this->never())
50
-			->method($this->anything());
49
+        $this->response->expects($this->never())
50
+            ->method($this->anything());
51 51
 
52
-		$attributes = $this->createMock(IAttributes::class);
53
-		$this->share->expects($this->any())
54
-			->method('getAttributes')
55
-			->willReturn($attributes);
52
+        $attributes = $this->createMock(IAttributes::class);
53
+        $this->share->expects($this->any())
54
+            ->method('getAttributes')
55
+            ->willReturn($attributes);
56 56
 
57
-		$this->share
58
-			->method('getToken')
59
-			->willReturn('token');
60
-	}
57
+        $this->share
58
+            ->method('getToken')
59
+            ->willReturn('token');
60
+    }
61 61
 
62
-	public function testInitialize(): void {
63
-		$this->server->expects($this->once())
64
-			->method('on')
65
-			->with(
66
-				$this->equalTo('beforeMethod:*'),
67
-				$this->equalTo([$this->plugin, 'beforeMethod']),
68
-				$this->equalTo(999)
69
-			);
62
+    public function testInitialize(): void {
63
+        $this->server->expects($this->once())
64
+            ->method('on')
65
+            ->with(
66
+                $this->equalTo('beforeMethod:*'),
67
+                $this->equalTo([$this->plugin, 'beforeMethod']),
68
+                $this->equalTo(999)
69
+            );
70 70
 
71
-		$this->plugin->initialize($this->server);
72
-	}
71
+        $this->plugin->initialize($this->server);
72
+    }
73 73
 
74
-	public function testNotEnabled(): void {
75
-		$this->view->expects($this->never())
76
-			->method($this->anything());
74
+    public function testNotEnabled(): void {
75
+        $this->view->expects($this->never())
76
+            ->method($this->anything());
77 77
 
78
-		$this->request->expects($this->never())
79
-			->method($this->anything());
78
+        $this->request->expects($this->never())
79
+            ->method($this->anything());
80 80
 
81
-		$this->plugin->beforeMethod($this->request, $this->response);
82
-	}
81
+        $this->plugin->beforeMethod($this->request, $this->response);
82
+    }
83 83
 
84
-	public function testValid(): void {
85
-		$this->plugin->enable();
86
-		$this->plugin->setView($this->view);
87
-		$this->plugin->setShare($this->share);
84
+    public function testValid(): void {
85
+        $this->plugin->enable();
86
+        $this->plugin->setView($this->view);
87
+        $this->plugin->setShare($this->share);
88 88
 
89
-		$this->request->method('getMethod')
90
-			->willReturn('PUT');
89
+        $this->request->method('getMethod')
90
+            ->willReturn('PUT');
91 91
 
92
-		$this->request->method('getPath')
93
-			->willReturn('/files/token/file.txt');
92
+        $this->request->method('getPath')
93
+            ->willReturn('/files/token/file.txt');
94 94
 
95
-		$this->request->method('getBaseUrl')
96
-			->willReturn('https://example.com');
95
+        $this->request->method('getBaseUrl')
96
+            ->willReturn('https://example.com');
97 97
 
98
-		$this->view->method('file_exists')
99
-			->with('/file.txt')
100
-			->willReturn(false);
98
+        $this->view->method('file_exists')
99
+            ->with('/file.txt')
100
+            ->willReturn(false);
101 101
 
102
-		$this->request->expects($this->once())
103
-			->method('setUrl')
104
-			->with('https://example.com/files/token/file.txt');
102
+        $this->request->expects($this->once())
103
+            ->method('setUrl')
104
+            ->with('https://example.com/files/token/file.txt');
105 105
 
106
-		$this->plugin->beforeMethod($this->request, $this->response);
107
-	}
106
+        $this->plugin->beforeMethod($this->request, $this->response);
107
+    }
108 108
 
109
-	public function testFileAlreadyExistsValid(): void {
110
-		$this->plugin->enable();
111
-		$this->plugin->setView($this->view);
112
-		$this->plugin->setShare($this->share);
109
+    public function testFileAlreadyExistsValid(): void {
110
+        $this->plugin->enable();
111
+        $this->plugin->setView($this->view);
112
+        $this->plugin->setShare($this->share);
113 113
 
114
-		$this->request->method('getMethod')
115
-			->willReturn('PUT');
114
+        $this->request->method('getMethod')
115
+            ->willReturn('PUT');
116 116
 
117
-		$this->request->method('getPath')
118
-			->willReturn('/files/token/file.txt');
117
+        $this->request->method('getPath')
118
+            ->willReturn('/files/token/file.txt');
119 119
 
120
-		$this->request->method('getBaseUrl')
121
-			->willReturn('https://example.com');
120
+        $this->request->method('getBaseUrl')
121
+            ->willReturn('https://example.com');
122 122
 
123
-		$this->view->method('file_exists')
124
-			->willReturnCallback(function ($path) {
125
-				if ($path === 'file.txt' || $path === '/file.txt') {
126
-					return true;
127
-				} else {
128
-					return false;
129
-				}
130
-			});
123
+        $this->view->method('file_exists')
124
+            ->willReturnCallback(function ($path) {
125
+                if ($path === 'file.txt' || $path === '/file.txt') {
126
+                    return true;
127
+                } else {
128
+                    return false;
129
+                }
130
+            });
131 131
 
132
-		$this->request->expects($this->once())
133
-			->method('setUrl')
134
-			->with($this->equalTo('https://example.com/files/token/file (2).txt'));
132
+        $this->request->expects($this->once())
133
+            ->method('setUrl')
134
+            ->with($this->equalTo('https://example.com/files/token/file (2).txt'));
135 135
 
136
-		$this->plugin->beforeMethod($this->request, $this->response);
137
-	}
136
+        $this->plugin->beforeMethod($this->request, $this->response);
137
+    }
138 138
 
139
-	public function testNoMKCOL(): void {
140
-		$this->plugin->enable();
141
-		$this->plugin->setView($this->view);
142
-		$this->plugin->setShare($this->share);
139
+    public function testNoMKCOL(): void {
140
+        $this->plugin->enable();
141
+        $this->plugin->setView($this->view);
142
+        $this->plugin->setShare($this->share);
143 143
 
144
-		$this->request->method('getMethod')
145
-			->willReturn('MKCOL');
144
+        $this->request->method('getMethod')
145
+            ->willReturn('MKCOL');
146 146
 
147
-		$this->expectException(MethodNotAllowed::class);
147
+        $this->expectException(MethodNotAllowed::class);
148 148
 
149
-		$this->plugin->beforeMethod($this->request, $this->response);
150
-	}
149
+        $this->plugin->beforeMethod($this->request, $this->response);
150
+    }
151 151
 
152
-	public function testNoSubdirPut(): void {
153
-		$this->plugin->enable();
154
-		$this->plugin->setView($this->view);
155
-		$this->plugin->setShare($this->share);
152
+    public function testNoSubdirPut(): void {
153
+        $this->plugin->enable();
154
+        $this->plugin->setView($this->view);
155
+        $this->plugin->setShare($this->share);
156 156
 
157
-		$this->request->method('getMethod')
158
-			->willReturn('PUT');
157
+        $this->request->method('getMethod')
158
+            ->willReturn('PUT');
159 159
 
160
-		$this->request->method('getPath')
161
-			->willReturn('/files/token/folder/file.txt');
160
+        $this->request->method('getPath')
161
+            ->willReturn('/files/token/folder/file.txt');
162 162
 
163
-		$this->request->method('getBaseUrl')
164
-			->willReturn('https://example.com');
163
+        $this->request->method('getBaseUrl')
164
+            ->willReturn('https://example.com');
165 165
 
166
-		$this->view->method('file_exists')
167
-			->willReturnCallback(function ($path) {
168
-				if ($path === 'file.txt' || $path === '/file.txt') {
169
-					return true;
170
-				} else {
171
-					return false;
172
-				}
173
-			});
166
+        $this->view->method('file_exists')
167
+            ->willReturnCallback(function ($path) {
168
+                if ($path === 'file.txt' || $path === '/file.txt') {
169
+                    return true;
170
+                } else {
171
+                    return false;
172
+                }
173
+            });
174 174
 
175
-		$this->request->expects($this->once())
176
-			->method('setUrl')
177
-			->with($this->equalTo('https://example.com/files/token/file (2).txt'));
175
+        $this->request->expects($this->once())
176
+            ->method('setUrl')
177
+            ->with($this->equalTo('https://example.com/files/token/file (2).txt'));
178 178
 
179
-		$this->plugin->beforeMethod($this->request, $this->response);
180
-	}
179
+        $this->plugin->beforeMethod($this->request, $this->response);
180
+    }
181 181
 }
Please login to merge, or discard this patch.
apps/dav/lib/Capabilities.php 1 patch
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -10,29 +10,29 @@
 block discarded – undo
10 10
 use OCP\User\IAvailabilityCoordinator;
11 11
 
12 12
 class Capabilities implements ICapability {
13
-	public function __construct(
14
-		private IConfig $config,
15
-		private IAvailabilityCoordinator $coordinator,
16
-	) {
17
-	}
13
+    public function __construct(
14
+        private IConfig $config,
15
+        private IAvailabilityCoordinator $coordinator,
16
+    ) {
17
+    }
18 18
 
19
-	/**
20
-	 * @return array{dav: array{chunking: string, public_shares_chunking: bool, bulkupload?: string, absence-supported?: bool, absence-replacement?: bool}}
21
-	 */
22
-	public function getCapabilities() {
23
-		$capabilities = [
24
-			'dav' => [
25
-				'chunking' => '1.0',
26
-				'public_shares_chunking' => true,
27
-			]
28
-		];
29
-		if ($this->config->getSystemValueBool('bulkupload.enabled', true)) {
30
-			$capabilities['dav']['bulkupload'] = '1.0';
31
-		}
32
-		if ($this->coordinator->isEnabled()) {
33
-			$capabilities['dav']['absence-supported'] = true;
34
-			$capabilities['dav']['absence-replacement'] = true;
35
-		}
36
-		return $capabilities;
37
-	}
19
+    /**
20
+     * @return array{dav: array{chunking: string, public_shares_chunking: bool, bulkupload?: string, absence-supported?: bool, absence-replacement?: bool}}
21
+     */
22
+    public function getCapabilities() {
23
+        $capabilities = [
24
+            'dav' => [
25
+                'chunking' => '1.0',
26
+                'public_shares_chunking' => true,
27
+            ]
28
+        ];
29
+        if ($this->config->getSystemValueBool('bulkupload.enabled', true)) {
30
+            $capabilities['dav']['bulkupload'] = '1.0';
31
+        }
32
+        if ($this->coordinator->isEnabled()) {
33
+            $capabilities['dav']['absence-supported'] = true;
34
+            $capabilities['dav']['absence-replacement'] = true;
35
+        }
36
+        return $capabilities;
37
+    }
38 38
 }
Please login to merge, or discard this patch.
apps/dav/lib/RootCollection.php 1 patch
Indentation   +154 added lines, -154 removed lines patch added patch discarded remove patch
@@ -46,158 +46,158 @@
 block discarded – undo
46 46
 use Sabre\DAV\SimpleCollection;
47 47
 
48 48
 class RootCollection extends SimpleCollection {
49
-	public function __construct() {
50
-		$l10n = \OC::$server->getL10N('dav');
51
-		$random = Server::get(ISecureRandom::class);
52
-		$logger = Server::get(LoggerInterface::class);
53
-		$userManager = Server::get(IUserManager::class);
54
-		$userSession = Server::get(IUserSession::class);
55
-		$groupManager = Server::get(IGroupManager::class);
56
-		$shareManager = Server::get(\OCP\Share\IManager::class);
57
-		$db = Server::get(IDBConnection::class);
58
-		$dispatcher = Server::get(IEventDispatcher::class);
59
-		$config = Server::get(IConfig::class);
60
-		$proxyMapper = Server::get(ProxyMapper::class);
61
-		$rootFolder = Server::get(IRootFolder::class);
62
-
63
-		$userPrincipalBackend = new Principal(
64
-			$userManager,
65
-			$groupManager,
66
-			Server::get(IAccountManager::class),
67
-			$shareManager,
68
-			Server::get(IUserSession::class),
69
-			Server::get(IAppManager::class),
70
-			$proxyMapper,
71
-			Server::get(KnownUserService::class),
72
-			Server::get(IConfig::class),
73
-			\OC::$server->getL10NFactory()
74
-		);
75
-
76
-		$groupPrincipalBackend = new GroupPrincipalBackend($groupManager, $userSession, $shareManager, $config);
77
-		$calendarResourcePrincipalBackend = new ResourcePrincipalBackend($db, $userSession, $groupManager, $logger, $proxyMapper);
78
-		$calendarRoomPrincipalBackend = new RoomPrincipalBackend($db, $userSession, $groupManager, $logger, $proxyMapper);
79
-		// as soon as debug mode is enabled we allow listing of principals
80
-		$disableListing = !$config->getSystemValue('debug', false);
81
-
82
-		// setup the first level of the dav tree
83
-		$userPrincipals = new Collection($userPrincipalBackend, 'principals/users');
84
-		$userPrincipals->disableListing = $disableListing;
85
-		$groupPrincipals = new Collection($groupPrincipalBackend, 'principals/groups');
86
-		$groupPrincipals->disableListing = $disableListing;
87
-		$systemPrincipals = new Collection(new SystemPrincipalBackend(), 'principals/system');
88
-		$systemPrincipals->disableListing = $disableListing;
89
-		$calendarResourcePrincipals = new Collection($calendarResourcePrincipalBackend, 'principals/calendar-resources');
90
-		$calendarRoomPrincipals = new Collection($calendarRoomPrincipalBackend, 'principals/calendar-rooms');
91
-		$calendarSharingBackend = Server::get(Backend::class);
92
-
93
-		$filesCollection = new Files\RootCollection($userPrincipalBackend, 'principals/users');
94
-		$filesCollection->disableListing = $disableListing;
95
-		$caldavBackend = new CalDavBackend(
96
-			$db,
97
-			$userPrincipalBackend,
98
-			$userManager,
99
-			$random,
100
-			$logger,
101
-			$dispatcher,
102
-			$config,
103
-			$calendarSharingBackend,
104
-			false,
105
-		);
106
-		$userCalendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users', $logger);
107
-		$userCalendarRoot->disableListing = $disableListing;
108
-
109
-		$resourceCalendarRoot = new CalendarRoot($calendarResourcePrincipalBackend, $caldavBackend, 'principals/calendar-resources', $logger);
110
-		$resourceCalendarRoot->disableListing = $disableListing;
111
-		$roomCalendarRoot = new CalendarRoot($calendarRoomPrincipalBackend, $caldavBackend, 'principals/calendar-rooms', $logger);
112
-		$roomCalendarRoot->disableListing = $disableListing;
113
-
114
-		$publicCalendarRoot = new PublicCalendarRoot($caldavBackend, $l10n, $config, $logger);
115
-
116
-		$systemTagCollection = Server::get(SystemTagsByIdCollection::class);
117
-		$systemTagRelationsCollection = new SystemTagsRelationsCollection(
118
-			Server::get(ISystemTagManager::class),
119
-			Server::get(ISystemTagObjectMapper::class),
120
-			Server::get(IUserSession::class),
121
-			$groupManager,
122
-			$dispatcher,
123
-			$rootFolder,
124
-		);
125
-		$systemTagInUseCollection = Server::get(SystemTagsInUseCollection::class);
126
-		$commentsCollection = new Comments\RootCollection(
127
-			Server::get(ICommentsManager::class),
128
-			$userManager,
129
-			Server::get(IUserSession::class),
130
-			$dispatcher,
131
-			$logger
132
-		);
133
-
134
-		$contactsSharingBackend = Server::get(\OCA\DAV\CardDAV\Sharing\Backend::class);
135
-
136
-		$pluginManager = new PluginManager(\OC::$server, Server::get(IAppManager::class));
137
-		$usersCardDavBackend = new CardDavBackend(
138
-			$db,
139
-			$userPrincipalBackend,
140
-			$userManager,
141
-			$dispatcher,
142
-			$contactsSharingBackend,
143
-		);
144
-		$usersAddressBookRoot = new AddressBookRoot($userPrincipalBackend, $usersCardDavBackend, $pluginManager, $userSession->getUser(), $groupManager, 'principals/users');
145
-		$usersAddressBookRoot->disableListing = $disableListing;
146
-
147
-		$systemCardDavBackend = new CardDavBackend(
148
-			$db,
149
-			$userPrincipalBackend,
150
-			$userManager,
151
-			$dispatcher,
152
-			$contactsSharingBackend,
153
-		);
154
-		$systemAddressBookRoot = new AddressBookRoot(new SystemPrincipalBackend(), $systemCardDavBackend, $pluginManager, $userSession->getUser(), $groupManager, 'principals/system');
155
-		$systemAddressBookRoot->disableListing = $disableListing;
156
-
157
-		$uploadCollection = new Upload\RootCollection(
158
-			$userPrincipalBackend,
159
-			'principals/users',
160
-			Server::get(CleanupService::class),
161
-			$rootFolder,
162
-			$userSession,
163
-			$shareManager,
164
-		);
165
-		$uploadCollection->disableListing = $disableListing;
166
-
167
-		$avatarCollection = new Avatars\RootCollection($userPrincipalBackend, 'principals/users');
168
-		$avatarCollection->disableListing = $disableListing;
169
-
170
-		$appleProvisioning = new AppleProvisioningNode(
171
-			Server::get(ITimeFactory::class));
172
-
173
-		$children = [
174
-			new SimpleCollection('principals', [
175
-				$userPrincipals,
176
-				$groupPrincipals,
177
-				$systemPrincipals,
178
-				$calendarResourcePrincipals,
179
-				$calendarRoomPrincipals]),
180
-			$filesCollection,
181
-			$userCalendarRoot,
182
-			new SimpleCollection('system-calendars', [
183
-				$resourceCalendarRoot,
184
-				$roomCalendarRoot,
185
-			]),
186
-			$publicCalendarRoot,
187
-			new SimpleCollection('addressbooks', [
188
-				$usersAddressBookRoot,
189
-				$systemAddressBookRoot]),
190
-			$systemTagCollection,
191
-			$systemTagRelationsCollection,
192
-			$systemTagInUseCollection,
193
-			$commentsCollection,
194
-			$uploadCollection,
195
-			$avatarCollection,
196
-			new SimpleCollection('provisioning', [
197
-				$appleProvisioning
198
-			])
199
-		];
200
-
201
-		parent::__construct('root', $children);
202
-	}
49
+    public function __construct() {
50
+        $l10n = \OC::$server->getL10N('dav');
51
+        $random = Server::get(ISecureRandom::class);
52
+        $logger = Server::get(LoggerInterface::class);
53
+        $userManager = Server::get(IUserManager::class);
54
+        $userSession = Server::get(IUserSession::class);
55
+        $groupManager = Server::get(IGroupManager::class);
56
+        $shareManager = Server::get(\OCP\Share\IManager::class);
57
+        $db = Server::get(IDBConnection::class);
58
+        $dispatcher = Server::get(IEventDispatcher::class);
59
+        $config = Server::get(IConfig::class);
60
+        $proxyMapper = Server::get(ProxyMapper::class);
61
+        $rootFolder = Server::get(IRootFolder::class);
62
+
63
+        $userPrincipalBackend = new Principal(
64
+            $userManager,
65
+            $groupManager,
66
+            Server::get(IAccountManager::class),
67
+            $shareManager,
68
+            Server::get(IUserSession::class),
69
+            Server::get(IAppManager::class),
70
+            $proxyMapper,
71
+            Server::get(KnownUserService::class),
72
+            Server::get(IConfig::class),
73
+            \OC::$server->getL10NFactory()
74
+        );
75
+
76
+        $groupPrincipalBackend = new GroupPrincipalBackend($groupManager, $userSession, $shareManager, $config);
77
+        $calendarResourcePrincipalBackend = new ResourcePrincipalBackend($db, $userSession, $groupManager, $logger, $proxyMapper);
78
+        $calendarRoomPrincipalBackend = new RoomPrincipalBackend($db, $userSession, $groupManager, $logger, $proxyMapper);
79
+        // as soon as debug mode is enabled we allow listing of principals
80
+        $disableListing = !$config->getSystemValue('debug', false);
81
+
82
+        // setup the first level of the dav tree
83
+        $userPrincipals = new Collection($userPrincipalBackend, 'principals/users');
84
+        $userPrincipals->disableListing = $disableListing;
85
+        $groupPrincipals = new Collection($groupPrincipalBackend, 'principals/groups');
86
+        $groupPrincipals->disableListing = $disableListing;
87
+        $systemPrincipals = new Collection(new SystemPrincipalBackend(), 'principals/system');
88
+        $systemPrincipals->disableListing = $disableListing;
89
+        $calendarResourcePrincipals = new Collection($calendarResourcePrincipalBackend, 'principals/calendar-resources');
90
+        $calendarRoomPrincipals = new Collection($calendarRoomPrincipalBackend, 'principals/calendar-rooms');
91
+        $calendarSharingBackend = Server::get(Backend::class);
92
+
93
+        $filesCollection = new Files\RootCollection($userPrincipalBackend, 'principals/users');
94
+        $filesCollection->disableListing = $disableListing;
95
+        $caldavBackend = new CalDavBackend(
96
+            $db,
97
+            $userPrincipalBackend,
98
+            $userManager,
99
+            $random,
100
+            $logger,
101
+            $dispatcher,
102
+            $config,
103
+            $calendarSharingBackend,
104
+            false,
105
+        );
106
+        $userCalendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users', $logger);
107
+        $userCalendarRoot->disableListing = $disableListing;
108
+
109
+        $resourceCalendarRoot = new CalendarRoot($calendarResourcePrincipalBackend, $caldavBackend, 'principals/calendar-resources', $logger);
110
+        $resourceCalendarRoot->disableListing = $disableListing;
111
+        $roomCalendarRoot = new CalendarRoot($calendarRoomPrincipalBackend, $caldavBackend, 'principals/calendar-rooms', $logger);
112
+        $roomCalendarRoot->disableListing = $disableListing;
113
+
114
+        $publicCalendarRoot = new PublicCalendarRoot($caldavBackend, $l10n, $config, $logger);
115
+
116
+        $systemTagCollection = Server::get(SystemTagsByIdCollection::class);
117
+        $systemTagRelationsCollection = new SystemTagsRelationsCollection(
118
+            Server::get(ISystemTagManager::class),
119
+            Server::get(ISystemTagObjectMapper::class),
120
+            Server::get(IUserSession::class),
121
+            $groupManager,
122
+            $dispatcher,
123
+            $rootFolder,
124
+        );
125
+        $systemTagInUseCollection = Server::get(SystemTagsInUseCollection::class);
126
+        $commentsCollection = new Comments\RootCollection(
127
+            Server::get(ICommentsManager::class),
128
+            $userManager,
129
+            Server::get(IUserSession::class),
130
+            $dispatcher,
131
+            $logger
132
+        );
133
+
134
+        $contactsSharingBackend = Server::get(\OCA\DAV\CardDAV\Sharing\Backend::class);
135
+
136
+        $pluginManager = new PluginManager(\OC::$server, Server::get(IAppManager::class));
137
+        $usersCardDavBackend = new CardDavBackend(
138
+            $db,
139
+            $userPrincipalBackend,
140
+            $userManager,
141
+            $dispatcher,
142
+            $contactsSharingBackend,
143
+        );
144
+        $usersAddressBookRoot = new AddressBookRoot($userPrincipalBackend, $usersCardDavBackend, $pluginManager, $userSession->getUser(), $groupManager, 'principals/users');
145
+        $usersAddressBookRoot->disableListing = $disableListing;
146
+
147
+        $systemCardDavBackend = new CardDavBackend(
148
+            $db,
149
+            $userPrincipalBackend,
150
+            $userManager,
151
+            $dispatcher,
152
+            $contactsSharingBackend,
153
+        );
154
+        $systemAddressBookRoot = new AddressBookRoot(new SystemPrincipalBackend(), $systemCardDavBackend, $pluginManager, $userSession->getUser(), $groupManager, 'principals/system');
155
+        $systemAddressBookRoot->disableListing = $disableListing;
156
+
157
+        $uploadCollection = new Upload\RootCollection(
158
+            $userPrincipalBackend,
159
+            'principals/users',
160
+            Server::get(CleanupService::class),
161
+            $rootFolder,
162
+            $userSession,
163
+            $shareManager,
164
+        );
165
+        $uploadCollection->disableListing = $disableListing;
166
+
167
+        $avatarCollection = new Avatars\RootCollection($userPrincipalBackend, 'principals/users');
168
+        $avatarCollection->disableListing = $disableListing;
169
+
170
+        $appleProvisioning = new AppleProvisioningNode(
171
+            Server::get(ITimeFactory::class));
172
+
173
+        $children = [
174
+            new SimpleCollection('principals', [
175
+                $userPrincipals,
176
+                $groupPrincipals,
177
+                $systemPrincipals,
178
+                $calendarResourcePrincipals,
179
+                $calendarRoomPrincipals]),
180
+            $filesCollection,
181
+            $userCalendarRoot,
182
+            new SimpleCollection('system-calendars', [
183
+                $resourceCalendarRoot,
184
+                $roomCalendarRoot,
185
+            ]),
186
+            $publicCalendarRoot,
187
+            new SimpleCollection('addressbooks', [
188
+                $usersAddressBookRoot,
189
+                $systemAddressBookRoot]),
190
+            $systemTagCollection,
191
+            $systemTagRelationsCollection,
192
+            $systemTagInUseCollection,
193
+            $commentsCollection,
194
+            $uploadCollection,
195
+            $avatarCollection,
196
+            new SimpleCollection('provisioning', [
197
+                $appleProvisioning
198
+            ])
199
+        ];
200
+
201
+        parent::__construct('root', $children);
202
+    }
203 203
 }
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/ServerFactory.php 1 patch
Indentation   +196 added lines, -196 removed lines patch added patch discarded remove patch
@@ -43,200 +43,200 @@
 block discarded – undo
43 43
 
44 44
 class ServerFactory {
45 45
 
46
-	public function __construct(
47
-		private IConfig $config,
48
-		private LoggerInterface $logger,
49
-		private IDBConnection $databaseConnection,
50
-		private IUserSession $userSession,
51
-		private IMountManager $mountManager,
52
-		private ITagManager $tagManager,
53
-		private IRequest $request,
54
-		private IPreview $previewManager,
55
-		private IEventDispatcher $eventDispatcher,
56
-		private IL10N $l10n,
57
-	) {
58
-	}
59
-
60
-	/**
61
-	 * @param callable $viewCallBack callback that should return the view for the dav endpoint
62
-	 */
63
-	public function createServer(
64
-		bool $isPublicShare,
65
-		string $baseUri,
66
-		string $requestUri,
67
-		Plugin $authPlugin,
68
-		callable $viewCallBack,
69
-	): Server {
70
-		// Fire up server
71
-		if ($isPublicShare) {
72
-			$rootCollection = new SimpleCollection('root');
73
-			$tree = new CachingTree($rootCollection);
74
-		} else {
75
-			$rootCollection = null;
76
-			$tree = new ObjectTree();
77
-		}
78
-		$server = new Server($tree);
79
-		// Set URL explicitly due to reverse-proxy situations
80
-		$server->httpRequest->setUrl($requestUri);
81
-		$server->setBaseUri($baseUri);
82
-
83
-		// Load plugins
84
-		$server->addPlugin(new MaintenancePlugin($this->config, $this->l10n));
85
-		$server->addPlugin(new BlockLegacyClientPlugin(
86
-			$this->config,
87
-			\OCP\Server::get(ThemingDefaults::class),
88
-		));
89
-		$server->addPlugin(new AnonymousOptionsPlugin());
90
-		$server->addPlugin($authPlugin);
91
-		// FIXME: The following line is a workaround for legacy components relying on being able to send a GET to /
92
-		$server->addPlugin(new DummyGetResponsePlugin());
93
-		$server->addPlugin(new ExceptionLoggerPlugin('webdav', $this->logger));
94
-		$server->addPlugin(new LockPlugin());
95
-
96
-		$server->addPlugin(new RequestIdHeaderPlugin($this->request));
97
-
98
-		$server->addPlugin(new ZipFolderPlugin(
99
-			$tree,
100
-			$this->logger,
101
-			$this->eventDispatcher,
102
-		));
103
-
104
-		// Some WebDAV clients do require Class 2 WebDAV support (locking), since
105
-		// we do not provide locking we emulate it using a fake locking plugin.
106
-		if ($this->request->isUserAgent([
107
-			'/WebDAVFS/',
108
-			'/OneNote/',
109
-			'/Microsoft-WebDAV-MiniRedir/',
110
-		])) {
111
-			$server->addPlugin(new FakeLockerPlugin());
112
-		}
113
-
114
-		if (BrowserErrorPagePlugin::isBrowserRequest($this->request)) {
115
-			$server->addPlugin(new BrowserErrorPagePlugin());
116
-		}
117
-
118
-		// wait with registering these until auth is handled and the filesystem is setup
119
-		$server->on('beforeMethod:*', function () use ($server, $tree, $viewCallBack, $isPublicShare, $rootCollection): void {
120
-			// ensure the skeleton is copied
121
-			$userFolder = \OC::$server->getUserFolder();
122
-
123
-			/** @var View $view */
124
-			$view = $viewCallBack($server);
125
-			if ($userFolder instanceof Folder && $userFolder->getPath() === $view->getRoot()) {
126
-				$rootInfo = $userFolder;
127
-			} else {
128
-				$rootInfo = $view->getFileInfo('');
129
-			}
130
-
131
-			// Create Nextcloud Dir
132
-			if ($rootInfo->getType() === 'dir') {
133
-				$root = new Directory($view, $rootInfo, $tree);
134
-			} else {
135
-				$root = new File($view, $rootInfo);
136
-			}
137
-
138
-			if ($isPublicShare) {
139
-				$userPrincipalBackend = new Principal(
140
-					\OCP\Server::get(IUserManager::class),
141
-					\OCP\Server::get(IGroupManager::class),
142
-					\OCP\Server::get(IAccountManager::class),
143
-					\OCP\Server::get(\OCP\Share\IManager::class),
144
-					\OCP\Server::get(IUserSession::class),
145
-					\OCP\Server::get(IAppManager::class),
146
-					\OCP\Server::get(ProxyMapper::class),
147
-					\OCP\Server::get(KnownUserService::class),
148
-					\OCP\Server::get(IConfig::class),
149
-					\OC::$server->getL10NFactory(),
150
-				);
151
-
152
-				// Mount the share collection at /public.php/dav/shares/<share token>
153
-				$rootCollection->addChild(new \OCA\DAV\Files\Sharing\RootCollection(
154
-					$root,
155
-					$userPrincipalBackend,
156
-					'principals/shares',
157
-				));
158
-
159
-				// Mount the upload collection at /public.php/dav/uploads/<share token>
160
-				$rootCollection->addChild(new \OCA\DAV\Upload\RootCollection(
161
-					$userPrincipalBackend,
162
-					'principals/shares',
163
-					\OCP\Server::get(CleanupService::class),
164
-					\OCP\Server::get(IRootFolder::class),
165
-					\OCP\Server::get(IUserSession::class),
166
-					\OCP\Server::get(\OCP\Share\IManager::class),
167
-				));
168
-			} else {
169
-				/** @var ObjectTree $tree */
170
-				$tree->init($root, $view, $this->mountManager);
171
-			}
172
-
173
-			$server->addPlugin(
174
-				new FilesPlugin(
175
-					$tree,
176
-					$this->config,
177
-					$this->request,
178
-					$this->previewManager,
179
-					$this->userSession,
180
-					\OCP\Server::get(IFilenameValidator::class),
181
-					\OCP\Server::get(IAccountManager::class),
182
-					false,
183
-					!$this->config->getSystemValue('debug', false)
184
-				)
185
-			);
186
-			$server->addPlugin(new QuotaPlugin($view, true));
187
-			$server->addPlugin(new ChecksumUpdatePlugin());
188
-
189
-			// Allow view-only plugin for webdav requests
190
-			$server->addPlugin(new ViewOnlyPlugin(
191
-				$userFolder,
192
-			));
193
-
194
-			if ($this->userSession->isLoggedIn()) {
195
-				$server->addPlugin(new TagsPlugin($tree, $this->tagManager, $this->eventDispatcher, $this->userSession));
196
-				$server->addPlugin(new SharesPlugin(
197
-					$tree,
198
-					$this->userSession,
199
-					$userFolder,
200
-					\OCP\Server::get(\OCP\Share\IManager::class)
201
-				));
202
-				$server->addPlugin(new CommentPropertiesPlugin(\OCP\Server::get(ICommentsManager::class), $this->userSession));
203
-				$server->addPlugin(new FilesReportPlugin(
204
-					$tree,
205
-					$view,
206
-					\OCP\Server::get(ISystemTagManager::class),
207
-					\OCP\Server::get(ISystemTagObjectMapper::class),
208
-					\OCP\Server::get(ITagManager::class),
209
-					$this->userSession,
210
-					\OCP\Server::get(IGroupManager::class),
211
-					$userFolder,
212
-					\OCP\Server::get(IAppManager::class)
213
-				));
214
-				// custom properties plugin must be the last one
215
-				$server->addPlugin(
216
-					new \Sabre\DAV\PropertyStorage\Plugin(
217
-						new CustomPropertiesBackend(
218
-							$server,
219
-							$tree,
220
-							$this->databaseConnection,
221
-							$this->userSession->getUser(),
222
-							\OCP\Server::get(DefaultCalendarValidator::class),
223
-						)
224
-					)
225
-				);
226
-			}
227
-			$server->addPlugin(new CopyEtagHeaderPlugin());
228
-
229
-			// Load dav plugins from apps
230
-			$event = new SabrePluginEvent($server);
231
-			$this->eventDispatcher->dispatchTyped($event);
232
-			$pluginManager = new PluginManager(
233
-				\OC::$server,
234
-				\OCP\Server::get(IAppManager::class)
235
-			);
236
-			foreach ($pluginManager->getAppPlugins() as $appPlugin) {
237
-				$server->addPlugin($appPlugin);
238
-			}
239
-		}, 30); // priority 30: after auth (10) and acl(20), before lock(50) and handling the request
240
-		return $server;
241
-	}
46
+    public function __construct(
47
+        private IConfig $config,
48
+        private LoggerInterface $logger,
49
+        private IDBConnection $databaseConnection,
50
+        private IUserSession $userSession,
51
+        private IMountManager $mountManager,
52
+        private ITagManager $tagManager,
53
+        private IRequest $request,
54
+        private IPreview $previewManager,
55
+        private IEventDispatcher $eventDispatcher,
56
+        private IL10N $l10n,
57
+    ) {
58
+    }
59
+
60
+    /**
61
+     * @param callable $viewCallBack callback that should return the view for the dav endpoint
62
+     */
63
+    public function createServer(
64
+        bool $isPublicShare,
65
+        string $baseUri,
66
+        string $requestUri,
67
+        Plugin $authPlugin,
68
+        callable $viewCallBack,
69
+    ): Server {
70
+        // Fire up server
71
+        if ($isPublicShare) {
72
+            $rootCollection = new SimpleCollection('root');
73
+            $tree = new CachingTree($rootCollection);
74
+        } else {
75
+            $rootCollection = null;
76
+            $tree = new ObjectTree();
77
+        }
78
+        $server = new Server($tree);
79
+        // Set URL explicitly due to reverse-proxy situations
80
+        $server->httpRequest->setUrl($requestUri);
81
+        $server->setBaseUri($baseUri);
82
+
83
+        // Load plugins
84
+        $server->addPlugin(new MaintenancePlugin($this->config, $this->l10n));
85
+        $server->addPlugin(new BlockLegacyClientPlugin(
86
+            $this->config,
87
+            \OCP\Server::get(ThemingDefaults::class),
88
+        ));
89
+        $server->addPlugin(new AnonymousOptionsPlugin());
90
+        $server->addPlugin($authPlugin);
91
+        // FIXME: The following line is a workaround for legacy components relying on being able to send a GET to /
92
+        $server->addPlugin(new DummyGetResponsePlugin());
93
+        $server->addPlugin(new ExceptionLoggerPlugin('webdav', $this->logger));
94
+        $server->addPlugin(new LockPlugin());
95
+
96
+        $server->addPlugin(new RequestIdHeaderPlugin($this->request));
97
+
98
+        $server->addPlugin(new ZipFolderPlugin(
99
+            $tree,
100
+            $this->logger,
101
+            $this->eventDispatcher,
102
+        ));
103
+
104
+        // Some WebDAV clients do require Class 2 WebDAV support (locking), since
105
+        // we do not provide locking we emulate it using a fake locking plugin.
106
+        if ($this->request->isUserAgent([
107
+            '/WebDAVFS/',
108
+            '/OneNote/',
109
+            '/Microsoft-WebDAV-MiniRedir/',
110
+        ])) {
111
+            $server->addPlugin(new FakeLockerPlugin());
112
+        }
113
+
114
+        if (BrowserErrorPagePlugin::isBrowserRequest($this->request)) {
115
+            $server->addPlugin(new BrowserErrorPagePlugin());
116
+        }
117
+
118
+        // wait with registering these until auth is handled and the filesystem is setup
119
+        $server->on('beforeMethod:*', function () use ($server, $tree, $viewCallBack, $isPublicShare, $rootCollection): void {
120
+            // ensure the skeleton is copied
121
+            $userFolder = \OC::$server->getUserFolder();
122
+
123
+            /** @var View $view */
124
+            $view = $viewCallBack($server);
125
+            if ($userFolder instanceof Folder && $userFolder->getPath() === $view->getRoot()) {
126
+                $rootInfo = $userFolder;
127
+            } else {
128
+                $rootInfo = $view->getFileInfo('');
129
+            }
130
+
131
+            // Create Nextcloud Dir
132
+            if ($rootInfo->getType() === 'dir') {
133
+                $root = new Directory($view, $rootInfo, $tree);
134
+            } else {
135
+                $root = new File($view, $rootInfo);
136
+            }
137
+
138
+            if ($isPublicShare) {
139
+                $userPrincipalBackend = new Principal(
140
+                    \OCP\Server::get(IUserManager::class),
141
+                    \OCP\Server::get(IGroupManager::class),
142
+                    \OCP\Server::get(IAccountManager::class),
143
+                    \OCP\Server::get(\OCP\Share\IManager::class),
144
+                    \OCP\Server::get(IUserSession::class),
145
+                    \OCP\Server::get(IAppManager::class),
146
+                    \OCP\Server::get(ProxyMapper::class),
147
+                    \OCP\Server::get(KnownUserService::class),
148
+                    \OCP\Server::get(IConfig::class),
149
+                    \OC::$server->getL10NFactory(),
150
+                );
151
+
152
+                // Mount the share collection at /public.php/dav/shares/<share token>
153
+                $rootCollection->addChild(new \OCA\DAV\Files\Sharing\RootCollection(
154
+                    $root,
155
+                    $userPrincipalBackend,
156
+                    'principals/shares',
157
+                ));
158
+
159
+                // Mount the upload collection at /public.php/dav/uploads/<share token>
160
+                $rootCollection->addChild(new \OCA\DAV\Upload\RootCollection(
161
+                    $userPrincipalBackend,
162
+                    'principals/shares',
163
+                    \OCP\Server::get(CleanupService::class),
164
+                    \OCP\Server::get(IRootFolder::class),
165
+                    \OCP\Server::get(IUserSession::class),
166
+                    \OCP\Server::get(\OCP\Share\IManager::class),
167
+                ));
168
+            } else {
169
+                /** @var ObjectTree $tree */
170
+                $tree->init($root, $view, $this->mountManager);
171
+            }
172
+
173
+            $server->addPlugin(
174
+                new FilesPlugin(
175
+                    $tree,
176
+                    $this->config,
177
+                    $this->request,
178
+                    $this->previewManager,
179
+                    $this->userSession,
180
+                    \OCP\Server::get(IFilenameValidator::class),
181
+                    \OCP\Server::get(IAccountManager::class),
182
+                    false,
183
+                    !$this->config->getSystemValue('debug', false)
184
+                )
185
+            );
186
+            $server->addPlugin(new QuotaPlugin($view, true));
187
+            $server->addPlugin(new ChecksumUpdatePlugin());
188
+
189
+            // Allow view-only plugin for webdav requests
190
+            $server->addPlugin(new ViewOnlyPlugin(
191
+                $userFolder,
192
+            ));
193
+
194
+            if ($this->userSession->isLoggedIn()) {
195
+                $server->addPlugin(new TagsPlugin($tree, $this->tagManager, $this->eventDispatcher, $this->userSession));
196
+                $server->addPlugin(new SharesPlugin(
197
+                    $tree,
198
+                    $this->userSession,
199
+                    $userFolder,
200
+                    \OCP\Server::get(\OCP\Share\IManager::class)
201
+                ));
202
+                $server->addPlugin(new CommentPropertiesPlugin(\OCP\Server::get(ICommentsManager::class), $this->userSession));
203
+                $server->addPlugin(new FilesReportPlugin(
204
+                    $tree,
205
+                    $view,
206
+                    \OCP\Server::get(ISystemTagManager::class),
207
+                    \OCP\Server::get(ISystemTagObjectMapper::class),
208
+                    \OCP\Server::get(ITagManager::class),
209
+                    $this->userSession,
210
+                    \OCP\Server::get(IGroupManager::class),
211
+                    $userFolder,
212
+                    \OCP\Server::get(IAppManager::class)
213
+                ));
214
+                // custom properties plugin must be the last one
215
+                $server->addPlugin(
216
+                    new \Sabre\DAV\PropertyStorage\Plugin(
217
+                        new CustomPropertiesBackend(
218
+                            $server,
219
+                            $tree,
220
+                            $this->databaseConnection,
221
+                            $this->userSession->getUser(),
222
+                            \OCP\Server::get(DefaultCalendarValidator::class),
223
+                        )
224
+                    )
225
+                );
226
+            }
227
+            $server->addPlugin(new CopyEtagHeaderPlugin());
228
+
229
+            // Load dav plugins from apps
230
+            $event = new SabrePluginEvent($server);
231
+            $this->eventDispatcher->dispatchTyped($event);
232
+            $pluginManager = new PluginManager(
233
+                \OC::$server,
234
+                \OCP\Server::get(IAppManager::class)
235
+            );
236
+            foreach ($pluginManager->getAppPlugins() as $appPlugin) {
237
+                $server->addPlugin($appPlugin);
238
+            }
239
+        }, 30); // priority 30: after auth (10) and acl(20), before lock(50) and handling the request
240
+        return $server;
241
+    }
242 242
 }
Please login to merge, or discard this patch.