|
@@ 876-911 (lines=36) @@
|
| 873 |
|
* @param \eZ\Publish\API\Repository\Values\User\UserGroup $userGroup |
| 874 |
|
* @param \eZ\Publish\API\Repository\Values\User\Limitation\RoleLimitation $roleLimitation an optional role limitation (which is either a subtree limitation or section limitation) |
| 875 |
|
*/ |
| 876 |
|
public function assignRoleToUserGroup(APIRole $role, UserGroup $userGroup, RoleLimitation $roleLimitation = null) |
| 877 |
|
{ |
| 878 |
|
if ($this->repository->canUser('role', 'assign', $userGroup, $role) !== true) { |
| 879 |
|
throw new UnauthorizedException('role', 'assign'); |
| 880 |
|
} |
| 881 |
|
|
| 882 |
|
if ($roleLimitation === null) { |
| 883 |
|
$limitation = null; |
| 884 |
|
} else { |
| 885 |
|
$limitationValidationErrors = $this->limitationService->validateLimitation($roleLimitation); |
| 886 |
|
if (!empty($limitationValidationErrors)) { |
| 887 |
|
throw new LimitationValidationException($limitationValidationErrors); |
| 888 |
|
} |
| 889 |
|
|
| 890 |
|
$limitation = array($roleLimitation->getIdentifier() => $roleLimitation->limitationValues); |
| 891 |
|
} |
| 892 |
|
|
| 893 |
|
// Check if objects exists |
| 894 |
|
$spiRole = $this->userHandler->loadRole($role->id); |
| 895 |
|
$loadedUserGroup = $this->repository->getUserService()->loadUserGroup($userGroup->id); |
| 896 |
|
|
| 897 |
|
$limitation = $this->checkAssignmentAndFilterLimitationValues($loadedUserGroup->id, $spiRole, $limitation); |
| 898 |
|
|
| 899 |
|
$this->repository->beginTransaction(); |
| 900 |
|
try { |
| 901 |
|
$this->userHandler->assignRole( |
| 902 |
|
$loadedUserGroup->id, |
| 903 |
|
$spiRole->id, |
| 904 |
|
$limitation |
| 905 |
|
); |
| 906 |
|
$this->repository->commit(); |
| 907 |
|
} catch (Exception $e) { |
| 908 |
|
$this->repository->rollback(); |
| 909 |
|
throw $e; |
| 910 |
|
} |
| 911 |
|
} |
| 912 |
|
|
| 913 |
|
/** |
| 914 |
|
* removes a role from the given user group. |
|
@@ 965-1000 (lines=36) @@
|
| 962 |
|
* @param \eZ\Publish\API\Repository\Values\User\User $user |
| 963 |
|
* @param \eZ\Publish\API\Repository\Values\User\Limitation\RoleLimitation $roleLimitation an optional role limitation (which is either a subtree limitation or section limitation) |
| 964 |
|
*/ |
| 965 |
|
public function assignRoleToUser(APIRole $role, User $user, RoleLimitation $roleLimitation = null) |
| 966 |
|
{ |
| 967 |
|
if ($this->repository->canUser('role', 'assign', $user, $role) !== true) { |
| 968 |
|
throw new UnauthorizedException('role', 'assign'); |
| 969 |
|
} |
| 970 |
|
|
| 971 |
|
if ($roleLimitation === null) { |
| 972 |
|
$limitation = null; |
| 973 |
|
} else { |
| 974 |
|
$limitationValidationErrors = $this->limitationService->validateLimitation($roleLimitation); |
| 975 |
|
if (!empty($limitationValidationErrors)) { |
| 976 |
|
throw new LimitationValidationException($limitationValidationErrors); |
| 977 |
|
} |
| 978 |
|
|
| 979 |
|
$limitation = array($roleLimitation->getIdentifier() => $roleLimitation->limitationValues); |
| 980 |
|
} |
| 981 |
|
|
| 982 |
|
// Check if objects exists |
| 983 |
|
$spiRole = $this->userHandler->loadRole($role->id); |
| 984 |
|
$spiUser = $this->userHandler->load($user->id); |
| 985 |
|
|
| 986 |
|
$limitation = $this->checkAssignmentAndFilterLimitationValues($spiUser->id, $spiRole, $limitation); |
| 987 |
|
|
| 988 |
|
$this->repository->beginTransaction(); |
| 989 |
|
try { |
| 990 |
|
$this->userHandler->assignRole( |
| 991 |
|
$spiUser->id, |
| 992 |
|
$spiRole->id, |
| 993 |
|
$limitation |
| 994 |
|
); |
| 995 |
|
$this->repository->commit(); |
| 996 |
|
} catch (Exception $e) { |
| 997 |
|
$this->repository->rollback(); |
| 998 |
|
throw $e; |
| 999 |
|
} |
| 1000 |
|
} |
| 1001 |
|
|
| 1002 |
|
/** |
| 1003 |
|
* removes a role from the given user. |