]> source.dussan.org Git - nextcloud-server.git/commitdiff
Emit moveToTrash event only for the deleting user
authorJulius Härtl <jus@bitgrid.net>
Mon, 5 Aug 2019 17:10:49 +0000 (19:10 +0200)
committerBackportbot <backportbot-noreply@rullzer.com>
Wed, 11 Sep 2019 10:38:50 +0000 (10:38 +0000)
Signed-off-by: Julius Härtl <jus@bitgrid.net>
apps/files_trashbin/lib/Storage.php
apps/files_trashbin/tests/StorageTest.php

index 0db634eeb9ea7556983313292b32c0100f7415b1..9c714d30aef53872004acf407bf472e1fe92e9d6 100644 (file)
@@ -125,10 +125,15 @@ class Storage extends Wrapper {
         * @return bool
         */
        protected function shouldMoveToTrash($path) {
+               $normalized = Filesystem::normalizePath($this->mountPoint . '/' . $path);
+               $parts = explode('/', $normalized);
+               if (count($parts) < 4 ||  !$this->userManager->userExists($parts[1])) {
+                       return false;
+               }
 
                // check if there is a app which want to disable the trash bin for this file
                $fileId = $this->storage->getCache()->getId($path);
-               $nodes = $this->rootFolder->getById($fileId);
+               $nodes = $this->rootFolder->getUserFolder($parts[1])->getById($fileId);
                foreach ($nodes as $node) {
                        $event = $this->createMoveToTrashEvent($node);
                        $this->eventDispatcher->dispatch('OCA\Files_Trashbin::moveToTrash', $event);
@@ -137,13 +142,7 @@ class Storage extends Wrapper {
                        }
                }
 
-               $normalized = Filesystem::normalizePath($this->mountPoint . '/' . $path);
-               $parts = explode('/', $normalized);
-               if (count($parts) < 4) {
-                       return false;
-               }
-
-               if ($parts[2] === 'files' && $this->userManager->userExists($parts[1])) {
+               if ($parts[2] === 'files') {
                        return true;
                }
 
index 058d64d1aa0dbf394a6835e87260f92b8f980882..330b00af20cf1393d7cc8fd3fd694288c195fc90 100644 (file)
@@ -36,6 +36,7 @@ use OCA\Files_Trashbin\Events\MoveToTrashEvent;
 use OCA\Files_Trashbin\Storage;
 use OCA\Files_Trashbin\Trash\ITrashManager;
 use OCP\Files\Cache\ICache;
+use OCP\Files\Folder;
 use OCP\Files\IRootFolder;
 use OCP\Files\Node;
 use OCP\ILogger;
@@ -546,12 +547,14 @@ class StorageTest extends \Test\TestCase {
                $eventDispatcher = $this->getMockBuilder(EventDispatcher::class)
                        ->disableOriginalConstructor()->getMock();
                $rootFolder = $this->createMock(IRootFolder::class);
+               $userFolder = $this->createMock(Folder::class);
                $node = $this->getMockBuilder(Node::class)->disableOriginalConstructor()->getMock();
                $trashManager = $this->createMock(ITrashManager::class);
                $event = $this->getMockBuilder(MoveToTrashEvent::class)->disableOriginalConstructor()->getMock();
                $event->expects($this->any())->method('shouldMoveToTrashBin')->willReturn(!$appDisablesTrash);
 
-               $rootFolder->expects($this->any())->method('getById')->with($fileID)->willReturn([$node]);
+               $userFolder->expects($this->any())->method('getById')->with($fileID)->willReturn([$node]);
+               $rootFolder->expects($this->any())->method('getUserFolder')->willReturn($userFolder);
 
                $storage = $this->getMockBuilder(Storage::class)
                        ->setConstructorArgs(