Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like RoleService often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use RoleService, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 44 | class RoleService implements RoleServiceInterface |
||
| 45 | { |
||
| 46 | /** @var \eZ\Publish\API\Repository\Repository */ |
||
| 47 | protected $repository; |
||
| 48 | |||
| 49 | /** @var \eZ\Publish\SPI\Persistence\User\Handler */ |
||
| 50 | protected $userHandler; |
||
| 51 | |||
| 52 | /** @var \eZ\Publish\Core\Repository\Helper\LimitationService */ |
||
| 53 | protected $limitationService; |
||
| 54 | |||
| 55 | /** @var \eZ\Publish\Core\Repository\Helper\RoleDomainMapper */ |
||
| 56 | protected $roleDomainMapper; |
||
| 57 | |||
| 58 | /** @var array */ |
||
| 59 | protected $settings; |
||
| 60 | |||
| 61 | /** @var \eZ\Publish\API\Repository\PermissionResolver */ |
||
| 62 | private $permissionResolver; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Setups service with reference to repository object that created it & corresponding handler. |
||
| 66 | * |
||
| 67 | * @param \eZ\Publish\API\Repository\Repository $repository |
||
| 68 | * @param \eZ\Publish\SPI\Persistence\User\Handler $userHandler |
||
| 69 | * @param \eZ\Publish\Core\Repository\Helper\LimitationService $limitationService |
||
| 70 | * @param \eZ\Publish\Core\Repository\Helper\RoleDomainMapper $roleDomainMapper |
||
| 71 | * @param array $settings |
||
| 72 | */ |
||
| 73 | public function __construct( |
||
| 74 | RepositoryInterface $repository, |
||
| 75 | Handler $userHandler, |
||
| 76 | Helper\LimitationService $limitationService, |
||
| 77 | Helper\RoleDomainMapper $roleDomainMapper, |
||
| 78 | array $settings = [] |
||
| 79 | ) { |
||
| 80 | $this->repository = $repository; |
||
| 81 | $this->userHandler = $userHandler; |
||
| 82 | $this->limitationService = $limitationService; |
||
| 83 | $this->roleDomainMapper = $roleDomainMapper; |
||
| 84 | $this->settings = $settings; |
||
| 85 | $this->permissionResolver = $repository->getPermissionResolver(); |
||
| 86 | } |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Creates a new RoleDraft. |
||
| 90 | * |
||
| 91 | * @since 6.0 |
||
| 92 | * |
||
| 93 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to create a RoleDraft |
||
| 94 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 95 | * if the name of the role already exists or if limitation of the same type |
||
| 96 | * is repeated in the policy create struct or if limitation is not allowed on module/function |
||
| 97 | * @throws \eZ\Publish\API\Repository\Exceptions\LimitationValidationException if a policy limitation in the $roleCreateStruct is not valid |
||
| 98 | * |
||
| 99 | * @param \eZ\Publish\API\Repository\Values\User\RoleCreateStruct $roleCreateStruct |
||
| 100 | * |
||
| 101 | * @return \eZ\Publish\API\Repository\Values\User\RoleDraft |
||
| 102 | */ |
||
| 103 | public function createRole(APIRoleCreateStruct $roleCreateStruct) |
||
| 143 | |||
| 144 | /** |
||
| 145 | * Creates a new RoleDraft for an existing Role. |
||
| 146 | * |
||
| 147 | * @since 6.0 |
||
| 148 | * |
||
| 149 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to create a RoleDraft |
||
| 150 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the Role already has a RoleDraft that will need to be removed first |
||
| 151 | * |
||
| 152 | * @param \eZ\Publish\API\Repository\Values\User\Role $role |
||
| 153 | * |
||
| 154 | * @return \eZ\Publish\API\Repository\Values\User\RoleDraft |
||
| 155 | */ |
||
| 156 | View Code Duplication | public function createRoleDraft(APIRole $role) |
|
| 183 | |||
| 184 | /** |
||
| 185 | * Loads a RoleDraft for the given id. |
||
| 186 | * |
||
| 187 | * @since 6.0 |
||
| 188 | * |
||
| 189 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to read this RoleDraft |
||
| 190 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if a RoleDraft with the given id was not found |
||
| 191 | * |
||
| 192 | * @param mixed $id |
||
| 193 | * |
||
| 194 | * @return \eZ\Publish\API\Repository\Values\User\RoleDraft |
||
| 195 | */ |
||
| 196 | View Code Duplication | public function loadRoleDraft($id) |
|
| 208 | |||
| 209 | /** |
||
| 210 | * Loads a RoleDraft by the ID of the role it was created from. |
||
| 211 | * |
||
| 212 | * @param mixed $roleId ID of the role the draft was created from. |
||
| 213 | * |
||
| 214 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to read this role |
||
| 215 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if a RoleDraft with the given id was not found |
||
| 216 | * |
||
| 217 | * @return \eZ\Publish\API\Repository\Values\User\RoleDraft |
||
| 218 | */ |
||
| 219 | View Code Duplication | public function loadRoleDraftByRoleId($roleId) |
|
| 231 | |||
| 232 | /** |
||
| 233 | * Updates the properties of a RoleDraft. |
||
| 234 | * |
||
| 235 | * @since 6.0 |
||
| 236 | * |
||
| 237 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to update a RoleDraft |
||
| 238 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the identifier of the RoleDraft already exists |
||
| 239 | * |
||
| 240 | * @param \eZ\Publish\API\Repository\Values\User\RoleDraft $roleDraft |
||
| 241 | * @param \eZ\Publish\API\Repository\Values\User\RoleUpdateStruct $roleUpdateStruct |
||
| 242 | * |
||
| 243 | * @return \eZ\Publish\API\Repository\Values\User\RoleDraft |
||
| 244 | */ |
||
| 245 | public function updateRoleDraft(APIRoleDraft $roleDraft, RoleUpdateStruct $roleUpdateStruct) |
||
| 246 | { |
||
| 247 | if ($roleUpdateStruct->identifier !== null && !is_string($roleUpdateStruct->identifier)) { |
||
| 248 | throw new InvalidArgumentValue('identifier', $roleUpdateStruct->identifier, 'RoleUpdateStruct'); |
||
| 249 | } |
||
| 250 | |||
| 251 | $loadedRoleDraft = $this->loadRoleDraft($roleDraft->id); |
||
| 252 | |||
| 253 | if (!$this->permissionResolver->canUser('role', 'update', $loadedRoleDraft)) { |
||
| 254 | throw new UnauthorizedException('role', 'update'); |
||
| 255 | } |
||
| 256 | |||
| 257 | if ($roleUpdateStruct->identifier !== null) { |
||
| 258 | try { |
||
| 259 | /* Throw exception if: |
||
| 260 | * - A published role with the same identifier exists, AND |
||
| 261 | * - The ID of the published role does not match the original ID of the draft |
||
| 262 | */ |
||
| 263 | $existingSPIRole = $this->userHandler->loadRoleByIdentifier($roleUpdateStruct->identifier); |
||
| 264 | $SPIRoleDraft = $this->userHandler->loadRole($loadedRoleDraft->id, Role::STATUS_DRAFT); |
||
| 265 | if ($existingSPIRole->id != $SPIRoleDraft->originalId) { |
||
| 266 | throw new InvalidArgumentException( |
||
| 267 | '$roleUpdateStruct', |
||
| 268 | "Role '{$existingSPIRole->id}' with the specified identifier '{$roleUpdateStruct->identifier}' " . |
||
| 269 | 'already exists' |
||
| 270 | ); |
||
| 271 | } |
||
| 272 | } catch (APINotFoundException $e) { |
||
| 273 | // Do nothing |
||
| 274 | } |
||
| 275 | } |
||
| 276 | |||
| 277 | $this->repository->beginTransaction(); |
||
| 278 | try { |
||
| 279 | $this->userHandler->updateRole( |
||
| 280 | new SPIRoleUpdateStruct( |
||
| 281 | [ |
||
| 282 | 'id' => $loadedRoleDraft->id, |
||
| 283 | 'identifier' => $roleUpdateStruct->identifier ?: $loadedRoleDraft->identifier, |
||
| 284 | ] |
||
| 285 | ) |
||
| 286 | ); |
||
| 287 | $this->repository->commit(); |
||
| 288 | } catch (Exception $e) { |
||
| 289 | $this->repository->rollback(); |
||
| 290 | throw $e; |
||
| 291 | } |
||
| 292 | |||
| 293 | return $this->loadRoleDraft($loadedRoleDraft->id); |
||
| 294 | } |
||
| 295 | |||
| 296 | /** |
||
| 297 | * Adds a new policy to the RoleDraft. |
||
| 298 | * |
||
| 299 | * @since 6.0 |
||
| 300 | * |
||
| 301 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to add a policy |
||
| 302 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if limitation of the same type is repeated in policy create |
||
| 303 | * struct or if limitation is not allowed on module/function |
||
| 304 | * @throws \eZ\Publish\API\Repository\Exceptions\LimitationValidationException if a limitation in the $policyCreateStruct is not valid |
||
| 305 | * |
||
| 306 | * @param \eZ\Publish\API\Repository\Values\User\RoleDraft $roleDraft |
||
| 307 | * @param \eZ\Publish\API\Repository\Values\User\PolicyCreateStruct $policyCreateStruct |
||
| 308 | * |
||
| 309 | * @return \eZ\Publish\API\Repository\Values\User\RoleDraft |
||
| 310 | */ |
||
| 311 | public function addPolicyByRoleDraft(APIRoleDraft $roleDraft, APIPolicyCreateStruct $policyCreateStruct) |
||
| 312 | { |
||
| 313 | if (!is_string($policyCreateStruct->module) || empty($policyCreateStruct->module)) { |
||
| 314 | throw new InvalidArgumentValue('module', $policyCreateStruct->module, 'PolicyCreateStruct'); |
||
| 315 | } |
||
| 316 | |||
| 317 | if (!is_string($policyCreateStruct->function) || empty($policyCreateStruct->function)) { |
||
| 318 | throw new InvalidArgumentValue('function', $policyCreateStruct->function, 'PolicyCreateStruct'); |
||
| 319 | } |
||
| 320 | |||
| 321 | if ($policyCreateStruct->module === '*' && $policyCreateStruct->function !== '*') { |
||
| 322 | throw new InvalidArgumentValue('module', $policyCreateStruct->module, 'PolicyCreateStruct'); |
||
| 323 | } |
||
| 324 | |||
| 325 | if (!$this->permissionResolver->canUser('role', 'update', $roleDraft)) { |
||
| 326 | throw new UnauthorizedException('role', 'update'); |
||
| 327 | } |
||
| 328 | |||
| 329 | $loadedRoleDraft = $this->loadRoleDraft($roleDraft->id); |
||
| 330 | |||
| 331 | $limitations = $policyCreateStruct->getLimitations(); |
||
| 332 | $limitationValidationErrors = $this->validatePolicy( |
||
| 333 | $policyCreateStruct->module, |
||
| 334 | $policyCreateStruct->function, |
||
| 335 | $limitations |
||
| 336 | ); |
||
| 337 | if (!empty($limitationValidationErrors)) { |
||
| 338 | throw new LimitationValidationException($limitationValidationErrors); |
||
| 339 | } |
||
| 340 | |||
| 341 | $spiPolicy = $this->roleDomainMapper->buildPersistencePolicyObject( |
||
| 342 | $policyCreateStruct->module, |
||
| 343 | $policyCreateStruct->function, |
||
| 344 | $limitations |
||
| 345 | ); |
||
| 346 | |||
| 347 | $this->repository->beginTransaction(); |
||
| 348 | try { |
||
| 349 | $this->userHandler->addPolicyByRoleDraft($loadedRoleDraft->id, $spiPolicy); |
||
| 350 | $this->repository->commit(); |
||
| 351 | } catch (Exception $e) { |
||
| 352 | $this->repository->rollback(); |
||
| 353 | throw $e; |
||
| 354 | } |
||
| 355 | |||
| 356 | return $this->loadRoleDraft($loadedRoleDraft->id); |
||
| 357 | } |
||
| 358 | |||
| 359 | /** |
||
| 360 | * Removes a policy from a RoleDraft. |
||
| 361 | * |
||
| 362 | * @since 6.0 |
||
| 363 | * |
||
| 364 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to remove a policy |
||
| 365 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if policy does not belong to the given RoleDraft |
||
| 366 | * |
||
| 367 | * @param \eZ\Publish\API\Repository\Values\User\RoleDraft $roleDraft |
||
| 368 | * @param PolicyDraft $policyDraft the policy to remove from the RoleDraft |
||
| 369 | * |
||
| 370 | * @return APIRoleDraft if the authenticated user is not allowed to remove a policy |
||
| 371 | */ |
||
| 372 | public function removePolicyByRoleDraft(APIRoleDraft $roleDraft, PolicyDraft $policyDraft) |
||
| 386 | |||
| 387 | /** |
||
| 388 | * Updates the limitations of a policy. The module and function cannot be changed and |
||
| 389 | * the limitations are replaced by the ones in $roleUpdateStruct. |
||
| 390 | * |
||
| 391 | * @since 6.0 |
||
| 392 | * |
||
| 393 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to update a policy |
||
| 394 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if limitation of the same type is repeated in policy update |
||
| 395 | * struct or if limitation is not allowed on module/function |
||
| 396 | * @throws \eZ\Publish\API\Repository\Exceptions\LimitationValidationException if a limitation in the $policyUpdateStruct is not valid |
||
| 397 | * |
||
| 398 | * @param \eZ\Publish\API\Repository\Values\User\RoleDraft $roleDraft |
||
| 399 | * @param \eZ\Publish\API\Repository\Values\User\PolicyDraft $policy |
||
| 400 | * @param \eZ\Publish\API\Repository\Values\User\PolicyUpdateStruct $policyUpdateStruct |
||
| 401 | * |
||
| 402 | * @return \eZ\Publish\API\Repository\Values\User\PolicyDraft |
||
| 403 | */ |
||
| 404 | public function updatePolicyByRoleDraft(APIRoleDraft $roleDraft, PolicyDraft $policy, APIPolicyUpdateStruct $policyUpdateStruct) |
||
| 452 | |||
| 453 | /** |
||
| 454 | * Deletes the given RoleDraft. |
||
| 455 | * |
||
| 456 | * @since 6.0 |
||
| 457 | * |
||
| 458 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to delete this RoleDraft |
||
| 459 | * |
||
| 460 | * @param \eZ\Publish\API\Repository\Values\User\RoleDraft $roleDraft |
||
| 461 | */ |
||
| 462 | public function deleteRoleDraft(APIRoleDraft $roleDraft) |
||
| 475 | |||
| 476 | /** |
||
| 477 | * Publishes a given RoleDraft. |
||
| 478 | * |
||
| 479 | * @since 6.0 |
||
| 480 | * |
||
| 481 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to publish this RoleDraft |
||
| 482 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the role draft cannot be loaded |
||
| 483 | * |
||
| 484 | * @param \eZ\Publish\API\Repository\Values\User\RoleDraft $roleDraft |
||
| 485 | */ |
||
| 486 | public function publishRoleDraft(APIRoleDraft $roleDraft) |
||
| 511 | |||
| 512 | /** |
||
| 513 | * Deletes a policy. |
||
| 514 | * |
||
| 515 | * Used by {@link removePolicy()} and {@link deletePolicy()} |
||
| 516 | * |
||
| 517 | * @param APIPolicy $policy |
||
| 518 | * |
||
| 519 | * @throws \Exception |
||
| 520 | */ |
||
| 521 | protected function internalDeletePolicy(APIPolicy $policy) |
||
| 532 | |||
| 533 | /** |
||
| 534 | * Loads a role for the given id. |
||
| 535 | * |
||
| 536 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to read this role |
||
| 537 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if a role with the given id was not found |
||
| 538 | * |
||
| 539 | * @param mixed $id |
||
| 540 | * |
||
| 541 | * @return \eZ\Publish\API\Repository\Values\User\Role |
||
| 542 | */ |
||
| 543 | View Code Duplication | public function loadRole($id) |
|
| 555 | |||
| 556 | /** |
||
| 557 | * Loads a role for the given identifier. |
||
| 558 | * |
||
| 559 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to read this role |
||
| 560 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if a role with the given name was not found |
||
| 561 | * |
||
| 562 | * @param string $identifier |
||
| 563 | * |
||
| 564 | * @return \eZ\Publish\API\Repository\Values\User\Role |
||
| 565 | */ |
||
| 566 | View Code Duplication | public function loadRoleByIdentifier($identifier) |
|
| 582 | |||
| 583 | /** |
||
| 584 | * Loads all roles, excluding the ones the current user is not allowed to read. |
||
| 585 | * |
||
| 586 | * @return \eZ\Publish\API\Repository\Values\User\Role[] |
||
| 587 | */ |
||
| 588 | public function loadRoles() |
||
| 606 | |||
| 607 | /** |
||
| 608 | * Deletes the given role. |
||
| 609 | * |
||
| 610 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to delete this role |
||
| 611 | * |
||
| 612 | * @param \eZ\Publish\API\Repository\Values\User\Role $role |
||
| 613 | */ |
||
| 614 | View Code Duplication | public function deleteRole(APIRole $role) |
|
| 631 | |||
| 632 | /** |
||
| 633 | * Assigns a role to the given user group. |
||
| 634 | * |
||
| 635 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to assign a role |
||
| 636 | * @throws \eZ\Publish\API\Repository\Exceptions\LimitationValidationException if $roleLimitation is not valid |
||
| 637 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If assignment already exists |
||
| 638 | * |
||
| 639 | * @param \eZ\Publish\API\Repository\Values\User\Role $role |
||
| 640 | * @param \eZ\Publish\API\Repository\Values\User\UserGroup $userGroup |
||
| 641 | * @param \eZ\Publish\API\Repository\Values\User\Limitation\RoleLimitation $roleLimitation an optional role limitation (which is either a subtree limitation or section limitation) |
||
| 642 | */ |
||
| 643 | View Code Duplication | public function assignRoleToUserGroup(APIRole $role, UserGroup $userGroup, RoleLimitation $roleLimitation = null) |
|
| 679 | |||
| 680 | /** |
||
| 681 | * Assigns a role to the given user. |
||
| 682 | * |
||
| 683 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to assign a role |
||
| 684 | * @throws \eZ\Publish\API\Repository\Exceptions\LimitationValidationException if $roleLimitation is not valid |
||
| 685 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If assignment already exists |
||
| 686 | * |
||
| 687 | * @param \eZ\Publish\API\Repository\Values\User\Role $role |
||
| 688 | * @param \eZ\Publish\API\Repository\Values\User\User $user |
||
| 689 | * @param \eZ\Publish\API\Repository\Values\User\Limitation\RoleLimitation $roleLimitation an optional role limitation (which is either a subtree limitation or section limitation) |
||
| 690 | */ |
||
| 691 | View Code Duplication | public function assignRoleToUser(APIRole $role, User $user, RoleLimitation $roleLimitation = null) |
|
| 727 | |||
| 728 | /** |
||
| 729 | * Removes the given role assignment. |
||
| 730 | * |
||
| 731 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to remove a role assignment |
||
| 732 | * |
||
| 733 | * @param \eZ\Publish\API\Repository\Values\User\RoleAssignment $roleAssignment |
||
| 734 | */ |
||
| 735 | View Code Duplication | public function removeRoleAssignment(RoleAssignment $roleAssignment) |
|
| 752 | |||
| 753 | /** |
||
| 754 | * Loads a role assignment for the given id. |
||
| 755 | * |
||
| 756 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to read this role |
||
| 757 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException If the role assignment was not found |
||
| 758 | * |
||
| 759 | * @param mixed $roleAssignmentId |
||
| 760 | * |
||
| 761 | * @return \eZ\Publish\API\Repository\Values\User\RoleAssignment |
||
| 762 | */ |
||
| 763 | public function loadRoleAssignment($roleAssignmentId) |
||
| 799 | |||
| 800 | /** |
||
| 801 | * Returns the assigned user and user groups to this role. |
||
| 802 | * |
||
| 803 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to read a role |
||
| 804 | * |
||
| 805 | * @param \eZ\Publish\API\Repository\Values\User\Role $role |
||
| 806 | * |
||
| 807 | * @return \eZ\Publish\API\Repository\Values\User\RoleAssignment[] |
||
| 808 | */ |
||
| 809 | public function getRoleAssignments(APIRole $role) |
||
| 845 | |||
| 846 | /** |
||
| 847 | * @see \eZ\Publish\API\Repository\RoleService::getRoleAssignmentsForUser() |
||
| 848 | */ |
||
| 849 | public function getRoleAssignmentsForUser(User $user, $inherited = false) |
||
| 878 | |||
| 879 | /** |
||
| 880 | * Returns the roles assigned to the given user group, excluding the ones the current user is not allowed to read. |
||
| 881 | * |
||
| 882 | * @param \eZ\Publish\API\Repository\Values\User\UserGroup $userGroup |
||
| 883 | * |
||
| 884 | * @return \eZ\Publish\API\Repository\Values\User\UserGroupRoleAssignment[] |
||
| 885 | */ |
||
| 886 | public function getRoleAssignmentsForUserGroup(UserGroup $userGroup) |
||
| 904 | |||
| 905 | /** |
||
| 906 | * Instantiates a role create class. |
||
| 907 | * |
||
| 908 | * @param string $name |
||
| 909 | * |
||
| 910 | * @return \eZ\Publish\API\Repository\Values\User\RoleCreateStruct |
||
| 911 | */ |
||
| 912 | public function newRoleCreateStruct($name) |
||
| 921 | |||
| 922 | /** |
||
| 923 | * Instantiates a policy create class. |
||
| 924 | * |
||
| 925 | * @param string $module |
||
| 926 | * @param string $function |
||
| 927 | * |
||
| 928 | * @return \eZ\Publish\API\Repository\Values\User\PolicyCreateStruct |
||
| 929 | */ |
||
| 930 | public function newPolicyCreateStruct($module, $function) |
||
| 940 | |||
| 941 | /** |
||
| 942 | * Instantiates a policy update class. |
||
| 943 | * |
||
| 944 | * @return \eZ\Publish\API\Repository\Values\User\PolicyUpdateStruct |
||
| 945 | */ |
||
| 946 | public function newPolicyUpdateStruct() |
||
| 954 | |||
| 955 | /** |
||
| 956 | * Instantiates a policy update class. |
||
| 957 | * |
||
| 958 | * @return \eZ\Publish\API\Repository\Values\User\RoleUpdateStruct |
||
| 959 | */ |
||
| 960 | public function newRoleUpdateStruct() |
||
| 964 | |||
| 965 | /** |
||
| 966 | * Returns the LimitationType registered with the given identifier. |
||
| 967 | * |
||
| 968 | * Returns the correct implementation of API Limitation value object |
||
| 969 | * based on provided identifier |
||
| 970 | * |
||
| 971 | * @param string $identifier |
||
| 972 | * |
||
| 973 | * @return \eZ\Publish\SPI\Limitation\Type |
||
| 974 | * |
||
| 975 | * @throws \RuntimeException if there is no LimitationType with $identifier |
||
| 976 | */ |
||
| 977 | public function getLimitationType($identifier) |
||
| 981 | |||
| 982 | /** |
||
| 983 | * Returns the LimitationType's assigned to a given module/function. |
||
| 984 | * |
||
| 985 | * Typically used for: |
||
| 986 | * - Internal validation limitation value use on Policies |
||
| 987 | * - Role admin gui for editing policy limitations incl list limitation options via valueSchema() |
||
| 988 | * |
||
| 989 | * @param string $module Legacy name of "controller", it's a unique identifier like "content" |
||
| 990 | * @param string $function Legacy name of a controller "action", it's a unique within the controller like "read" |
||
| 991 | * |
||
| 992 | * @return \eZ\Publish\SPI\Limitation\Type[] |
||
| 993 | * |
||
| 994 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException If module/function to limitation type mapping |
||
| 995 | * refers to a non existing identifier. |
||
| 996 | */ |
||
| 997 | public function getLimitationTypesByModuleFunction($module, $function) |
||
| 1018 | |||
| 1019 | /** |
||
| 1020 | * Validates Policies and Limitations in Role create struct. |
||
| 1021 | * |
||
| 1022 | * @uses ::validatePolicy() |
||
| 1023 | * |
||
| 1024 | * @param \eZ\Publish\API\Repository\Values\User\RoleCreateStruct $roleCreateStruct |
||
| 1025 | * |
||
| 1026 | * @return \eZ\Publish\Core\FieldType\ValidationError[][][] |
||
| 1027 | */ |
||
| 1028 | protected function validateRoleCreateStruct(APIRoleCreateStruct $roleCreateStruct) |
||
| 1045 | |||
| 1046 | /** |
||
| 1047 | * Validates Policy context: Limitations on a module and function. |
||
| 1048 | * |
||
| 1049 | * @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentException If the same limitation is repeated or if |
||
| 1050 | * limitation is not allowed on module/function |
||
| 1051 | * |
||
| 1052 | * @param string $module |
||
| 1053 | * @param string $function |
||
| 1054 | * @param \eZ\Publish\API\Repository\Values\User\Limitation[] $limitations |
||
| 1055 | * |
||
| 1056 | * @return \eZ\Publish\Core\FieldType\ValidationError[][] |
||
| 1057 | */ |
||
| 1058 | protected function validatePolicy($module, $function, array $limitations) |
||
| 1083 | |||
| 1084 | /** |
||
| 1085 | * Validate that assignments not already exists and filter validations against existing. |
||
| 1086 | * |
||
| 1087 | * @param mixed $contentId |
||
| 1088 | * @param SPIRole $spiRole |
||
| 1089 | * @param array|null $limitation |
||
| 1090 | * |
||
| 1091 | * @return array[]|null Filtered version of $limitation |
||
| 1092 | * |
||
| 1093 | * @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentException If assignment already exists |
||
| 1094 | */ |
||
| 1095 | protected function checkAssignmentAndFilterLimitationValues($contentId, SPIRole $spiRole, array $limitation = null) |
||
| 1137 | } |
||
| 1138 |