Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(share): allow opening attachments
Provide relative path to attachments in public shares.

The path needs to be relative to the shared folder.

Open attachments in public collective shares
as well as in folder descriptions of public shares.

Signed-off-by: Max <[email protected]>
  • Loading branch information
max-nextcloud committed Jul 28, 2025
commit 6bcb0cde4758759bd845a1062dcc7805c2db4594
37 changes: 35 additions & 2 deletions lib/Service/AttachmentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,11 @@ public function getAttachmentList(int $documentId, ?string $userId = null, ?Sess
: '?documentId=' . $documentId . $shareTokenUrlString;

$attachments = [];
$userFolder = $userId !== null ? $this->rootFolder->getUserFolder($userId) : null;

// Folder davPath need to be relative to.
$davFolder = $userId !== null
? $this->rootFolder->getUserFolder($userId)
: $this->getShareFolder($shareToken);

$fileNodes = [];
$fileIds = [];
Expand All @@ -247,7 +251,7 @@ public function getAttachmentList(int $documentId, ?string $userId = null, ?Sess
'mimetype' => $node->getMimeType(),
'mtime' => $node->getMTime(),
'isImage' => $isImage,
'davPath' => $userFolder?->getRelativePath($node->getPath()),
'davPath' => $davFolder?->getRelativePath($node->getPath()),
'metadata' => $metadata,
'fullUrl' => $isImage
? $this->urlGenerator->linkToRouteAbsolute('text.Attachment.getImageFile') . $urlParamsBase . '&imageFileName=' . rawurlencode($name) . '&preferRawImage=1'
Expand Down Expand Up @@ -574,6 +578,35 @@ private function getTextFilePublic(?int $documentId, string $shareToken): File {
throw new NotFoundException('Text file with id=' . $documentId . ' and shareToken ' . $shareToken . ' was not found.');
}

/**
* Get share folder
*
* @param string $shareToken
*
* @throws NotFoundException
*/
private function getShareFolder(string $shareToken): ?Folder {
// is the file shared with this token?
try {
$share = $this->shareManager->getShareByToken($shareToken);
if (in_array($share->getShareType(), [IShare::TYPE_LINK, IShare::TYPE_EMAIL])) {
// shared file or folder?
if ($share->getNodeType() === 'file') {
return null;
} elseif ($share->getNodeType() === 'folder') {
$folder = $share->getNode();
if ($folder instanceof Folder) {
return $folder;
}
throw new NotFoundException('Share folder for ' . $shareToken . ' was not a folder.');
}
}
} catch (ShareNotFound $e) {
// same as below
}
throw new NotFoundException('Share folder for ' . $shareToken . ' was not found.');
}

/**
* Actually delete attachment files which are not pointed in the markdown content
*
Expand Down