Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion js/editor.js.map

Large diffs are not rendered by default.

31 changes: 24 additions & 7 deletions lib/Service/ImageService.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

use Exception;
use OCA\Text\Controller\ImageController;
use OCA\Files_Sharing\SharedStorage;
use OCP\Constants;
use OCP\Files\Folder;
use OCP\Files\File;
Expand Down Expand Up @@ -328,13 +329,27 @@ private function getFileFromPath(string $filePath, string $userId): ?File {
$userFolder = $this->rootFolder->getUserFolder($userId);
if ($userFolder->nodeExists($filePath)) {
$file = $userFolder->get($filePath);
if ($file instanceof File) {
if ($file instanceof File && !$this->isDownloadDisabled($file)) {
return $file;
}
}
return null;
}

private function isDownloadDisabled(File $file): bool {
$storage = $file->getStorage();
if ($storage->instanceOfStorage(SharedStorage::class)) {
/** @var SharedStorage $storage */
$share = $storage->getShare();
$attributes = $share->getAttributes();
if ($attributes !== null && $attributes->getAttribute('permissions', 'download') === false) {
return true;
}
}

return false;
}

/**
* Get a user file from file ID
*
Expand All @@ -347,9 +362,10 @@ private function getFileFromPath(string $filePath, string $userId): ?File {
*/
private function getTextFile(int $documentId, string $userId): File {
$userFolder = $this->rootFolder->getUserFolder($userId);
$textFile = $userFolder->getById($documentId);
if (count($textFile) > 0 && $textFile[0] instanceof File) {
return $textFile[0];
$files = $userFolder->getById($documentId);
$file = array_shift($files);
if ($file instanceof File && !$this->isDownloadDisabled($file)) {
return $file;
}
throw new NotFoundException('Text file with id=' . $documentId . ' was not found in storage of ' . $userId);
}
Expand All @@ -370,15 +386,16 @@ private function getTextFilePublic(?int $documentId, string $shareToken): File {
// shared file or folder?
if ($share->getNodeType() === 'file') {
$textFile = $share->getNode();
if ($textFile instanceof File) {
if ($textFile instanceof File && !$this->isDownloadDisabled($textFile)) {
return $textFile;
}
} elseif ($documentId !== null && $share->getNodeType() === 'folder') {
$folder = $share->getNode();
if ($folder instanceof Folder) {
$textFile = $folder->getById($documentId);
if (count($textFile) > 0 && $textFile[0] instanceof File) {
return $textFile[0];
$textFile = array_shift($textFile);
if ($textFile instanceof File && !$this->isDownloadDisabled($textFile)) {
return $textFile;
}
}
}
Expand Down