Skip to content

Commit 16eaea2

Browse files
committed
fixup! feat: improve ZipFolderPlugin behaviour for different cases
Signed-off-by: Salvatore Martire <4652631+salmart-dev@users.noreply.github.com>
1 parent ccc00aa commit 16eaea2

4 files changed

Lines changed: 23 additions & 14 deletions

File tree

apps/files_sharing/lib/Listener/BeforeZipCreatedListener.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ public function handle(Event $event): void {
3838
$files = $event->getFiles();
3939

4040
if (empty($files)) {
41-
$pathsToCheck = [$dir];
41+
$pathsToCheck = [];
4242
} else {
4343
$pathsToCheck = [];
4444
foreach ($files as $file) {
45-
$pathsToCheck[] = $dir . '/' . $file;
45+
$pathsToCheck[] = $file;
4646
}
4747
}
4848

@@ -58,7 +58,7 @@ public function handle(Event $event): void {
5858
$userFolder = $user ? $this->rootFolder->getUserFolder($user->getUID()) : null;
5959
$folderToCheck = $userFolder ? $userFolder->get($dir) : $folder;
6060

61-
$viewOnlyHandler = new ViewOnly($userFolder);
61+
$viewOnlyHandler = new ViewOnly($folderToCheck);
6262
$isRootDownloadable = $viewOnlyHandler->isDownloadable($folderToCheck);
6363

6464
if (!$isRootDownloadable) {

apps/files_sharing/lib/ViewOnly.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,27 @@
1919
class ViewOnly {
2020

2121
public function __construct(
22-
private ?Folder $userFolder,
22+
private ?Folder $folder,
2323
) {
2424
}
2525

2626
/**
27-
* @param string[] $pathsToCheck paths to check, relative to the user folder
27+
* @param string[] $pathsToCheck paths to check, relative to the given folder
2828
* @return bool
2929
*/
3030
public function check(array $pathsToCheck): bool {
31-
if ($this->userFolder === null) {
32-
throw new \LogicException('The user folder is not set but this check requires it.');
31+
if ($this->folder === null) {
32+
throw new \LogicException('Folder is not set but this check requires it.');
33+
}
34+
35+
if (empty($pathsToCheck)) {
36+
return $this->dirRecursiveCheck($this->folder);
3337
}
3438

3539
// If any of elements cannot be downloaded, prevent whole download
3640
foreach ($pathsToCheck as $file) {
3741
try {
38-
$info = $this->userFolder->get($file);
42+
$info = $this->folder->get($file);
3943
if ($info instanceof File) {
4044
// access to filecache is expensive in the loop
4145
if (!$this->isDownloadable($info)) {

apps/files_sharing/tests/ApplicationTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,14 @@ function (string $fileStorage) use ($nonSharedStorage, $secureSharedStorage) {
164164
$directoryListing
165165
);
166166
$folder->method('getDirectoryListing')->willReturn($directoryListing);
167+
$callCount = 0;
168+
$folder->method('get')->willReturnCallback(function (string $path) use (&$callCount, $directoryListing) {
169+
if (isset($directoryListing[$callCount])) {
170+
return $directoryListing[$callCount++];
171+
}
172+
173+
throw new \Exception('Unknown path ' . $path);
174+
});
167175
}
168176

169177
// If the folder contains any secure-shared files, make it appear as a secure-shared folder
@@ -178,7 +186,7 @@ function (string $fileStorage) use ($nonSharedStorage, $secureSharedStorage) {
178186
$rootFolder->method('getDirectoryListing')->willReturn([$folder]);
179187

180188
$userFolder = $this->createMock(Folder::class);
181-
$userFolder->method('get')->willReturn($rootFolder);
189+
$userFolder->method('get')->willReturn($folder);
182190

183191
$user = $this->createMock(IUser::class);
184192
$user->method('getUID')->willReturn('test');

apps/files_sharing/tests/unit/Listener/BeforeZipCreatedListenerTest.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ protected function setUp(): void {
4646

4747
public static function dataHandle(): array {
4848
$rootFromFolder = '/folder';
49-
// files are relative to $folderPath
50-
// filesFilter are relative to $folderPath but without leading /
51-
// expectedNodeList are ...
5249
return [
5350
'partial archive disabled, no filtering, 1 blocked file => should fail event' => [
5451
'folderPath' => $rootFromFolder,
@@ -194,10 +191,10 @@ public function testHandle(
194191
$fileNodes[] = $file;
195192
}
196193
$folder = $this->createSharedFolder($rootDownloadable, $folderPathFromUserRoot, $fileNodes);
197-
$this->userFolder->method('get')->willReturnCallback(function (string $path) use ($folderPath, $fileNodesByName, $folder) {
194+
$this->userFolder->method('get')->willReturn($folder);
195+
$folder->method('get')->willReturnCallback(function (string $path) use ($folderPath, $fileNodesByName, $folder) {
198196
$path = str_replace($folderPath . '/', '', $path);
199197
return match (true) {
200-
$path === $folderPath => $folder,
201198
isset($fileNodesByName[$path]) => $fileNodesByName[$path],
202199
default => throw new \RuntimeException("Mock node not set for {$path}"),
203200
};

0 commit comments

Comments
 (0)