From e88d1fb4581987f0b6fcdbe9bcb35f7c9609e8da Mon Sep 17 00:00:00 2001 From: Benjamin Gaussorgues Date: Wed, 30 Aug 2023 10:15:04 +0200 Subject: [PATCH] Fix leave share for root folder --- lib/Connector/Sabre/LockPlugin.php | 5 ++++- lib/FileService.php | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/Connector/Sabre/LockPlugin.php b/lib/Connector/Sabre/LockPlugin.php index b1e1ea1a..66ff54bb 100644 --- a/lib/Connector/Sabre/LockPlugin.php +++ b/lib/Connector/Sabre/LockPlugin.php @@ -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.'); } } diff --git a/lib/FileService.php b/lib/FileService.php index 266a9980..e23f1ae0 100644 --- a/lib/FileService.php +++ b/lib/FileService.php @@ -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; @@ -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(); } @@ -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' => [],