Skip to content

Commit e089475

Browse files
committed
fix: attachment visibility for authenticated users via shared links
Signed-off-by: ailkiv <a.ilkiv.ye@gmail.com>
1 parent be3ff42 commit e089475

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

lib/Middleware/SessionMiddleware.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,14 @@ private function assertDocumentSession(ISessionAwareController $controller): voi
123123
private function assertUserOrShareToken(ISessionAwareController $controller): void {
124124
$documentId = (int)$this->request->getParam('documentId');
125125
if (null !== $userId = $this->userSession->getUser()?->getUID()) {
126-
// Check if user has access to document
127-
if ($this->rootFolder->getUserFolder($userId)->getFirstNodeById($documentId) === null) {
128-
throw new InvalidSessionException();
126+
if ($this->rootFolder->getUserFolder($userId)->getFirstNodeById($documentId) !== null) {
127+
$controller->setUserId($userId);
128+
$controller->setDocumentId($documentId);
129+
return;
129130
}
130-
$controller->setUserId($userId);
131-
} elseif ('' !== $shareToken = (string)$this->request->getParam('shareToken')) {
131+
}
132+
133+
if ('' !== $shareToken = (string)$this->request->getParam('shareToken')) {
132134
try {
133135
$share = $this->shareManager->getShareByToken($shareToken);
134136
} catch (ShareNotFound) {
@@ -155,11 +157,12 @@ private function assertUserOrShareToken(ISessionAwareController $controller): vo
155157
if ($attributes !== null && $attributes->getAttribute('permissions', 'download') === false) {
156158
throw new InvalidSessionException();
157159
}
158-
} else {
159-
throw new InvalidSessionException();
160+
161+
$controller->setDocumentId($documentId);
162+
return;
160163
}
161164

162-
$controller->setDocumentId($documentId);
165+
throw new InvalidSessionException();
163166
}
164167

165168
public function afterException($controller, $methodName, \Exception $exception): JSONResponse|Response {

0 commit comments

Comments
 (0)