Merge pull request #17099 from nextcloud/backport/16664/stable16
[stable16] Emit moveToTrash event only for the deleting user
This commit is contained in:
commit
ecd05d7cad
|
@ -125,10 +125,21 @@ class Storage extends Wrapper {
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function shouldMoveToTrash($path) {
|
protected function shouldMoveToTrash($path) {
|
||||||
|
$normalized = Filesystem::normalizePath($this->mountPoint . '/' . $path);
|
||||||
|
$parts = explode('/', $normalized);
|
||||||
|
if (count($parts) < 4) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// check if there is a app which want to disable the trash bin for this file
|
// check if there is a app which want to disable the trash bin for this file
|
||||||
$fileId = $this->storage->getCache()->getId($path);
|
$fileId = $this->storage->getCache()->getId($path);
|
||||||
$nodes = $this->rootFolder->getById($fileId);
|
$owner = $this->storage->getOwner($path);
|
||||||
|
if ($owner === false) {
|
||||||
|
$nodes = $this->rootFolder->getById($fileId);
|
||||||
|
} else {
|
||||||
|
$nodes = $this->rootFolder->getUserFolder($owner)->getById($fileId);
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($nodes as $node) {
|
foreach ($nodes as $node) {
|
||||||
$event = $this->createMoveToTrashEvent($node);
|
$event = $this->createMoveToTrashEvent($node);
|
||||||
$this->eventDispatcher->dispatch('OCA\Files_Trashbin::moveToTrash', $event);
|
$this->eventDispatcher->dispatch('OCA\Files_Trashbin::moveToTrash', $event);
|
||||||
|
@ -137,12 +148,6 @@ 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' && $this->userManager->userExists($parts[1])) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,7 @@ use OCA\Files_Trashbin\Events\MoveToTrashEvent;
|
||||||
use OCA\Files_Trashbin\Storage;
|
use OCA\Files_Trashbin\Storage;
|
||||||
use OCA\Files_Trashbin\Trash\ITrashManager;
|
use OCA\Files_Trashbin\Trash\ITrashManager;
|
||||||
use OCP\Files\Cache\ICache;
|
use OCP\Files\Cache\ICache;
|
||||||
|
use OCP\Files\Folder;
|
||||||
use OCP\Files\IRootFolder;
|
use OCP\Files\IRootFolder;
|
||||||
use OCP\Files\Node;
|
use OCP\Files\Node;
|
||||||
use OCP\ILogger;
|
use OCP\ILogger;
|
||||||
|
@ -546,12 +547,14 @@ class StorageTest extends \Test\TestCase {
|
||||||
$eventDispatcher = $this->getMockBuilder(EventDispatcher::class)
|
$eventDispatcher = $this->getMockBuilder(EventDispatcher::class)
|
||||||
->disableOriginalConstructor()->getMock();
|
->disableOriginalConstructor()->getMock();
|
||||||
$rootFolder = $this->createMock(IRootFolder::class);
|
$rootFolder = $this->createMock(IRootFolder::class);
|
||||||
|
$userFolder = $this->createMock(Folder::class);
|
||||||
$node = $this->getMockBuilder(Node::class)->disableOriginalConstructor()->getMock();
|
$node = $this->getMockBuilder(Node::class)->disableOriginalConstructor()->getMock();
|
||||||
$trashManager = $this->createMock(ITrashManager::class);
|
$trashManager = $this->createMock(ITrashManager::class);
|
||||||
$event = $this->getMockBuilder(MoveToTrashEvent::class)->disableOriginalConstructor()->getMock();
|
$event = $this->getMockBuilder(MoveToTrashEvent::class)->disableOriginalConstructor()->getMock();
|
||||||
$event->expects($this->any())->method('shouldMoveToTrashBin')->willReturn(!$appDisablesTrash);
|
$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)
|
$storage = $this->getMockBuilder(Storage::class)
|
||||||
->setConstructorArgs(
|
->setConstructorArgs(
|
||||||
|
|
Loading…
Reference in New Issue