Skip to content

Commit

Permalink
Fix leave share for root folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Altahrim committed Aug 30, 2023
1 parent 319d27e commit e88d1fb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/Connector/Sabre/LockPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ public function checkLock(RequestInterface $request): void {
}

// Prevent moving or copying stuff from non-encrypted to encrypted folders
if ($this->isE2EEnabledPath($node) xor $this->isE2EEnabledPath($destNode)) {
// if original operation is not a DELETE
if ($this->isE2EEnabledPath($node) !== $this->isE2EEnabledPath($destNode)
&& $request->getHeader('X-Nc-Sabre-Original-Method') !== 'DELETE'
) {
throw new Forbidden('Cannot copy or move files from non-encrypted folders to end to end encrypted folders or vice versa.');
}
}
Expand Down
15 changes: 15 additions & 0 deletions lib/FileService.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
namespace OCA\EndToEndEncryption;

use OCA\EndToEndEncryption\Connector\Sabre\RedirectRequestPlugin;
use OCA\Files_Sharing\SharedStorage;
use OCP\Files\Folder;
use OCP\Files\Node;

Expand Down Expand Up @@ -72,6 +73,12 @@ public function finalizeChanges(Folder $folder): bool {

/** @var Node $intermediateFile */
foreach ($intermediateFiles['to_delete'] as $intermediateFile) {
// If shared to user, try to unshare it first
$storage = $intermediateFile->getStorage();
if ($storage->instanceOfStorage(SharedStorage::class) && $storage->unshareStorage()) {
continue;
}
// Otherwise delete it
$intermediateFile->delete();
}

Expand All @@ -83,6 +90,14 @@ public function finalizeChanges(Folder $folder): bool {
* @return array{to_save: Node[], to_delete: Node[]}
*/
private function getIntermediateFiles(Folder $folder): array {
// Special case when root folder is deleted/unshared
if ($this->isIntermediateFileToDelete($folder)) {
return [
'to_save' => [],
'to_delete' => [$folder]
];
}

$listing = $folder->getDirectoryListing();
$result = [
'to_save' => [],
Expand Down

0 comments on commit e88d1fb

Please sign in to comment.