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 |
||
| 47 | class RoleService implements RoleServiceInterface |
||
| 48 | { |
||
| 49 | /** @var \eZ\Publish\API\Repository\Repository */ |
||
| 50 | protected $repository; |
||
| 51 | |||
| 52 | /** @var \eZ\Publish\SPI\Persistence\User\Handler */ |
||
| 53 | protected $userHandler; |
||
| 54 | |||
| 55 | /** @var \eZ\Publish\Core\Repository\Helper\LimitationService */ |
||
| 56 | protected $limitationService; |
||
| 57 | |||
| 58 | /** @var \eZ\Publish\Core\Repository\Helper\RoleDomainMapper */ |
||
| 59 | protected $roleDomainMapper; |
||
| 60 | |||
| 61 | /** @var array */ |
||
| 62 | protected $settings; |
||
| 63 | |||
| 64 | /** @var \eZ\Publish\API\Repository\PermissionResolver */ |
||
| 65 | private $permissionResolver; |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Setups service with reference to repository object that created it & corresponding handler. |
||
| 69 | * |
||
| 70 | * @param \eZ\Publish\API\Repository\Repository $repository |
||
| 71 | * @param \eZ\Publish\SPI\Persistence\User\Handler $userHandler |
||
| 72 | * @param \eZ\Publish\Core\Repository\Helper\LimitationService $limitationService |
||
| 73 | * @param \eZ\Publish\Core\Repository\Helper\RoleDomainMapper $roleDomainMapper |
||
| 74 | * @param array $settings |
||
| 75 | */ |
||
| 76 | public function __construct( |
||
| 90 | |||
| 91 | /** |
||
| 92 | * Creates a new RoleDraft. |
||
| 93 | * |
||
| 94 | * @since 6.0 |
||
| 95 | * |
||
| 96 | * @param \eZ\Publish\API\Repository\Values\User\RoleCreateStruct $roleCreateStruct |
||
| 97 | * |
||
| 98 | * @return \eZ\Publish\API\Repository\Values\User\RoleDraft |
||
| 99 | * |
||
| 100 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 101 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the name of the role already exists or if limitation of the same type |
||
| 102 | * is repeated in the policy create struct or if limitation is not allowed on module/function |
||
| 103 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to create a RoleDraft |
||
| 104 | * @throws \eZ\Publish\API\Repository\Exceptions\LimitationValidationException if a policy limitation in the $roleCreateStruct is not valid |
||
| 105 | */ |
||
| 106 | public function createRole(APIRoleCreateStruct $roleCreateStruct): APIRoleDraft |
||
| 146 | |||
| 147 | /** |
||
| 148 | * Creates a new RoleDraft for an existing Role. |
||
| 149 | * |
||
| 150 | * @since 6.0 |
||
| 151 | * |
||
| 152 | * @param \eZ\Publish\API\Repository\Values\User\Role $role |
||
| 153 | * |
||
| 154 | * @return \eZ\Publish\API\Repository\Values\User\RoleDraft |
||
| 155 | * |
||
| 156 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 157 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the Role already has a RoleDraft that will need to be removed first |
||
| 158 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to create a RoleDraft |
||
| 159 | */ |
||
| 160 | public function createRoleDraft(APIRole $role): APIRoleDraft |
||
| 187 | |||
| 188 | /** |
||
| 189 | * Copies an existing Role. |
||
| 190 | * |
||
| 191 | * @since 8.0 |
||
| 192 | * |
||
| 193 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to copy a Role |
||
| 194 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the name of the role already exists or if limitation of the same type |
||
| 195 | * is repeated in the policy create struct or if limitation is not allowed on module/function |
||
| 196 | * @throws \eZ\Publish\API\Repository\Exceptions\LimitationValidationException if a policy limitation in the $roleCopyStruct is not valid |
||
| 197 | * |
||
| 198 | * @param \eZ\Publish\API\Repository\Values\User\Role $role |
||
| 199 | * @param \eZ\Publish\API\Repository\Values\User\RoleCopyStruct $roleCopyStruct |
||
| 200 | * |
||
| 201 | * @return \eZ\Publish\API\Repository\Values\User\Role |
||
| 202 | */ |
||
| 203 | public function copyRole(APIRole $role, APIRoleCopyStruct $roleCopyStruct): APIRole |
||
| 254 | |||
| 255 | /** |
||
| 256 | * Loads a RoleDraft for the given id. |
||
| 257 | * |
||
| 258 | * @since 6.0 |
||
| 259 | * |
||
| 260 | * @param int $id |
||
| 261 | * |
||
| 262 | * @return \eZ\Publish\API\Repository\Values\User\RoleDraft |
||
| 263 | * |
||
| 264 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 265 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 266 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if a RoleDraft with the given id was not found |
||
| 267 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to create a RoleDraft |
||
| 268 | */ |
||
| 269 | public function loadRoleDraft(int $id): APIRoleDraft |
||
| 281 | |||
| 282 | /** |
||
| 283 | * Loads a RoleDraft by the ID of the role it was created from. |
||
| 284 | * |
||
| 285 | * @param int $roleId ID of the role the draft was created from. |
||
| 286 | * |
||
| 287 | * @return \eZ\Publish\API\Repository\Values\User\RoleDraft |
||
| 288 | * |
||
| 289 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 290 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 291 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if a RoleDraft with the given id was not found |
||
| 292 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to read this role |
||
| 293 | */ |
||
| 294 | public function loadRoleDraftByRoleId(int $roleId): APIRoleDraft |
||
| 306 | |||
| 307 | /** |
||
| 308 | * Updates the properties of a RoleDraft. |
||
| 309 | * |
||
| 310 | * @since 6.0 |
||
| 311 | * |
||
| 312 | * @param \eZ\Publish\API\Repository\Values\User\RoleDraft $roleDraft |
||
| 313 | * @param \eZ\Publish\API\Repository\Values\User\RoleUpdateStruct $roleUpdateStruct |
||
| 314 | * |
||
| 315 | * @return \eZ\Publish\API\Repository\Values\User\RoleDraft |
||
| 316 | * |
||
| 317 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 318 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the identifier of the RoleDraft already exists |
||
| 319 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 320 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to update a RoleDraft |
||
| 321 | */ |
||
| 322 | public function updateRoleDraft(APIRoleDraft $roleDraft, RoleUpdateStruct $roleUpdateStruct): APIRoleDraft |
||
| 372 | |||
| 373 | /** |
||
| 374 | * Adds a new policy to the RoleDraft. |
||
| 375 | * |
||
| 376 | * @since 6.0 |
||
| 377 | * |
||
| 378 | * @param \eZ\Publish\API\Repository\Values\User\RoleDraft $roleDraft |
||
| 379 | * @param \eZ\Publish\API\Repository\Values\User\PolicyCreateStruct $policyCreateStruct |
||
| 380 | * |
||
| 381 | * @return \eZ\Publish\API\Repository\Values\User\RoleDraft |
||
| 382 | * |
||
| 383 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 384 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if limitation of the same type is repeated in policy create |
||
| 385 | * struct or if limitation is not allowed on module/function |
||
| 386 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 387 | * @throws \eZ\Publish\API\Repository\Exceptions\LimitationValidationException if a limitation in the $policyCreateStruct is not valid |
||
| 388 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to add a policy |
||
| 389 | */ |
||
| 390 | public function addPolicyByRoleDraft(APIRoleDraft $roleDraft, APIPolicyCreateStruct $policyCreateStruct): APIRoleDraft |
||
| 437 | |||
| 438 | /** |
||
| 439 | * Removes a policy from a RoleDraft. |
||
| 440 | * |
||
| 441 | * @since 6.0 |
||
| 442 | * |
||
| 443 | * @param \eZ\Publish\API\Repository\Values\User\RoleDraft $roleDraft |
||
| 444 | * @param \eZ\Publish\API\Repository\Values\User\PolicyDraft $policyDraft the policy to remove from the RoleDraft |
||
| 445 | * |
||
| 446 | * @return \eZ\Publish\API\Repository\Values\User\RoleDraft |
||
| 447 | * |
||
| 448 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 449 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if policy does not belong to the given RoleDraft |
||
| 450 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 451 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to remove a policy |
||
| 452 | */ |
||
| 453 | public function removePolicyByRoleDraft(APIRoleDraft $roleDraft, PolicyDraft $policyDraft): APIRoleDraft |
||
| 467 | |||
| 468 | /** |
||
| 469 | * Updates the limitations of a policy. The module and function cannot be changed and |
||
| 470 | * the limitations are replaced by the ones in $roleUpdateStruct. |
||
| 471 | * |
||
| 472 | * @since 6.0 |
||
| 473 | * |
||
| 474 | * @param \eZ\Publish\API\Repository\Values\User\RoleDraft $roleDraft |
||
| 475 | * @param \eZ\Publish\API\Repository\Values\User\PolicyDraft $policy |
||
| 476 | * @param \eZ\Publish\API\Repository\Values\User\PolicyUpdateStruct $policyUpdateStruct |
||
| 477 | * |
||
| 478 | * @return \eZ\Publish\API\Repository\Values\User\PolicyDraft |
||
| 479 | * |
||
| 480 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 481 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if limitation of the same type is repeated in policy update |
||
| 482 | * struct or if limitation is not allowed on module/function |
||
| 483 | * @throws \eZ\Publish\API\Repository\Exceptions\LimitationValidationException if a limitation in the $policyUpdateStruct is not valid |
||
| 484 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to update a policy |
||
| 485 | */ |
||
| 486 | public function updatePolicyByRoleDraft( |
||
| 537 | |||
| 538 | /** |
||
| 539 | * Deletes the given RoleDraft. |
||
| 540 | * |
||
| 541 | * @since 6.0 |
||
| 542 | * |
||
| 543 | * @param \eZ\Publish\API\Repository\Values\User\RoleDraft $roleDraft |
||
| 544 | * |
||
| 545 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 546 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 547 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 548 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to delete this RoleDraft |
||
| 549 | */ |
||
| 550 | public function deleteRoleDraft(APIRoleDraft $roleDraft): void |
||
| 563 | |||
| 564 | /** |
||
| 565 | * Publishes a given RoleDraft. |
||
| 566 | * |
||
| 567 | * @since 6.0 |
||
| 568 | * |
||
| 569 | * @param \eZ\Publish\API\Repository\Values\User\RoleDraft $roleDraft |
||
| 570 | * |
||
| 571 | * |
||
| 572 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the role draft cannot be loaded |
||
| 573 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 574 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to publish this RoleDraft |
||
| 575 | */ |
||
| 576 | public function publishRoleDraft(APIRoleDraft $roleDraft): void |
||
| 601 | |||
| 602 | /** |
||
| 603 | * Loads a role for the given id. |
||
| 604 | * |
||
| 605 | * @param int $id |
||
| 606 | * |
||
| 607 | * @return \eZ\Publish\Core\Repository\Values\User\Role |
||
| 608 | * |
||
| 609 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 610 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 611 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if a role with the given id was not found |
||
| 612 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to read this role |
||
| 613 | */ |
||
| 614 | public function loadRole(int $id): APIRole |
||
| 626 | |||
| 627 | /** |
||
| 628 | * Loads a role for the given identifier. |
||
| 629 | * |
||
| 630 | * @param string $identifier |
||
| 631 | * |
||
| 632 | * @return \eZ\Publish\API\Repository\Values\User\Role |
||
| 633 | * |
||
| 634 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 635 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 636 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if a role with the given name was not found |
||
| 637 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to read this role |
||
| 638 | */ |
||
| 639 | public function loadRoleByIdentifier(string $identifier): APIRole |
||
| 651 | |||
| 652 | /** |
||
| 653 | * Loads all roles, excluding the ones the current user is not allowed to read. |
||
| 654 | * |
||
| 655 | * @return \eZ\Publish\API\Repository\Values\User\Role[] |
||
| 656 | */ |
||
| 657 | public function loadRoles(): iterable |
||
| 675 | |||
| 676 | /** |
||
| 677 | * Deletes the given role. |
||
| 678 | * |
||
| 679 | * @param \eZ\Publish\API\Repository\Values\User\Role $role |
||
| 680 | * |
||
| 681 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 682 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 683 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 684 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to delete this role |
||
| 685 | */ |
||
| 686 | public function deleteRole(APIRole $role): void |
||
| 703 | |||
| 704 | /** |
||
| 705 | * Assigns a role to the given user group. |
||
| 706 | * |
||
| 707 | * @param \eZ\Publish\API\Repository\Values\User\Role $role |
||
| 708 | * @param \eZ\Publish\API\Repository\Values\User\UserGroup $userGroup |
||
| 709 | * @param \eZ\Publish\API\Repository\Values\User\Limitation\RoleLimitation $roleLimitation an optional role limitation (which is either a subtree limitation or section limitation) |
||
| 710 | * |
||
| 711 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 712 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If assignment already exists |
||
| 713 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 714 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to assign a role |
||
| 715 | * @throws \eZ\Publish\API\Repository\Exceptions\LimitationValidationException if $roleLimitation is not valid |
||
| 716 | */ |
||
| 717 | public function assignRoleToUserGroup(APIRole $role, UserGroup $userGroup, RoleLimitation $roleLimitation = null): void |
||
| 753 | |||
| 754 | /** |
||
| 755 | * Assigns a role to the given user. |
||
| 756 | * |
||
| 757 | * @param \eZ\Publish\API\Repository\Values\User\Role $role |
||
| 758 | * @param \eZ\Publish\API\Repository\Values\User\User $user |
||
| 759 | * @param \eZ\Publish\API\Repository\Values\User\Limitation\RoleLimitation $roleLimitation an optional role limitation (which is either a subtree limitation or section limitation) |
||
| 760 | * |
||
| 761 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 762 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If assignment already exists |
||
| 763 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 764 | * @throws \eZ\Publish\API\Repository\Exceptions\LimitationValidationException if $roleLimitation is not valid |
||
| 765 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to assign a role |
||
| 766 | */ |
||
| 767 | public function assignRoleToUser(APIRole $role, User $user, RoleLimitation $roleLimitation = null): void |
||
| 803 | |||
| 804 | /** |
||
| 805 | * Removes the given role assignment. |
||
| 806 | * |
||
| 807 | * @param \eZ\Publish\API\Repository\Values\User\RoleAssignment $roleAssignment |
||
| 808 | * |
||
| 809 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 810 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 811 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 812 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to remove a role assignment |
||
| 813 | */ |
||
| 814 | public function removeRoleAssignment(RoleAssignment $roleAssignment): void |
||
| 831 | |||
| 832 | /** |
||
| 833 | * Loads a role assignment for the given id. |
||
| 834 | * |
||
| 835 | * @param int $roleAssignmentId |
||
| 836 | * |
||
| 837 | * @return \eZ\Publish\API\Repository\Values\User\RoleAssignment |
||
| 838 | * |
||
| 839 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 840 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 841 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException If the role assignment was not found |
||
| 842 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to read this role |
||
| 843 | */ |
||
| 844 | public function loadRoleAssignment(int $roleAssignmentId): RoleAssignment |
||
| 880 | |||
| 881 | /** |
||
| 882 | * Returns the assigned user and user groups to this role. |
||
| 883 | * |
||
| 884 | * @param \eZ\Publish\API\Repository\Values\User\Role $role |
||
| 885 | * |
||
| 886 | * @return \eZ\Publish\API\Repository\Values\User\RoleAssignment[] |
||
| 887 | * |
||
| 888 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 889 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 890 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to read a role |
||
| 891 | */ |
||
| 892 | public function getRoleAssignments(APIRole $role): iterable |
||
| 928 | |||
| 929 | /** |
||
| 930 | * @see \eZ\Publish\API\Repository\RoleService::getRoleAssignmentsForUser() |
||
| 931 | * |
||
| 932 | * @param \eZ\Publish\API\Repository\Values\User\User $user |
||
| 933 | * @param bool $inherited |
||
| 934 | * |
||
| 935 | * @return iterable |
||
| 936 | * |
||
| 937 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 938 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 939 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 940 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
| 941 | */ |
||
| 942 | public function getRoleAssignmentsForUser(User $user, bool $inherited = false): iterable |
||
| 971 | |||
| 972 | /** |
||
| 973 | * Returns the roles assigned to the given user group, excluding the ones the current user is not allowed to read. |
||
| 974 | * |
||
| 975 | * @param \eZ\Publish\API\Repository\Values\User\UserGroup $userGroup |
||
| 976 | * |
||
| 977 | * @return \eZ\Publish\API\Repository\Values\User\UserGroupRoleAssignment[] |
||
| 978 | * |
||
| 979 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 980 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 981 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 982 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
| 983 | */ |
||
| 984 | public function getRoleAssignmentsForUserGroup(UserGroup $userGroup): iterable |
||
| 1002 | |||
| 1003 | /** |
||
| 1004 | * Instantiates a role create class. |
||
| 1005 | * |
||
| 1006 | * @param string $name |
||
| 1007 | * |
||
| 1008 | * @return \eZ\Publish\API\Repository\Values\User\RoleCreateStruct |
||
| 1009 | */ |
||
| 1010 | public function newRoleCreateStruct(string $name): APIRoleCreateStruct |
||
| 1019 | |||
| 1020 | /** |
||
| 1021 | * Instantiates a role copy class. |
||
| 1022 | * |
||
| 1023 | * @param string $name |
||
| 1024 | * |
||
| 1025 | * @return \eZ\Publish\API\Repository\Values\User\RoleCopyStruct |
||
| 1026 | */ |
||
| 1027 | public function newRoleCopyStruct($name): APIRoleCopyStruct |
||
| 1036 | |||
| 1037 | /** |
||
| 1038 | * Instantiates a policy create class. |
||
| 1039 | * |
||
| 1040 | * @param string $module |
||
| 1041 | * @param string $function |
||
| 1042 | * |
||
| 1043 | * @return \eZ\Publish\API\Repository\Values\User\PolicyCreateStruct |
||
| 1044 | */ |
||
| 1045 | public function newPolicyCreateStruct(string $module, string $function): APIPolicyCreateStruct |
||
| 1055 | |||
| 1056 | /** |
||
| 1057 | * Instantiates a policy update class. |
||
| 1058 | * |
||
| 1059 | * @return \eZ\Publish\API\Repository\Values\User\PolicyUpdateStruct |
||
| 1060 | */ |
||
| 1061 | public function newPolicyUpdateStruct(): APIPolicyUpdateStruct |
||
| 1069 | |||
| 1070 | /** |
||
| 1071 | * Instantiates a policy update class. |
||
| 1072 | * |
||
| 1073 | * @return \eZ\Publish\API\Repository\Values\User\RoleUpdateStruct |
||
| 1074 | */ |
||
| 1075 | public function newRoleUpdateStruct(): RoleUpdateStruct |
||
| 1079 | |||
| 1080 | /** |
||
| 1081 | * Returns the LimitationType registered with the given identifier. |
||
| 1082 | * |
||
| 1083 | * Returns the correct implementation of API Limitation value object |
||
| 1084 | * based on provided identifier |
||
| 1085 | * |
||
| 1086 | * @param string $identifier |
||
| 1087 | * |
||
| 1088 | * @return \eZ\Publish\SPI\Limitation\Type |
||
| 1089 | * |
||
| 1090 | * @throws \RuntimeException if there is no LimitationType with $identifier |
||
| 1091 | */ |
||
| 1092 | public function getLimitationType(string $identifier): Type |
||
| 1096 | |||
| 1097 | /** |
||
| 1098 | * Returns the LimitationType's assigned to a given module/function. |
||
| 1099 | * |
||
| 1100 | * Typically used for: |
||
| 1101 | * - Internal validation limitation value use on Policies |
||
| 1102 | * - Role admin gui for editing policy limitations incl list limitation options via valueSchema() |
||
| 1103 | * |
||
| 1104 | * @param string $module Legacy name of "controller", it's a unique identifier like "content" |
||
| 1105 | * @param string $function Legacy name of a controller "action", it's a unique within the controller like "read" |
||
| 1106 | * |
||
| 1107 | * @return \eZ\Publish\SPI\Limitation\Type[] |
||
| 1108 | * |
||
| 1109 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException If module/function to limitation type mapping |
||
| 1110 | * refers to a non existing identifier. |
||
| 1111 | */ |
||
| 1112 | public function getLimitationTypesByModuleFunction(string $module, string $function): iterable |
||
| 1133 | |||
| 1134 | /** |
||
| 1135 | * Validates Policies and Limitations in Role create struct. |
||
| 1136 | * |
||
| 1137 | * @uses ::validatePolicy() |
||
| 1138 | * |
||
| 1139 | * @param \eZ\Publish\API\Repository\Values\User\RoleCreateStruct $roleCreateStruct |
||
| 1140 | * |
||
| 1141 | * @return \eZ\Publish\Core\FieldType\ValidationError[][][] |
||
| 1142 | * |
||
| 1143 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 1144 | */ |
||
| 1145 | protected function validateRoleCreateStruct(APIRoleCreateStruct $roleCreateStruct): iterable |
||
| 1162 | |||
| 1163 | /** |
||
| 1164 | * Validates Policies and Limitations in Role copy struct. |
||
| 1165 | * |
||
| 1166 | * @uses ::validatePolicy() |
||
| 1167 | * |
||
| 1168 | * @param \eZ\Publish\API\Repository\Values\User\RoleCopyStruct $roleCopyStruct |
||
| 1169 | * |
||
| 1170 | * @return \eZ\Publish\Core\FieldType\ValidationError[][][] |
||
| 1171 | */ |
||
| 1172 | protected function validateRoleCopyStruct(APIRoleCopyStruct $roleCopyStruct) |
||
| 1189 | |||
| 1190 | /** |
||
| 1191 | * Validates Policy context: Limitations on a module and function. |
||
| 1192 | * |
||
| 1193 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If the same limitation is repeated or if |
||
| 1194 | * limitation is not allowed on module/function |
||
| 1195 | * |
||
| 1196 | * @param string $module |
||
| 1197 | * @param string $function |
||
| 1198 | * @param \eZ\Publish\API\Repository\Values\User\Limitation[] $limitations |
||
| 1199 | * |
||
| 1200 | * @return \eZ\Publish\Core\FieldType\ValidationError[][] |
||
| 1201 | */ |
||
| 1202 | protected function validatePolicy(string $module, string $function, array $limitations): iterable |
||
| 1227 | |||
| 1228 | /** |
||
| 1229 | * Validate that assignments not already exists and filter validations against existing. |
||
| 1230 | * |
||
| 1231 | * @param int $contentId |
||
| 1232 | * @param \eZ\Publish\SPI\Persistence\User\Role $spiRole |
||
| 1233 | * @param array|null $limitation |
||
| 1234 | * |
||
| 1235 | * @return array[]|null Filtered version of $limitation |
||
| 1236 | * |
||
| 1237 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If assignment already exists |
||
| 1238 | */ |
||
| 1239 | protected function checkAssignmentAndFilterLimitationValues( |
||
| 1284 | |||
| 1285 | /** |
||
| 1286 | * Deletes a policy. |
||
| 1287 | * |
||
| 1288 | * Used by {@link removePolicy()} and {@link deletePolicy()} |
||
| 1289 | * |
||
| 1290 | * @param \eZ\Publish\API\Repository\Values\User\Policy $policy |
||
| 1291 | * |
||
| 1292 | * @throws \Exception |
||
| 1293 | */ |
||
| 1294 | protected function internalDeletePolicy(APIPolicy $policy): void |
||
| 1305 | } |
||
| 1306 |