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

feat: Add allowed_view_extensions config node #6564

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
9 changes: 7 additions & 2 deletions lib/Service/ApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,13 @@ public function create(?int $fileId = null, ?string $filePath = null, ?string $b
if ($storage->instanceOfStorage(SharedStorage::class)) {
/** @var IShare $share */
$share = $storage->getShare();
$shareAttribtues = $share->getAttributes();
if ($shareAttribtues !== null && $shareAttribtues->getAttribute('permissions', 'download') === false) {

$allowedFileExtensions = $this->configService->getAllowedViewFileExtensions();
$isAllowedToViewForExtension = $allowedFileExtensions && in_array($file->getExtension(), $allowedFileExtensions, true);
$shareAttributes = $share->getAttributes();
$isAllowedByShare = $shareAttributes === null || $shareAttributes->getAttribute('permissions', 'download') !== false;

if (!$isAllowedToViewForExtension && !$isAllowedByShare) {
return new DataResponse(['error' => $this->l10n->t('This file cannot be displayed as download is disabled by the share')], Http::STATUS_FORBIDDEN);
}
}
Expand Down
7 changes: 7 additions & 0 deletions lib/Service/AttachmentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function __construct(
private IMimeTypeDetector $mimeTypeDetector,
private IURLGenerator $urlGenerator,
private IFilenameValidator $filenameValidator,
private ConfigService $configService,
) {
}

Expand Down Expand Up @@ -464,6 +465,12 @@ private function isDownloadDisabled(File $file): bool {
if ($storage->instanceOfStorage(SharedStorage::class)) {
/** @var SharedStorage $storage */
$share = $storage->getShare();

$allowedFileExtensions = $this->configService->getAllowedViewFileExtensions();
if ($allowedFileExtensions && in_array($file->getExtension(), $allowedFileExtensions, true)) {
return false;
}

$attributes = $share->getAttributes();
if ($attributes !== null && $attributes->getAttribute('permissions', 'download') === false) {
return true;
Expand Down
6 changes: 6 additions & 0 deletions lib/Service/ConfigService.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ public function isRichWorkspaceEnabledForUser(?string $userId): bool {

public function isNotifyPushSyncEnabled(): bool {
return $this->appConfig->getValueBool(Application::APP_NAME, 'notify_push');
}

/**
* @return string[]
*/
public function getAllowedViewFileExtensions(): array {
return $this->config->getSystemValue('allowed_view_extensions', []);
}
}
Loading