Skip to content
Merged
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
32 changes: 26 additions & 6 deletions lib/Operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
use Exception;
use OC\Files\FileInfo;
use OC\Files\Node\Folder;
use OC\Files\Storage\Wrapper\Jail;
use OC\Files\View;
use OCA\GroupFolders\Mount\GroupMountPoint;
use OCA\WorkflowEngine\Entity\File;
use OCP\Constants;
use OCP\EventDispatcher\Event;
use OCP\Files\Cache\ICacheEntry;
use OCP\Files\Cache\IFileAccess;
use OCP\Files\ForbiddenException;
use OCP\Files\IRootFolder;
use OCP\Files\Mount\IMountManager;
Expand All @@ -43,6 +45,7 @@ public function __construct(
protected readonly IMountManager $mountManager,
protected readonly IRootFolder $rootFolder,
protected readonly LoggerInterface $logger,
protected readonly IFileAccess $fileAccess,
) {
}

Expand Down Expand Up @@ -158,14 +161,15 @@ protected function isBlockablePath(IMountPoint $mountPoint, string $path): bool
/**
* For thumbnails and versions we want to check the tags of the original file
*/
protected function translatePath(IMountPoint $mountPoint, IStorage $storage, string $path): string {
protected function translatePath(IMountPoint $mountPoint, IStorage &$storage, string $path): string {
if ($mountPoint instanceof GroupMountPoint) {
/**
* Case | Mount point path | Path ($path)
* --------+---------------------------------------+--------------------------------
* Files | /user/files/$folderName/ | Subfolder/File.txt
* Trash | /user/files_trashbin/groupfolder/$id/ | Subfolder/File.txt.v{timestamp}
* Version | /user/files_versions/groupfolder/$id/ | Subfolder/File.txt.d{timestamp}
* Case | Mount point path | Path ($path)
* --------+----------------------------------------+--------------------------------
* Files | /user/files/$folderName/ | Subfolder/File.txt
* Trash | /user/files_trashbin/groupfolders/$id/ | Subfolder/File.txt.d{timestamp}
* Version | /user/files_versions/groupfolders/$id/ | Subfolder/File.txt.v{timestamp}
* Version | /user/files_versions/groupfolders/$id/ | {fileId}/{timestamp}
*/
$mountPath = $mountPoint->getMountPoint();
if (substr_count($mountPath, '/') >= 3) {
Expand All @@ -174,6 +178,22 @@ protected function translatePath(IMountPoint $mountPoint, IStorage $storage, str
// Remove trailing ".v{timestamp}"
return substr($path, 0, -12);
}
if ($folder === 'files_versions' && preg_match('/^\d+\/\d+$/', $path)) {
// Map "{fileId}/{timestamp}" to the original file
/** @var Jail $storage */
$cacheEntry = $this->fileAccess->getByFileIdInStorage((int)basename(dirname($path)), $storage->getCache()->getNumericStorageId());
if ($cacheEntry !== null) {
if ($storage->instanceOfStorage(Jail::class)) {
$storage = $storage->getUnjailedStorage();
}
return $cacheEntry->getPath();
}
$node = $this->rootFolder->getFirstNodeById((int)basename(dirname($path)));
if ($node !== null) {
$storage = $node->getStorage();
return $node->getInternalPath();
}
}
if ($folder === 'files_trashbin' && preg_match('/.+\.d\d{10}$/', basename($path))) {
// Remove trailing ".d{timestamp}"
return substr($path, 0, -12);
Expand Down
27 changes: 27 additions & 0 deletions tests/Integration/features/bootstrap/WebDav.php
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,18 @@ public function userUploadsAFileTo($user, $source, $destination) {
}
}

/**
* @When User :user uploads file :source to :destination with mtime :mtime
* @param string $user
* @param string $source
* @param string $destination
* @param string $mtime
*/
public function userUploadsAFileToWithMtime($user, $source, $destination, $mtime) {
$file = \GuzzleHttp\Psr7\Utils::streamFor(fopen($source, 'r'));
$this->response = $this->makeDavRequest($user, 'PUT', $destination, ['X-OC-MTime' => $mtime], $file);
}

/**
* @When User :user adds a file of :bytes bytes to :destination
* @param string $user
Expand Down Expand Up @@ -1049,6 +1061,21 @@ public function userLoadsFileListOfTrashbin($user) {
}


/**
* @Then /^User "([^"]*)" sees (\d+) versions of file "([^"]*)"$/
* @param string $user
* @param string $count
* @param string $path
*/
public function userSeesVersionsOfFile($user, $count, $path) {
$fileId = $this->getFileIdForPath($user, $path);
$client = $this->getSabreClient($user);
$response = $client->propfind($this->makeSabrePath($user, 'versions/' . $fileId, 'versions'), ['{DAV:}getetag'], 1);
unset($response['/remote.php/dav/versions/' . $user . '/versions/' . $fileId . '/']);

Assert::assertCount((int)$count, $response);
}

/**
* @param string $user
* @param string $path
Expand Down
62 changes: 62 additions & 0 deletions tests/Integration/features/mimetypes.feature
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,65 @@
| checks-1 | {"class":"OCA\\\\WorkflowEngine\\\\Check\\\\FileMimeType", "operator": "!is", "value": "text/plain"} |
When User "test1" deletes file "/Folder886/foobar.txt"
Then The webdav response should have a status code "204"

Scenario: Blocking by mimetype does not block versions of groupfolders
Given group "groupversions" exists
And user "test1" is member of group "groupversions"
And setup group folder "FolderVersions" for group "groupversions"
Given User "test1" uploads file "data/textfile.txt" to "/FolderVersions/foobar.txt" with mtime "1700000000"
Then The webdav response should have a status code "201"
And user "admin" creates global flow with 200
| name | Admin flow |
| class | OCA\FilesAccessControl\Operation |
| entity | OCA\WorkflowEngine\Entity\File |
| events | [] |
| operation | deny |
| checks-0 | {"class":"OCA\\\\WorkflowEngine\\\\Check\\\\FileMimeType", "operator": "!is", "value": "httpd/unix-directory"} |
| checks-1 | {"class":"OCA\\\\WorkflowEngine\\\\Check\\\\FileMimeType", "operator": "!is", "value": "text/plain"} |
When User "test1" uploads file "data/textfile-2.txt" to "/FolderVersions/foobar.txt"
Then The webdav response should have a status code "204"
And User "test1" sees 2 versions of file "/FolderVersions/foobar.txt"

Scenario: Blocking by tag does not block versions of groupfolders
Given Ensure tag exists
And group "groupversions" exists
And user "test1" is member of group "groupversions"
And setup group folder "FolderVersions" for group "groupversions"
Given User "test1" uploads file "data/textfile.txt" to "/FolderVersions/foobar.txt" with mtime "1700000000"
Then The webdav response should have a status code "201"
And user "test1" tags file "/FolderVersions/foobar.txt"
And user "admin" creates global flow with 200
| name | Admin flow |
| class | OCA\FilesAccessControl\Operation |
| entity | OCA\WorkflowEngine\Entity\File |
| events | [] |
| operation | deny |
| checks-0 | {"class":"OCA\\\\WorkflowEngine\\\\Check\\\\FileMimeType", "operator": "!is", "value": "httpd/unix-directory"} |
| checks-1 | {"class":"OCA\\\\WorkflowEngine\\\\Check\\\\FileSystemTags", "operator": "!is", "value": "{{{FILES_ACCESSCONTROL_INTEGRATIONTEST_TAGID}}}"} |
When User "test1" uploads file "data/textfile-2.txt" to "/FolderVersions/foobar.txt"
Then The webdav response should have a status code "204"
And User "test1" sees 2 versions of file "/FolderVersions/foobar.txt"

Scenario: Blocking by tag does not block versions of files moved out of groupfolders
Given Ensure tag exists
And group "groupversions" exists
And user "test1" is member of group "groupversions"
And setup group folder "FolderVersions" for group "groupversions"
Given User "test1" uploads file "data/textfile.txt" to "/FolderVersions/foobar.txt" with mtime "1700000000"
Then The webdav response should have a status code "201"
When User "test1" uploads file "data/textfile-2.txt" to "/FolderVersions/foobar.txt"
Then The webdav response should have a status code "204"
And user "test1" tags file "/FolderVersions/foobar.txt"
And User "test1" created a folder "/Approved"
And user "test1" tags file "/Approved"
And user "admin" creates global flow with 200
| name | Admin flow |
| class | OCA\FilesAccessControl\Operation |
| entity | OCA\WorkflowEngine\Entity\File |
| events | [] |
| operation | deny |
| checks-0 | {"class":"OCA\\\\WorkflowEngine\\\\Check\\\\FileMimeType", "operator": "!is", "value": "httpd/unix-directory"} |
| checks-1 | {"class":"OCA\\\\WorkflowEngine\\\\Check\\\\FileSystemTags", "operator": "!is", "value": "{{{FILES_ACCESSCONTROL_INTEGRATIONTEST_TAGID}}}"} |
When User "test1" moves file "/FolderVersions/foobar.txt" to "/Approved/foobar.txt"
Then The webdav response should have a status code "201"
And User "test1" sees 2 versions of file "/Approved/foobar.txt"
2 changes: 2 additions & 0 deletions tests/Unit/OperationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use OCA\WorkflowEngine\Entity\File;
use OCP\Constants;
use OCP\Files\Cache\ICache;
use OCP\Files\Cache\IFileAccess;
use OCP\Files\ForbiddenException;
use OCP\Files\IRootFolder;
use OCP\Files\Mount\IMountManager;
Expand Down Expand Up @@ -61,6 +62,7 @@ protected function setUp(): void {
$this->createMock(IMountManager::class),
$this->createMock(IRootFolder::class),
$this->createMock(LoggerInterface::class),
$this->createMock(IFileAccess::class),
])
->onlyMethods(['isBlockablePath', 'isCreatingSkeletonFiles', 'translatePath'])
->getMock();
Expand Down
Loading