Ejemplo n.º 1
0
 /**
  * Returns the assigned user and user groups to this role
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to read a role
  *
  * @param \eZ\Publish\API\Repository\Values\User\Role $role
  *
  * @return \eZ\Publish\API\Repository\Values\User\RoleAssignment[]
  */
 public function getRoleAssignments(APIRole $role)
 {
     if ($this->repository->hasAccess('role', 'read') !== true) {
         throw new UnauthorizedException('role', 'read');
     }
     $userService = $this->repository->getUserService();
     $spiRoleAssignments = $this->userHandler->loadRoleAssignmentsByRoleId($role->id);
     $roleAssignments = array();
     foreach ($spiRoleAssignments as $spiRoleAssignment) {
         // First check if the Role is assigned to a User
         // If no User is found, see if it belongs to a UserGroup
         try {
             $user = $userService->loadUser($spiRoleAssignment->contentId);
             $roleAssignments[] = $this->buildDomainUserRoleAssignmentObject($spiRoleAssignment, $user, $role);
         } catch (APINotFoundException $e) {
             try {
                 $userGroup = $userService->loadUserGroup($spiRoleAssignment->contentId);
                 $roleAssignments[] = $this->buildDomainUserGroupRoleAssignmentObject($spiRoleAssignment, $userGroup, $role);
             } catch (APINotFoundException $e) {
                 // Do nothing
             }
         }
     }
     return $roleAssignments;
 }