Skip to content

Commit c9955f2

Browse files
committed
feat: also send x-user-id for dav responses
Signed-off-by: Robin Appelman <[email protected]>
1 parent 3f2e420 commit c9955f2

File tree

5 files changed

+42
-1
lines changed

5 files changed

+42
-1
lines changed

apps/dav/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@
218218
'OCA\\DAV\\Connector\\Sabre\\SharesPlugin' => $baseDir . '/../lib/Connector/Sabre/SharesPlugin.php',
219219
'OCA\\DAV\\Connector\\Sabre\\TagList' => $baseDir . '/../lib/Connector/Sabre/TagList.php',
220220
'OCA\\DAV\\Connector\\Sabre\\TagsPlugin' => $baseDir . '/../lib/Connector/Sabre/TagsPlugin.php',
221+
'OCA\\DAV\\Connector\\Sabre\\UserIdHeaderPlugin' => $baseDir . '/../lib/Connector/Sabre/UserIdHeaderPlugin.php',
221222
'OCA\\DAV\\Controller\\BirthdayCalendarController' => $baseDir . '/../lib/Controller/BirthdayCalendarController.php',
222223
'OCA\\DAV\\Controller\\DirectController' => $baseDir . '/../lib/Controller/DirectController.php',
223224
'OCA\\DAV\\Controller\\InvitationResponseController' => $baseDir . '/../lib/Controller/InvitationResponseController.php',

apps/dav/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ class ComposerStaticInitDAV
233233
'OCA\\DAV\\Connector\\Sabre\\SharesPlugin' => __DIR__ . '/..' . '/../lib/Connector/Sabre/SharesPlugin.php',
234234
'OCA\\DAV\\Connector\\Sabre\\TagList' => __DIR__ . '/..' . '/../lib/Connector/Sabre/TagList.php',
235235
'OCA\\DAV\\Connector\\Sabre\\TagsPlugin' => __DIR__ . '/..' . '/../lib/Connector/Sabre/TagsPlugin.php',
236+
'OCA\\DAV\\Connector\\Sabre\\UserIdHeaderPlugin' => __DIR__ . '/..' . '/../lib/Connector/Sabre/UserIdHeaderPlugin.php',
236237
'OCA\\DAV\\Controller\\BirthdayCalendarController' => __DIR__ . '/..' . '/../lib/Controller/BirthdayCalendarController.php',
237238
'OCA\\DAV\\Controller\\DirectController' => __DIR__ . '/..' . '/../lib/Controller/DirectController.php',
238239
'OCA\\DAV\\Controller\\InvitationResponseController' => __DIR__ . '/..' . '/../lib/Controller/InvitationResponseController.php',

apps/dav/lib/Connector/Sabre/ServerFactory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ public function createServer(string $baseUri,
8888
$server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $this->logger));
8989
$server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin());
9090

91-
$server->addPlugin(new RequestIdHeaderPlugin(\OC::$server->get(IRequest::class)));
91+
$server->addPlugin(new RequestIdHeaderPlugin($this->request));
92+
$server->addPlugin(new UserIdHeaderPlugin($this->userSession));
9293

9394
// Some WebDAV clients do require Class 2 WebDAV support (locking), since
9495
// we do not provide locking we emulate it using a fake locking plugin.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
6+
* SPDX-License-Identifier: AGPL-3.0-or-later
7+
*/
8+
9+
namespace OCA\DAV\Connector\Sabre;
10+
11+
use OCP\IUserSession;
12+
use Sabre\HTTP\RequestInterface;
13+
use Sabre\HTTP\ResponseInterface;
14+
15+
class UserIdHeaderPlugin extends \Sabre\DAV\ServerPlugin {
16+
public function __construct(
17+
private readonly IUserSession $userSession,
18+
) {
19+
}
20+
21+
public function initialize(\Sabre\DAV\Server $server): void {
22+
$server->on('afterMethod:*', [$this, 'afterMethod']);
23+
}
24+
25+
/**
26+
* Add the request id as a header in the response
27+
*
28+
* @param RequestInterface $request request
29+
* @param ResponseInterface $response response
30+
*/
31+
public function afterMethod(RequestInterface $request, ResponseInterface $response): void {
32+
if ($user = $this->userSession->getUser()) {
33+
$response->setHeader('X-User-Id', $user->getUID());
34+
}
35+
}
36+
}

apps/dav/lib/Server.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
use OCA\DAV\Connector\Sabre\RequestIdHeaderPlugin;
4141
use OCA\DAV\Connector\Sabre\SharesPlugin;
4242
use OCA\DAV\Connector\Sabre\TagsPlugin;
43+
use OCA\DAV\Connector\Sabre\UserIdHeaderPlugin;
4344
use OCA\DAV\DAV\CustomPropertiesBackend;
4445
use OCA\DAV\DAV\PublicAuth;
4546
use OCA\DAV\DAV\ViewOnlyPlugin;
@@ -208,6 +209,7 @@ public function __construct(IRequest $request, string $baseUri) {
208209

209210
$this->server->addPlugin(new CopyEtagHeaderPlugin());
210211
$this->server->addPlugin(new RequestIdHeaderPlugin(\OC::$server->get(IRequest::class)));
212+
$this->server->addPlugin(new UserIdHeaderPlugin(\OCP\Server::get(IUserSession::class)));
211213
$this->server->addPlugin(new ChunkingV2Plugin(\OCP\Server::get(ICacheFactory::class)));
212214
$this->server->addPlugin(new ChunkingPlugin());
213215

0 commit comments

Comments
 (0)