Skip to content

Commit

Permalink
fix(Trash): Fix empty original location
Browse files Browse the repository at this point in the history
Signed-off-by: provokateurin <[email protected]>
  • Loading branch information
provokateurin committed Oct 14, 2024
1 parent 2994e18 commit a665bb7
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions tests/Trash/TrashBackendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@
use OCA\GroupFolders\Folder\FolderManager;
use OCA\GroupFolders\Mount\GroupFolderStorage;
use OCA\GroupFolders\Trash\TrashBackend;
use OCP\Constants;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\IUser;
use OCP\Server;
use OCP\Share;
use Test\TestCase;
use Test\Traits\UserTrait;

Expand Down Expand Up @@ -211,4 +214,61 @@ public function testHideDeletedTrashItemInDeletedParentFolderAcl(): void {

$this->logout();
}

public function testBug(): void {
$userA = $this->createUser('A', 'test');
$userAFolder = Server::get(IRootFolder::class)->getUserFolder('A');
$userB = $this->createUser('B', 'test');
$userBFolder = Server::get(IRootFolder::class)->getUserFolder('B');

$groupBackend = Server::get(Database::class);
$groupBackend->createGroup('A');
$groupBackend->addToGroup('A', 'A');

$groupFolderId = $this->folderManager->createFolder('A');
$this->folderManager->addApplicableGroup($groupFolderId, 'A');
$this->assertInstanceOf(Folder::class, $userAFolder->get('A'));

$this->loginAsUser('A');

$userAFolder->newFolder('A/B');
$this->ruleManager->saveRule(new Rule(new UserMapping('group', 'A'), $userAFolder->get('A/B')->getId(), Constants::PERMISSION_ALL, 0));
$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));
// TODO: Bug?
//$this->assertSame(Constants::PERMISSION_READ | Constants::PERMISSION_UPDATE | Constants::PERMISSION_CREATE, $this->aclManager->getACLPermissionsForPath('A/B'));

$userAFolder->newFolder('A/B/C');
$this->ruleManager->saveRule(new Rule(new UserMapping('user', 'A'), $userAFolder->get('A/B/C')->getId(), Constants::PERMISSION_ALL, Constants::PERMISSION_ALL));
$this->assertSame(Constants::PERMISSION_ALL, $this->aclManager->getACLPermissionsForPath('A/B/C'));

$userAFolder->newFile('A/B/C/D', 'foo');

$shareManager = Server::get(Share\IManager::class);

$folderShare = $shareManager->newShare();
$folderShare->setShareType(Share\IShare::TYPE_USER);
$folderShare->setSharedWith('B');
$folderShare->setSharedBy('A');
$folderShare->setPermissions(19);
$folderShare->setNode($userAFolder->get('A/B/C'));
$folderShare = $shareManager->createShare($folderShare);
$this->assertNotEmpty($folderShare->getId());

$fileShare = $shareManager->newShare();
$fileShare->setShareType(Share\IShare::TYPE_USER);
$fileShare->setSharedWith('B');
$fileShare->setSharedBy('A');
$fileShare->setPermissions(19);
$fileShare->setNode($userAFolder->get('A/B/C/D'));
$fileShare = $shareManager->createShare($fileShare);
$this->assertNotEmpty($fileShare->getId());

$this->loginAsUser('B');

$this->assertTrue($userBFolder->get('D')->isDeletable());
$userBFolder->get('D')->delete();

// TODO: Bug?
$this->assertCount(1, $this->trashBackend->listTrashRoot($userA));
}
}

0 comments on commit a665bb7

Please sign in to comment.