Skip to content

Commit 9d9ff21

Browse files
nickvergessenbackportbot[bot]
authored andcommitted
fix(teamfolder): Fix mimetype detection in teamfolder trashbin and versions
Signed-off-by: Joas Schilling <coding@schilljs.com>
1 parent ce53004 commit 9d9ff21

3 files changed

Lines changed: 50 additions & 3 deletions

File tree

lib/Operation.php

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use OC\Files\FileInfo;
1313
use OC\Files\Node\Folder;
1414
use OC\Files\View;
15+
use OCA\GroupFolders\Mount\GroupMountPoint;
1516
use OCA\WorkflowEngine\Entity\File;
1617
use OCP\EventDispatcher\Event;
1718
use OCP\Files\Cache\ICacheEntry;
@@ -62,7 +63,7 @@ public function checkFileAccess(string $path, IMountPoint $mountPoint, bool $isD
6263

6364
$this->nestingLevel++;
6465

65-
$filePath = $this->translatePath($storage, $path);
66+
$filePath = $this->translatePath($mountPoint, $storage, $path);
6667
$ruleMatcher = $this->manager->getRuleMatcher();
6768
$ruleMatcher->setFileInfo($storage, $filePath, $isDir);
6869
$node = $this->getNode($path, $mountPoint, $cacheEntry);
@@ -119,8 +120,31 @@ protected function isBlockablePath(IMountPoint $mountPoint, string $path): bool
119120
/**
120121
* For thumbnails and versions we want to check the tags of the original file
121122
*/
122-
protected function translatePath(IStorage $storage, string $path): string {
123-
if (substr_count($path, '/') < 1) {
123+
protected function translatePath(IMountPoint $mountPoint, IStorage $storage, string $path): string {
124+
if ($mountPoint instanceof GroupMountPoint) {
125+
/**
126+
* Case | Mount point path | Path ($path)
127+
* --------+---------------------------------------+--------------------------------
128+
* Files | /user/files/$folderName/ | Subfolder/File.txt
129+
* Trash | /user/files_trashbin/groupfolder/$id/ | Subfolder/File.txt.v{timestamp}
130+
* Version | /user/files_versions/groupfolder/$id/ | Subfolder/File.txt.d{timestamp}
131+
*/
132+
$mountPath = $mountPoint->getMountPoint();
133+
if (substr_count($mountPath, '/') >= 3) {
134+
[,, $folder] = explode('/', $mountPath);
135+
if ($folder === 'files_versions' && preg_match('/.+\.v\d{10}$/', basename($path))) {
136+
// Remove trailing ".v{timestamp}"
137+
return substr($path, 0, -12);
138+
}
139+
if ($folder === 'files_trashbin' && preg_match('/.+\.d\d{10}$/', basename($path))) {
140+
// Remove trailing ".d{timestamp}"
141+
return substr($path, 0, -12);
142+
}
143+
}
144+
return $path;
145+
}
146+
147+
if (substr_count($path, '/') === 0) {
124148
return $path;
125149
}
126150

@@ -176,6 +200,10 @@ protected function isCreatingSkeletonFiles(): bool {
176200
&& isset($step['function']) && $step['function'] === 'tryLogin') {
177201
return true;
178202
}
203+
if (isset($step['class']) && $step['class'] === \OCA\GroupFolders\Trash\TrashBackend::class
204+
&& isset($step['function']) && $step['function'] === 'setupTrashFolder') {
205+
return true;
206+
}
179207
}
180208

181209
return false;

psalm.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@
3131
<file name="tests/stubs/oc_files_cache_wrapper_cachewrapper.php" />
3232
<file name="tests/stubs/oc_files_storage_wrapper_wrapper.php" />
3333
<file name="tests/stubs/oc_files_storage_wrapper_jail.php" />
34+
<file name="tests/stubs/oca_groupfolders.php" />
3435
</stubs>
3536
</psalm>

tests/stubs/oca_groupfolders.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
/**
4+
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
5+
* SPDX-License-Identifier: AGPL-3.0-or-later
6+
*/
7+
8+
namespace OCA\GroupFolders\Trash {
9+
class TrashBackend {
10+
public function setupTrashFolder(string $class, string $value, $closure) {
11+
}
12+
}
13+
}
14+
15+
namespace OCA\GroupFolders\Mount {
16+
abstract class GroupMountPoint implements \OCP\Files\Mount\IMountPoint {
17+
}
18+
}

0 commit comments

Comments
 (0)