Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable25] fix: Fetch attachment share permissions #4489

Merged
merged 4 commits into from
Jul 12, 2023
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 .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
# cypress will install dependencies

- name: Set up php ${{ matrix.php-versions }}
uses: shivammathur/setup-php@v2
uses: shivammathur/setup-php@4bd44f22a98a19e0950cbad5f31095157cc9621b # 2.25.4
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring, iconv, fileinfo, intl, sqlite, pdo_sqlite, zip, gd, apcu
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
path: apps/${{ env.APP_NAME }}

- name: Set up php ${{ matrix.php-versions }}
uses: shivammathur/setup-php@v2
uses: shivammathur/setup-php@4bd44f22a98a19e0950cbad5f31095157cc9621b # 2.25.4
with:
php-version: ${{ matrix.php-versions }}
tools: phpunit:9
Expand Down Expand Up @@ -97,11 +97,11 @@ jobs:
path: apps/${{ env.APP_NAME }}

- name: Set up php ${{ matrix.php-versions }}
uses: shivammathur/setup-php@v2
uses: shivammathur/setup-php@4bd44f22a98a19e0950cbad5f31095157cc9621b # 2.25.4
with:
php-version: ${{ matrix.php-versions }}
tools: phpunit:9
extensions: mbstring, iconv, fileinfo, intl, oci8
extensions: mbstring, iconv, fileinfo, intl, oci8, gd
coverage: none

- name: Set up PHPUnit
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/psalm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
uses: actions/checkout@v3

- name: Set up php
uses: shivammathur/setup-php@v2
uses: shivammathur/setup-php@4bd44f22a98a19e0950cbad5f31095157cc9621b # 2.25.4
with:
php-version: 7.4
coverage: none
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/update-nextcloud-ocp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
submodules: true

- name: Set up php7.4
uses: shivammathur/setup-php@v2
uses: shivammathur/setup-php@4bd44f22a98a19e0950cbad5f31095157cc9621b # 2.25.4
with:
php-version: 7.4
extensions: ctype,curl,dom,fileinfo,gd,intl,json,mbstring,openssl,pdo_sqlite,posix,sqlite,xml,zip
Expand Down
2 changes: 1 addition & 1 deletion js/editor.js.map

Large diffs are not rendered by default.

35 changes: 26 additions & 9 deletions lib/Service/AttachmentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

namespace OCA\Text\Service;

use OCA\Files_Sharing\SharedStorage;
use OCA\Text\Controller\AttachmentController;
use OCP\Constants;
use OCP\Files\Folder;
Expand Down Expand Up @@ -165,7 +166,7 @@ public function getMediaFilePublic(int $documentId, string $mediaFileName, strin
private function getMediaFullFile(string $mediaFileName, File $textFile): ?File {
$attachmentFolder = $this->getAttachmentDirectoryForFile($textFile, true);
$mediaFile = $attachmentFolder->get($mediaFileName);
if ($mediaFile instanceof File) {
if ($mediaFile instanceof File && !$this->isDownloadDisabled($mediaFile)) {
return $mediaFile;
}
return null;
Expand Down Expand Up @@ -213,7 +214,7 @@ public function getMediaFilePreviewPublic(int $documentId, string $mediaFileName
private function getMediaFilePreviewFile(string $mediaFileName, File $textFile): ?array {
$attachmentFolder = $this->getAttachmentDirectoryForFile($textFile, true);
$mediaFile = $attachmentFolder->get($mediaFileName);
if ($mediaFile instanceof File) {
if ($mediaFile instanceof File && !$this->isDownloadDisabled($mediaFile)) {
if ($this->previewManager->isMimeSupported($mediaFile->getMimeType())) {
try {
return [
Expand Down Expand Up @@ -474,13 +475,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 @@ -493,9 +508,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 @@ -516,15 +532,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