Skip to content

Commit bf2f624

Browse files
committed
feat: Add allowed_view_extensions config node
Signed-off-by: Kostiantyn Miakshyn <molodchick@gmail.com>
1 parent 6ce11f8 commit bf2f624

3 files changed

Lines changed: 20 additions & 2 deletions

File tree

lib/Service/ApiService.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,13 @@ public function create(?int $fileId = null, ?string $filePath = null, ?string $b
8181
if ($storage->instanceOfStorage(SharedStorage::class)) {
8282
/** @var IShare $share */
8383
$share = $storage->getShare();
84-
$shareAttribtues = $share->getAttributes();
85-
if ($shareAttribtues !== null && $shareAttribtues->getAttribute('permissions', 'download') === false) {
84+
85+
$allowedFileExtensions = $this->configService->getAllowedViewFileExtensions();
86+
$isAllowedToViewForExtension = $allowedFileExtensions && in_array($file->getExtension(), $allowedFileExtensions, true);
87+
$shareAttributes = $share->getAttributes();
88+
$isAllowedByShare = $shareAttributes === null || $shareAttributes->getAttribute('permissions', 'download') !== false;
89+
90+
if (!$isAllowedToViewForExtension && !$isAllowedByShare) {
8691
return new DataResponse(['error' => $this->l10n->t('This file cannot be displayed as download is disabled by the share')], Http::STATUS_FORBIDDEN);
8792
}
8893
}

lib/Service/AttachmentService.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public function __construct(
3939
private IMimeTypeDetector $mimeTypeDetector,
4040
private IURLGenerator $urlGenerator,
4141
private IFilenameValidator $filenameValidator,
42+
private ConfigService $configService,
4243
) {
4344
}
4445

@@ -464,6 +465,12 @@ private function isDownloadDisabled(File $file): bool {
464465
if ($storage->instanceOfStorage(SharedStorage::class)) {
465466
/** @var SharedStorage $storage */
466467
$share = $storage->getShare();
468+
469+
$allowedFileExtensions = $this->configService->getAllowedViewFileExtensions();
470+
if ($allowedFileExtensions && in_array($file->getExtension(), $allowedFileExtensions, true)) {
471+
return false;
472+
}
473+
467474
$attributes = $share->getAttributes();
468475
if ($attributes !== null && $attributes->getAttribute('permissions', 'download') === false) {
469476
return true;

lib/Service/ConfigService.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ public function isRichWorkspaceEnabledForUser(?string $userId): bool {
4242

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

47+
/**
48+
* @return string[]
49+
*/
50+
public function getAllowedViewFileExtensions(): array {
51+
return $this->config->getSystemValue('allowed_view_extensions', []);
4652
}
4753
}

0 commit comments

Comments
 (0)