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 #48903

Open
wants to merge 1 commit into
base: master
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
7 changes: 7 additions & 0 deletions apps/dav/lib/DAV/ViewOnlyPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use OCP\Files\Folder;
use OCP\Files\NotFoundException;
use OCP\Files\Storage\ISharedStorage;
use OCP\IConfig;
use Sabre\DAV\Exception\NotFound;
use Sabre\DAV\Server;
use Sabre\DAV\ServerPlugin;
Expand All @@ -27,6 +28,7 @@ class ViewOnlyPlugin extends ServerPlugin {

public function __construct(
private ?Folder $userFolder,
private IConfig $config,
) {
}

Expand Down Expand Up @@ -92,6 +94,11 @@ public function checkViewOnly(RequestInterface $request): bool {
return true;
}

$allowedFileExtensions = $this->config->getSystemValue('allowed_view_extensions', []);
if ($allowedFileExtensions && in_array($node->getExtension(), $allowedFileExtensions, true)) {
return true;
}

// Check if read-only and on whether permission can download is both set and disabled.
$canDownload = $attributes->getAttribute('permissions', 'download');
if ($canDownload !== null && !$canDownload) {
Expand Down
1 change: 1 addition & 0 deletions apps/dav/lib/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ public function __construct(
// Allow view-only plugin for webdav requests
$this->server->addPlugin(new ViewOnlyPlugin(
\OC::$server->getUserFolder(),
\OCP\Server::get(IConfig::class),
));

// custom properties plugin must be the last one
Expand Down
Loading