| @@ 922-952 (lines=31) @@ | ||
| 919 | * @param \eZ\Publish\API\Repository\Values\User\Role $role |
|
| 920 | * @param \eZ\Publish\API\Repository\Values\User\UserGroup $userGroup |
|
| 921 | */ |
|
| 922 | public function unassignRoleFromUserGroup(APIRole $role, UserGroup $userGroup) |
|
| 923 | { |
|
| 924 | if ($this->repository->canUser('role', 'assign', $userGroup, $role) !== true) { |
|
| 925 | throw new UnauthorizedException('role', 'assign'); |
|
| 926 | } |
|
| 927 | ||
| 928 | $spiRoleAssignments = $this->userHandler->loadRoleAssignmentsByGroupId($userGroup->id); |
|
| 929 | $isAssigned = false; |
|
| 930 | foreach ($spiRoleAssignments as $spiRoleAssignment) { |
|
| 931 | if ($spiRoleAssignment->roleId === $role->id) { |
|
| 932 | $isAssigned = true; |
|
| 933 | break; |
|
| 934 | } |
|
| 935 | } |
|
| 936 | ||
| 937 | if (!$isAssigned) { |
|
| 938 | throw new InvalidArgumentException( |
|
| 939 | '$userGroup', |
|
| 940 | 'Role is not assigned to the given UserGroup' |
|
| 941 | ); |
|
| 942 | } |
|
| 943 | ||
| 944 | $this->repository->beginTransaction(); |
|
| 945 | try { |
|
| 946 | $this->userHandler->unassignRole($userGroup->id, $role->id); |
|
| 947 | $this->repository->commit(); |
|
| 948 | } catch (Exception $e) { |
|
| 949 | $this->repository->rollback(); |
|
| 950 | throw $e; |
|
| 951 | } |
|
| 952 | } |
|
| 953 | ||
| 954 | /** |
|
| 955 | * Assigns a role to the given user. |
|
| @@ 1011-1041 (lines=31) @@ | ||
| 1008 | * @param \eZ\Publish\API\Repository\Values\User\Role $role |
|
| 1009 | * @param \eZ\Publish\API\Repository\Values\User\User $user |
|
| 1010 | */ |
|
| 1011 | public function unassignRoleFromUser(APIRole $role, User $user) |
|
| 1012 | { |
|
| 1013 | if ($this->repository->canUser('role', 'assign', $user, $role) !== true) { |
|
| 1014 | throw new UnauthorizedException('role', 'assign'); |
|
| 1015 | } |
|
| 1016 | ||
| 1017 | $spiRoleAssignments = $this->userHandler->loadRoleAssignmentsByGroupId($user->id); |
|
| 1018 | $isAssigned = false; |
|
| 1019 | foreach ($spiRoleAssignments as $spiRoleAssignment) { |
|
| 1020 | if ($spiRoleAssignment->roleId === $role->id) { |
|
| 1021 | $isAssigned = true; |
|
| 1022 | break; |
|
| 1023 | } |
|
| 1024 | } |
|
| 1025 | ||
| 1026 | if (!$isAssigned) { |
|
| 1027 | throw new InvalidArgumentException( |
|
| 1028 | '$user', |
|
| 1029 | 'Role is not assigned to the given User' |
|
| 1030 | ); |
|
| 1031 | } |
|
| 1032 | ||
| 1033 | $this->repository->beginTransaction(); |
|
| 1034 | try { |
|
| 1035 | $this->userHandler->unassignRole($user->id, $role->id); |
|
| 1036 | $this->repository->commit(); |
|
| 1037 | } catch (Exception $e) { |
|
| 1038 | $this->repository->rollback(); |
|
| 1039 | throw $e; |
|
| 1040 | } |
|
| 1041 | } |
|
| 1042 | ||
| 1043 | /** |
|
| 1044 | * Removes the given role assignment. |
|