Merge pull request #58144 from nextcloud/fix/more-missing-userid-cases

fix: add missing `X-User-Id` in DAV uploads and index redirect
This commit is contained in:
Salvatore Martire 2026-02-19 15:27:06 +01:00 committed by GitHub
commit 238e459032
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 3 deletions

View file

@ -19,7 +19,7 @@ class UserIdHeaderPlugin extends \Sabre\DAV\ServerPlugin {
}
public function initialize(\Sabre\DAV\Server $server): void {
$server->on('afterMethod:*', [$this, 'afterMethod']);
$server->on('beforeMethod:*', [$this, 'beforeMethod']);
}
/**
@ -28,7 +28,7 @@ class UserIdHeaderPlugin extends \Sabre\DAV\ServerPlugin {
* @param RequestInterface $request request
* @param ResponseInterface $response response
*/
public function afterMethod(RequestInterface $request, ResponseInterface $response): void {
public function beforeMethod(RequestInterface $request, ResponseInterface $response): void {
if ($user = $this->userSession->getUser()) {
$response->setHeader('X-User-Id', $user->getUID());
}

View file

@ -1190,7 +1190,9 @@ class OC {
// Redirect to the default app or login only as an entry point
if ($requestPath === '') {
// Someone is logged in
if (Server::get(IUserSession::class)->isLoggedIn()) {
$userSession = Server::get(IUserSession::class);
if ($userSession->isLoggedIn()) {
header('X-User-Id: ' . $userSession->getUser()?->getUID());
header('Location: ' . Server::get(IURLGenerator::class)->linkToDefaultPageUrl());
} else {
// Not handled and not logged in