summaryrefslogtreecommitdiffstats
path: root/apps/files_trashbin
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2019-08-05 19:10:49 +0200
committerJulius Härtl <jus@bitgrid.net>2019-08-06 17:45:50 +0200
commitb1832c8bef99be60acf7923fad2c58a726bfeecb (patch)
tree938932cb4b36be57b0261cac8ed4c4d8f6aa3efe /apps/files_trashbin
parent1d72073e349bf6926a13c085495c44fce2406e61 (diff)
downloadnextcloud-server-b1832c8bef99be60acf7923fad2c58a726bfeecb.tar.gz
nextcloud-server-b1832c8bef99be60acf7923fad2c58a726bfeecb.zip
Emit moveToTrash event only for the deleting user
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'apps/files_trashbin')
-rw-r--r--apps/files_trashbin/lib/Storage.php15
-rw-r--r--apps/files_trashbin/tests/StorageTest.php5
2 files changed, 11 insertions, 9 deletions
diff --git a/apps/files_trashbin/lib/Storage.php b/apps/files_trashbin/lib/Storage.php
index 04105dda6ce..ef341ada948 100644
--- a/apps/files_trashbin/lib/Storage.php
+++ b/apps/files_trashbin/lib/Storage.php
@@ -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;
}
diff --git a/apps/files_trashbin/tests/StorageTest.php b/apps/files_trashbin/tests/StorageTest.php
index eff33f9b30c..3c660134d1c 100644
--- a/apps/files_trashbin/tests/StorageTest.php
+++ b/apps/files_trashbin/tests/StorageTest.php
@@ -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;
@@ -545,12 +546,14 @@ class StorageTest extends \Test\TestCase {
$logger = $this->getMockBuilder(ILogger::class)->getMock();
$eventDispatcher = $this->createMock(EventDispatcherInterface::class);
$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(