|
22 | 22 | use eZ\Publish\API\Repository\Values\Content\Query; |
23 | 23 | use eZ\Publish\API\Repository\Values\Content\Search\SearchHit; |
24 | 24 | use eZ\Publish\API\Repository\Values\Content\URLAlias; |
| 25 | +use eZ\Publish\API\Repository\Values\User\Limitation\SubtreeLimitation; |
25 | 26 | use eZ\Publish\Core\Repository\Values\Content\ContentUpdateStruct; |
26 | 27 |
|
27 | 28 | /** |
@@ -3471,6 +3472,69 @@ public function testMoveSubtreeKeepsContentHiddenOnChildren(): void |
3471 | 3472 | } |
3472 | 3473 | } |
3473 | 3474 |
|
| 3475 | + /** |
| 3476 | + * Test validating whether content that is being moved is still allowed to be moved when one of its locations |
| 3477 | + * is inaccessible by a current user, however, when moved location is accessible. |
| 3478 | + * |
| 3479 | + * @covers \eZ\Publish\API\Repository\LocationService::moveSubtree |
| 3480 | + * |
| 3481 | + * @throws \eZ\Publish\API\Repository\Exceptions\Exception |
| 3482 | + */ |
| 3483 | + public function testMoveSubtreeContentWithMultipleLocationsAndOneOfThemInaccessible(): void |
| 3484 | + { |
| 3485 | + $repository = $this->getRepository(); |
| 3486 | + $locationService = $repository->getLocationService(); |
| 3487 | + $permissionResolver = $repository->getPermissionResolver(); |
| 3488 | + |
| 3489 | + $folder = $this->publishContentWithParentLocation('Parent folder', 2); |
| 3490 | + $accessibleFolder = $this->publishContentWithParentLocation('Accessible folder', 2); |
| 3491 | + $subFolder = $this->publishContentWithParentLocation( |
| 3492 | + 'Sub folder', |
| 3493 | + $folder->contentInfo->mainLocationId |
| 3494 | + ); |
| 3495 | + $contentToBeMoved = $this->publishContentWithParentLocation( |
| 3496 | + 'Target folder', |
| 3497 | + $subFolder->contentInfo->mainLocationId |
| 3498 | + ); |
| 3499 | + $forbiddenContent = $this->publishContentWithParentLocation('Forbidden folder', 2); |
| 3500 | + |
| 3501 | + // Add second location (parent 'Forbidden folder') to 'Target content' in folder that user won't have access to |
| 3502 | + $locationService->createLocation( |
| 3503 | + $contentToBeMoved->contentInfo, |
| 3504 | + $locationService->newLocationCreateStruct($forbiddenContent->contentInfo->mainLocationId) |
| 3505 | + ); |
| 3506 | + |
| 3507 | + $folderLocation = $locationService->loadLocation($folder->contentInfo->mainLocationId); |
| 3508 | + $accessibleFolderLocation = $locationService->loadLocation($accessibleFolder->contentInfo->mainLocationId); |
| 3509 | + |
| 3510 | + // Set user that cannot access 'Forbidden folder' |
| 3511 | + $user = $this->createUserWithPolicies( |
| 3512 | + 'user', |
| 3513 | + [ |
| 3514 | + ['module' => 'content', 'function' => 'read'], |
| 3515 | + ['module' => 'content', 'function' => 'create'], |
| 3516 | + ], |
| 3517 | + new SubtreeLimitation( |
| 3518 | + ['limitationValues' => [ |
| 3519 | + $folderLocation->getPathString(), |
| 3520 | + $accessibleFolderLocation->getPathString(), |
| 3521 | + ], |
| 3522 | + ] |
| 3523 | + ) |
| 3524 | + ); |
| 3525 | + $permissionResolver->setCurrentUserReference($user); |
| 3526 | + |
| 3527 | + // Move Parent folder/Sub folder/Target folder to location of ID = 2 |
| 3528 | + $locationService->moveSubtree( |
| 3529 | + $contentToBeMoved->contentInfo->getMainLocation(), |
| 3530 | + $accessibleFolderLocation |
| 3531 | + ); |
| 3532 | + |
| 3533 | + $targetContentMainLocation = $locationService->loadLocation($contentToBeMoved->contentInfo->mainLocationId); |
| 3534 | + |
| 3535 | + self::assertSame($targetContentMainLocation->parentLocationId, $accessibleFolderLocation->id); |
| 3536 | + } |
| 3537 | + |
3474 | 3538 | public function testGetSubtreeSize(): Location |
3475 | 3539 | { |
3476 | 3540 | $repository = $this->getRepository(); |
|
0 commit comments