| @@ 979-1009 (lines=31) @@ | ||
| 976 | * @param \eZ\Publish\API\Repository\Values\User\Role $role |
|
| 977 | * @param \eZ\Publish\API\Repository\Values\User\UserGroup $userGroup |
|
| 978 | */ |
|
| 979 | public function unassignRoleFromUserGroup(APIRole $role, UserGroup $userGroup) |
|
| 980 | { |
|
| 981 | if ($this->repository->canUser('role', 'assign', $userGroup, $role) !== true) { |
|
| 982 | throw new UnauthorizedException('role', 'assign'); |
|
| 983 | } |
|
| 984 | ||
| 985 | $spiRoleAssignments = $this->userHandler->loadRoleAssignmentsByGroupId($userGroup->id); |
|
| 986 | $isAssigned = false; |
|
| 987 | foreach ($spiRoleAssignments as $spiRoleAssignment) { |
|
| 988 | if ($spiRoleAssignment->roleId === $role->id) { |
|
| 989 | $isAssigned = true; |
|
| 990 | break; |
|
| 991 | } |
|
| 992 | } |
|
| 993 | ||
| 994 | if (!$isAssigned) { |
|
| 995 | throw new InvalidArgumentException( |
|
| 996 | '$userGroup', |
|
| 997 | 'Role is not assigned to the given UserGroup' |
|
| 998 | ); |
|
| 999 | } |
|
| 1000 | ||
| 1001 | $this->repository->beginTransaction(); |
|
| 1002 | try { |
|
| 1003 | $this->userHandler->unassignRole($userGroup->id, $role->id); |
|
| 1004 | $this->repository->commit(); |
|
| 1005 | } catch (Exception $e) { |
|
| 1006 | $this->repository->rollback(); |
|
| 1007 | throw $e; |
|
| 1008 | } |
|
| 1009 | } |
|
| 1010 | ||
| 1011 | /** |
|
| 1012 | * Assigns a role to the given user. |
|
| @@ 1068-1098 (lines=31) @@ | ||
| 1065 | * @param \eZ\Publish\API\Repository\Values\User\Role $role |
|
| 1066 | * @param \eZ\Publish\API\Repository\Values\User\User $user |
|
| 1067 | */ |
|
| 1068 | public function unassignRoleFromUser(APIRole $role, User $user) |
|
| 1069 | { |
|
| 1070 | if ($this->repository->canUser('role', 'assign', $user, $role) !== true) { |
|
| 1071 | throw new UnauthorizedException('role', 'assign'); |
|
| 1072 | } |
|
| 1073 | ||
| 1074 | $spiRoleAssignments = $this->userHandler->loadRoleAssignmentsByGroupId($user->id); |
|
| 1075 | $isAssigned = false; |
|
| 1076 | foreach ($spiRoleAssignments as $spiRoleAssignment) { |
|
| 1077 | if ($spiRoleAssignment->roleId === $role->id) { |
|
| 1078 | $isAssigned = true; |
|
| 1079 | break; |
|
| 1080 | } |
|
| 1081 | } |
|
| 1082 | ||
| 1083 | if (!$isAssigned) { |
|
| 1084 | throw new InvalidArgumentException( |
|
| 1085 | '$user', |
|
| 1086 | 'Role is not assigned to the given User' |
|
| 1087 | ); |
|
| 1088 | } |
|
| 1089 | ||
| 1090 | $this->repository->beginTransaction(); |
|
| 1091 | try { |
|
| 1092 | $this->userHandler->unassignRole($user->id, $role->id); |
|
| 1093 | $this->repository->commit(); |
|
| 1094 | } catch (Exception $e) { |
|
| 1095 | $this->repository->rollback(); |
|
| 1096 | throw $e; |
|
| 1097 | } |
|
| 1098 | } |
|
| 1099 | ||
| 1100 | /** |
|
| 1101 | * Removes the given role assignment. |
|