Skip to content

Commit ecd05d7

Browse files
authored
Merge pull request #17099 from nextcloud/backport/16664/stable16
[stable16] Emit moveToTrash event only for the deleting user
2 parents 1b8ae61 + 1db1d2c commit ecd05d7

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

apps/files_trashbin/lib/Storage.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,21 @@ public function rmdir($path) {
125125
* @return bool
126126
*/
127127
protected function shouldMoveToTrash($path) {
128+
$normalized = Filesystem::normalizePath($this->mountPoint . '/' . $path);
129+
$parts = explode('/', $normalized);
130+
if (count($parts) < 4) {
131+
return false;
132+
}
128133

129134
// check if there is a app which want to disable the trash bin for this file
130135
$fileId = $this->storage->getCache()->getId($path);
131-
$nodes = $this->rootFolder->getById($fileId);
136+
$owner = $this->storage->getOwner($path);
137+
if ($owner === false) {
138+
$nodes = $this->rootFolder->getById($fileId);
139+
} else {
140+
$nodes = $this->rootFolder->getUserFolder($owner)->getById($fileId);
141+
}
142+
132143
foreach ($nodes as $node) {
133144
$event = $this->createMoveToTrashEvent($node);
134145
$this->eventDispatcher->dispatch('OCA\Files_Trashbin::moveToTrash', $event);
@@ -137,12 +148,6 @@ protected function shouldMoveToTrash($path) {
137148
}
138149
}
139150

140-
$normalized = Filesystem::normalizePath($this->mountPoint . '/' . $path);
141-
$parts = explode('/', $normalized);
142-
if (count($parts) < 4) {
143-
return false;
144-
}
145-
146151
if ($parts[2] === 'files' && $this->userManager->userExists($parts[1])) {
147152
return true;
148153
}

apps/files_trashbin/tests/StorageTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
use OCA\Files_Trashbin\Storage;
3737
use OCA\Files_Trashbin\Trash\ITrashManager;
3838
use OCP\Files\Cache\ICache;
39+
use OCP\Files\Folder;
3940
use OCP\Files\IRootFolder;
4041
use OCP\Files\Node;
4142
use OCP\ILogger;
@@ -546,12 +547,14 @@ public function testShouldMoveToTrash($mountPoint, $path, $userExists, $appDisab
546547
$eventDispatcher = $this->getMockBuilder(EventDispatcher::class)
547548
->disableOriginalConstructor()->getMock();
548549
$rootFolder = $this->createMock(IRootFolder::class);
550+
$userFolder = $this->createMock(Folder::class);
549551
$node = $this->getMockBuilder(Node::class)->disableOriginalConstructor()->getMock();
550552
$trashManager = $this->createMock(ITrashManager::class);
551553
$event = $this->getMockBuilder(MoveToTrashEvent::class)->disableOriginalConstructor()->getMock();
552554
$event->expects($this->any())->method('shouldMoveToTrashBin')->willReturn(!$appDisablesTrash);
553555

554-
$rootFolder->expects($this->any())->method('getById')->with($fileID)->willReturn([$node]);
556+
$userFolder->expects($this->any())->method('getById')->with($fileID)->willReturn([$node]);
557+
$rootFolder->expects($this->any())->method('getUserFolder')->willReturn($userFolder);
555558

556559
$storage = $this->getMockBuilder(Storage::class)
557560
->setConstructorArgs(

0 commit comments

Comments
 (0)