Skip to content

Commit b848516

Browse files
committed
fix(Trash): Fix wrong original location
Signed-off-by: provokateurin <kate@provokateurin.de>
1 parent 4b484ad commit b848516

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

tests/Trash/TrashBackendTest.php

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@
1919
use OCA\GroupFolders\Folder\FolderManager;
2020
use OCA\GroupFolders\Mount\GroupFolderStorage;
2121
use OCA\GroupFolders\Trash\TrashBackend;
22+
use OCP\Constants;
2223
use OCP\Files\Folder;
2324
use OCP\Files\IRootFolder;
2425
use OCP\IUser;
26+
use OCP\Server;
27+
use OCP\Share;
2528
use Test\TestCase;
2629
use Test\Traits\UserTrait;
2730

@@ -211,4 +214,68 @@ public function testHideDeletedTrashItemInDeletedParentFolderAcl(): void {
211214

212215
$this->logout();
213216
}
217+
218+
public function testWrongOriginalLocation(): void {
219+
$userA = $this->createUser('A', 'test');
220+
$userAFolder = Server::get(IRootFolder::class)->getUserFolder('A');
221+
$userB = $this->createUser('B', 'test');
222+
$userBFolder = Server::get(IRootFolder::class)->getUserFolder('B');
223+
224+
$groupBackend = Server::get(Database::class);
225+
$groupBackend->createGroup('A');
226+
$groupBackend->addToGroup('A', 'A');
227+
$groupBackend->addToGroup('B', 'A');
228+
$this->assertCount(2, $groupBackend->usersInGroup('A'));
229+
230+
$groupFolderId = $this->folderManager->createFolder('A');
231+
$this->folderManager->setFolderACL($groupFolderId, true);
232+
$this->folderManager->addApplicableGroup($groupFolderId, 'A');
233+
$this->folderManager->setGroupPermissions($groupFolderId, 'A', Constants::PERMISSION_ALL);
234+
$this->assertInstanceOf(Folder::class, $userAFolder->get('A'));
235+
236+
$userAFolder->newFolder('A/B');
237+
238+
$this->ruleManager->saveRule(new Rule(new UserMapping('group', 'A'), $userAFolder->get('A/B')->getId(), Constants::PERMISSION_READ, 0));
239+
$this->ruleManager->saveRule(new Rule(new UserMapping('user', 'A'), $userAFolder->get('A/B')->getId(), Constants::PERMISSION_ALL, Constants::PERMISSION_READ | Constants::PERMISSION_UPDATE | Constants::PERMISSION_CREATE));
240+
241+
// TODO: Bug?
242+
//$this->assertSame(Constants::PERMISSION_READ | Constants::PERMISSION_UPDATE | Constants::PERMISSION_CREATE, $this->aclManager->getACLPermissionsForPath('A/B'));
243+
244+
$userAFolder->newFolder('A/B/C');
245+
$this->ruleManager->saveRule(new Rule(new UserMapping('user', 'A'), $userAFolder->get('A/B/C')->getId(), Constants::PERMISSION_ALL, Constants::PERMISSION_ALL));
246+
$this->assertSame(Constants::PERMISSION_ALL, $this->aclManager->getACLPermissionsForPath('A/B/C'));
247+
248+
$userAFolder->newFile('A/B/C/D', 'foo');
249+
$this->loginAsUser('A');
250+
$shareManager = Server::get(Share\IManager::class);
251+
252+
$folderShare = $shareManager->newShare();
253+
$folderShare->setShareType(Share\IShare::TYPE_USER);
254+
$folderShare->setSharedWith('B');
255+
$folderShare->setSharedBy('A');
256+
$folderShare->setPermissions(Constants::PERMISSION_ALL);
257+
$folderShare->setNode($userAFolder->get('A/B/C'));
258+
$folderShare = $shareManager->createShare($folderShare);
259+
$this->assertNotEmpty($folderShare->getId());
260+
261+
$fileShare = $shareManager->newShare();
262+
$fileShare->setShareType(Share\IShare::TYPE_USER);
263+
$fileShare->setSharedWith('B');
264+
$fileShare->setSharedBy('A');
265+
$fileShare->setPermissions(19);
266+
$fileShare->setNode($userAFolder->get('A/B/C/D'));
267+
$fileShare = $shareManager->createShare($fileShare);
268+
$this->assertNotEmpty($fileShare->getId());
269+
270+
$this->loginAsUser('B');
271+
$this->assertTrue($userBFolder->get('C/D')->isDeletable());
272+
$userBFolder->get('C/D')->delete();
273+
274+
$trashedOfUserB = $this->trashBackend->listTrashRoot($userB);
275+
$this->assertCount(1, $this->trashBackend->listTrashRoot($userA));
276+
$this->assertCount(1, $trashedOfUserB);
277+
278+
// TODO: Bug original location is wrong
279+
$this->assertSame('C/D', $trashedOfUserB[0]->getOriginalLocation());
280+
}
214281
}

0 commit comments

Comments
 (0)