|
19 | 19 | use OCA\GroupFolders\Folder\FolderManager;
|
20 | 20 | use OCA\GroupFolders\Mount\GroupFolderStorage;
|
21 | 21 | use OCA\GroupFolders\Trash\TrashBackend;
|
| 22 | +use OCP\Constants; |
22 | 23 | use OCP\Files\Folder;
|
23 | 24 | use OCP\Files\IRootFolder;
|
24 | 25 | use OCP\IUser;
|
| 26 | +use OCP\Server; |
| 27 | +use OCP\Share; |
25 | 28 | use Test\TestCase;
|
26 | 29 | use Test\Traits\UserTrait;
|
27 | 30 |
|
@@ -211,4 +214,72 @@ public function testHideDeletedTrashItemInDeletedParentFolderAcl(): void {
|
211 | 214 |
|
212 | 215 | $this->logout();
|
213 | 216 | }
|
| 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('C'); |
| 229 | + $groupBackend->addToGroup('A', 'C'); |
| 230 | + $groupBackend->addToGroup('B', 'C'); |
| 231 | + $this->assertCount(2, $groupBackend->usersInGroup('C')); |
| 232 | + |
| 233 | + $groupFolderId = $this->folderManager->createFolder('D'); |
| 234 | + $this->folderManager->setFolderACL($groupFolderId, true); |
| 235 | + $this->folderManager->addApplicableGroup($groupFolderId, 'C'); |
| 236 | + $this->folderManager->setGroupPermissions($groupFolderId, 'C', Constants::PERMISSION_ALL); |
| 237 | + $this->assertInstanceOf(Folder::class, $userAFolder->get('D')); |
| 238 | + $this->assertInstanceOf(Folder::class, $userBFolder->get('D')); |
| 239 | + |
| 240 | + $this->loginAsUser('A'); |
| 241 | + $userAFolder->newFolder('D/E/F'); |
| 242 | + $userAFolder->newFile('D/E/F/G', 'foo'); |
| 243 | + |
| 244 | + $this->ruleManager->saveRule(new Rule(new UserMapping('group', 'C'), $userAFolder->get('D/E')->getId(), Constants::PERMISSION_READ, 0)); |
| 245 | + $this->ruleManager->saveRule(new Rule(new UserMapping('user', 'A'), $userAFolder->get('D/E')->getId(), Constants::PERMISSION_ALL, Constants::PERMISSION_READ | Constants::PERMISSION_UPDATE | Constants::PERMISSION_CREATE)); |
| 246 | + $this->ruleManager->saveRule(new Rule(new UserMapping('user', 'A'), $userAFolder->get('D/E/F')->getId(), Constants::PERMISSION_ALL, Constants::PERMISSION_ALL)); |
| 247 | + |
| 248 | + $folderShare = $shareManager->newShare(); |
| 249 | + $folderShare->setShareType(Share\IShare::TYPE_USER); |
| 250 | + $folderShare->setSharedWith('B'); |
| 251 | + $folderShare->setSharedBy('A'); |
| 252 | + $folderShare->setPermissions(Constants::PERMISSION_ALL); |
| 253 | + $folderShare->setNode($userAFolder->get('D/E/F')); |
| 254 | + $folderShare = $shareManager->createShare($folderShare); |
| 255 | + $this->assertNotEmpty($folderShare->getId()); |
| 256 | + |
| 257 | + $fileShare = $shareManager->newShare(); |
| 258 | + $fileShare->setShareType(Share\IShare::TYPE_USER); |
| 259 | + $fileShare->setSharedWith('B'); |
| 260 | + $fileShare->setSharedBy('A'); |
| 261 | + $fileShare->setPermissions(19); |
| 262 | + $fileShare->setNode($userAFolder->get('D/E/F/G')); |
| 263 | + $fileShare = $shareManager->createShare($fileShare); |
| 264 | + $this->assertNotEmpty($fileShare->getId()); |
| 265 | + |
| 266 | + $this->loginAsUser('B'); |
| 267 | + $this->assertTrue($userBFolder->get('F/G')->isDeletable()); |
| 268 | + $userBFolder->get('F/G')->delete(); |
| 269 | + |
| 270 | + $this->assertFalse($userAFolder->nodeExists('D/E/F/G')); |
| 271 | + |
| 272 | + $trashedOfUserA = $this->trashBackend->listTrashRoot($userA); |
| 273 | + $this->assertCount(1, $trashedOfUserA); |
| 274 | + // Ensure original location inside share is correct |
| 275 | + $this->assertSame('D/E/F/G', $trashedOfUserA[0]->getOriginalLocation()); |
| 276 | + |
| 277 | + $trashedOfUserB = $this->trashBackend->listTrashRoot($userB); |
| 278 | + // Deleting share only unshares it, so no trash here |
| 279 | + $this->assertCount(0, $trashedOfUserB); |
| 280 | + |
| 281 | + // Restoring to original location works |
| 282 | + $this->trashBackend->restoreItem($trashedOfUserA[0]); |
| 283 | + $this->assertTrue($userAFolder->nodeExists('D/E/F/G')); |
| 284 | + } |
214 | 285 | }
|
0 commit comments