| @@ 85-132 (lines=48) @@ | ||
| 82 | * |
|
| 83 | * @see \eZ\Publish\API\Repository\Values\User\Limitation\NewSectionLimitation |
|
| 84 | */ |
|
| 85 | public function testNewSectionLimitationForbid() |
|
| 86 | { |
|
| 87 | $this->expectException(\eZ\Publish\API\Repository\Exceptions\UnauthorizedException::class); |
|
| 88 | ||
| 89 | $repository = $this->getRepository(); |
|
| 90 | $permissionResolver = $repository->getPermissionResolver(); |
|
| 91 | ||
| 92 | $contentId = $this->generateId('content', 58); |
|
| 93 | $sectionId = $this->generateId('section', 6); |
|
| 94 | $otherSectionId = $this->generateId('section', 1); |
|
| 95 | /* BEGIN: Use Case */ |
|
| 96 | $user = $this->createUserVersion1(); |
|
| 97 | ||
| 98 | $roleService = $repository->getRoleService(); |
|
| 99 | ||
| 100 | $policyCreate = $roleService->newPolicyCreateStruct('section', 'assign'); |
|
| 101 | $policyCreate->addLimitation( |
|
| 102 | new NewSectionLimitation( |
|
| 103 | ['limitationValues' => [$sectionId]] |
|
| 104 | ) |
|
| 105 | ); |
|
| 106 | ||
| 107 | $role = $roleService->loadRoleByIdentifier('Editor'); |
|
| 108 | $roleDraft = $roleService->createRoleDraft($role); |
|
| 109 | $roleService->addPolicyByRoleDraft( |
|
| 110 | $roleDraft, |
|
| 111 | $policyCreate |
|
| 112 | ); |
|
| 113 | $roleService->addPolicyByRoleDraft( |
|
| 114 | $roleDraft, |
|
| 115 | $roleService->newPolicyCreateStruct('section', 'view') |
|
| 116 | ); |
|
| 117 | $roleService->publishRoleDraft($roleDraft); |
|
| 118 | ||
| 119 | $roleService->assignRoleToUser($role, $user); |
|
| 120 | ||
| 121 | $permissionResolver->setCurrentUserReference($user); |
|
| 122 | ||
| 123 | $contentService = $repository->getContentService(); |
|
| 124 | $contentInfo = $contentService->loadContentInfo($contentId); |
|
| 125 | ||
| 126 | $sectionService = $repository->getSectionService(); |
|
| 127 | $sectionService->assignSection( |
|
| 128 | $contentInfo, |
|
| 129 | $sectionService->loadSection($otherSectionId) |
|
| 130 | ); |
|
| 131 | /* END: Use Case */ |
|
| 132 | } |
|
| 133 | } |
|
| 134 | ||
| @@ 96-150 (lines=55) @@ | ||
| 93 | * |
|
| 94 | * @see eZ\Publish\API\Repository\Values\User\Limitation\ParentUserGroupLimitation |
|
| 95 | */ |
|
| 96 | public function testParentUserGroupLimitationForbid() |
|
| 97 | { |
|
| 98 | $this->expectException(\eZ\Publish\API\Repository\Exceptions\UnauthorizedException::class); |
|
| 99 | ||
| 100 | $repository = $this->getRepository(); |
|
| 101 | $userService = $repository->getUserService(); |
|
| 102 | $permissionResolver = $repository->getPermissionResolver(); |
|
| 103 | ||
| 104 | $parentUserGroupId = $this->generateId('location', 4); |
|
| 105 | /* BEGIN: Use Case */ |
|
| 106 | $user = $this->createUserVersion1(); |
|
| 107 | ||
| 108 | $userGroupCreate = $userService->newUserGroupCreateStruct('eng-GB'); |
|
| 109 | $userGroupCreate->setField('name', 'Shared wiki'); |
|
| 110 | ||
| 111 | $userGroup = $userService->createUserGroup( |
|
| 112 | $userGroupCreate, |
|
| 113 | $userService->loadUserGroup( |
|
| 114 | $parentUserGroupId |
|
| 115 | ) |
|
| 116 | ); |
|
| 117 | ||
| 118 | // Assign only example user to new group |
|
| 119 | $userService->assignUserToUserGroup($user, $userGroup); |
|
| 120 | ||
| 121 | $roleService = $repository->getRoleService(); |
|
| 122 | ||
| 123 | $policyCreate = $roleService->newPolicyCreateStruct('content', 'create'); |
|
| 124 | $policyCreate->addLimitation( |
|
| 125 | new ParentUserGroupLimitation( |
|
| 126 | [ |
|
| 127 | 'limitationValues' => [true], |
|
| 128 | ] |
|
| 129 | ) |
|
| 130 | ); |
|
| 131 | ||
| 132 | $role = $roleService->loadRoleByIdentifier('Editor'); |
|
| 133 | $roleDraft = $roleService->createRoleDraft($role); |
|
| 134 | $roleService->addPolicyByRoleDraft( |
|
| 135 | $roleDraft, |
|
| 136 | $policyCreate |
|
| 137 | ); |
|
| 138 | $roleService->addPolicyByRoleDraft( |
|
| 139 | $roleDraft, |
|
| 140 | $roleService->newPolicyCreateStruct('content', 'read') |
|
| 141 | ); |
|
| 142 | $roleService->publishRoleDraft($roleDraft); |
|
| 143 | ||
| 144 | $roleService->assignRoleToUserGroup($role, $userGroup); |
|
| 145 | ||
| 146 | $permissionResolver->setCurrentUserReference($user); |
|
| 147 | ||
| 148 | $this->createWikiPageDraft(); |
|
| 149 | /* END: Use Case */ |
|
| 150 | } |
|
| 151 | } |
|
| 152 | ||