Skip to content

Commit 5191596

Browse files
committed
fix(Trash): Fix wrong original location
Signed-off-by: provokateurin <[email protected]>
1 parent 4b484ad commit 5191596

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

tests/Trash/TrashBackendTest.php

+65
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,66 @@ public function testHideDeletedTrashItemInDeletedParentFolderAcl(): void {
211214

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

0 commit comments

Comments
 (0)