Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Emit moveToTrash event only for the deleting user
Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliusknorr authored and Backportbot committed Sep 11, 2019
commit f4ef37285b715a01a7fecdd8f62d44501cbd3c63
15 changes: 7 additions & 8 deletions apps/files_trashbin/lib/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,15 @@ public function rmdir($path) {
* @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);
Expand All @@ -137,13 +142,7 @@ protected function shouldMoveToTrash($path) {
}
}

$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;
}

Expand Down
5 changes: 4 additions & 1 deletion apps/files_trashbin/tests/StorageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
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;
Expand Down Expand Up @@ -546,12 +547,14 @@ public function testShouldMoveToTrash($mountPoint, $path, $userExists, $appDisab
$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(
Expand Down