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

optionally hide hidden files if accessed via public share #41947

Open
wants to merge 2 commits 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
28 changes: 28 additions & 0 deletions lib/private/Files/Cache/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,34 @@ public function getFolderContentsById($fileId) {
return [];
}

/**
* get the metadata of all files stored in $folder except hidden files
*
* @param int $fileId the file id of the folder
* @return ICacheEntry[]
*/
public function getFolderContentsByIdExceptHidden($fileId) {
if ($fileId > -1) {
$query = $this->getQueryBuilder();
$query->selectFileCache()
->whereParent($fileId)
->andWhere($query->expr()->notlike('name', $query->createNamedParameter('.%')))
->orderBy('name', 'ASC');

$metadataQuery = $query->selectMetadata();

$result = $query->execute();
$files = $result->fetchAll();
$result->closeCursor();

return array_map(function (array $data) use ($metadataQuery) {
$data['metadata'] = $metadataQuery?->extractMetadata($data)->asArray() ?? [];
return self::cacheEntryFromData($data, $this->mimetypeLoader);
}, $files);
}
return [];
}

/**
* insert or update meta data for a file or folder
*
Expand Down
12 changes: 11 additions & 1 deletion lib/private/Files/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
use OCP\Files\NotFoundException;
use OCP\Files\ReservedWordException;
use OCP\Files\Storage\IStorage;
use OCP\IConfig;
use OCP\IUser;
use OCP\Lock\ILockingProvider;
use OCP\Lock\LockedException;
Expand Down Expand Up @@ -95,6 +96,9 @@ class View {
private UserManager $userManager;
private LoggerInterface $logger;

/** @var IConfig */
protected $config;

/**
* @throws \Exception If $root contains an invalid path
*/
Expand All @@ -103,6 +107,7 @@ public function __construct(string $root = '') {
throw new \Exception();
}

$this->config = \OC::$server->getConfig();
$this->fakeRoot = $root;
$this->lockingProvider = \OC::$server->getLockingProvider();
$this->lockingEnabled = !($this->lockingProvider instanceof \OC\Lock\NoopLockingProvider);
Expand Down Expand Up @@ -1454,7 +1459,12 @@ public function getDirectoryContent($directory, $mimetype_filter = '', \OCP\File
}

$folderId = $data->getId();
$contents = $cache->getFolderContentsById($folderId); //TODO: mimetype_filter
$systemConfigHideHiddenFilesViaPublicShareAccess = $this->config->getSystemValueBool('hide_hidden_files_via_public_share_access', false);
if ( $_SERVER['REQUEST_URI'] === "/public.php/webdav/" && $systemConfigHideHiddenFilesViaPublicShareAccess ){
$contents = $cache->getFolderContentsByIdExceptHidden($folderId); //TODO: mimetype_filter
Fixed Show fixed Hide fixed
}else{
$contents = $cache->getFolderContentsById($folderId); //TODO: mimetype_filter
}

$sharingDisabled = \OCP\Util::isSharingDisabledForUser();

Expand Down
11 changes: 11 additions & 0 deletions lib/public/Files/Cache/ICache.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@ public function getFolderContents($folder);
*/
public function getFolderContentsById($fileId);

/**
* get the metadata of all files stored in $folder except hidden files
*
* Only returns files one level deep, no recursion
*
* @param int $fileId the file id of the folder
* @return ICacheEntry[]
* @since 9.0.0
*/
public function getFolderContentsByIdExceptHidden($fileId);

/**
* store meta data for a file or folder
* This will automatically call either insert or update depending on if the file exists
Expand Down
Loading