Example #1
0
 protected function addUsers($username, $password, $fullname, $email)
 {
     $sm = $this->getServiceLocator();
     /** @var \RcmUser\Service\RcmUserService $userService */
     $userService = $sm->get('RcmUser\\Service\\RcmUserService');
     /** @var \RcmUser\User\Service\UserRoleService $userRoleService */
     $userRoleService = $sm->get('RcmUser\\User\\Service\\UserRoleService');
     /** @var \RcmUser\Acl\Service\AclDataService $aclDataService */
     $aclDataService = $sm->get('RcmUser\\Acl\\AclDataService');
     $user = new User();
     $user->setUsername($username);
     $user->setPassword($password);
     $user->setEmail($email);
     $user->setName($fullname);
     $user->setState('enabled');
     $response = $userService->createUser($user);
     if (!$response->isSuccess()) {
         throw new \Exception(implode("<br />", $response->getMessages()));
     }
     $user = $response->getData();
     $suRoleIdResponse = $aclDataService->getSuperAdminRoleId();
     $suRoleId = $suRoleIdResponse->getData();
     $suRole = new AclRole();
     $suRole->setRoleId($suRoleId);
     $suRole->setDescription('Super Admin Role');
     $response = $aclDataService->createRole($suRole);
     if (!$response->isSuccess()) {
         throw new \Exception(implode("<br />", $response->getMessages()));
     }
     $guestRoleIdResponse = $aclDataService->getGuestRoleId();
     $guestRoleId = $guestRoleIdResponse->getData();
     $guestRole = new AclRole();
     $guestRole->setRoleId($guestRoleId);
     $guestRole->setDescription('Default Guest');
     $response = $aclDataService->createRole($guestRole);
     if (!$response->isSuccess()) {
         throw new \Exception(implode("<br />", $response->getMessages()));
     }
     $response = $userRoleService->addRole($user, $suRoleId);
     if (!$response->isSuccess()) {
         throw new \Exception(implode("<br />", $response->getMessages()));
     }
 }
Example #2
0
 /**
  * testToString
  *
  * @return void
  */
 public function testToString()
 {
     $aclRole = new AclRole();
     $aclRole->setRoleId('role');
     $this->assertEquals('role', $aclRole->__toString(), 'toString should return role id.');
 }
 /**
  * createNamespaceId
  *
  * @param AclRole $role     acl role
  * @param array   $aclRoles array of roles
  *
  * @return string
  */
 public function createNamespaceId(AclRole $role, $aclRoles)
 {
     $parentRoleId = $role->getParentRoleId();
     $ns = $role->getRoleId();
     if (!empty($parentRoleId)) {
         $parent = $aclRoles[$parentRoleId];
         $newns = $this->createNamespaceId($parent, $aclRoles, $ns);
         $ns = $newns . '.' . $ns;
     }
     return $ns;
 }
Example #4
0
 /**
  * delete
  *
  * @param string $id id
  *
  * @return mixed|JsonModel
  */
 public function delete($id)
 {
     // ACCESS CHECK
     if (!$this->isAllowed(RcmUserAclResourceProvider::RESOURCE_ID_ACL, 'delete')) {
         return $this->getNotAllowedResponse();
     }
     $aclDataService = $this->getServiceLocator()->get('RcmUser\\Acl\\AclDataService');
     try {
         $aclRole = new AclRole();
         $aclRole->setRoleId((string) $id);
         $result = $aclDataService->deleteRole($aclRole);
     } catch (\Exception $e) {
         return $this->getExceptionResponse($e);
     }
     return $this->getJsonResponse($result);
 }
Example #5
0
 /**
  * populate
  *
  * @param array|AclRole $data data to populate with
  *
  * @return void
  * @throws RcmUserException
  */
 public function populate($data = [])
 {
     if ($data instanceof AclRole) {
         $this->setRoleId($data->getRoleId());
         $this->setDescription($data->getDescription());
         $this->setParentRoleId($data->getParentRoleId());
         $parentRole = $data->getParentRole();
         if (!empty($parentRole)) {
             $this->setParentRole($parentRole);
         }
         return;
     }
     if (is_array($data)) {
         if (isset($data['roleId'])) {
             $this->setRoleId($data['roleId']);
         }
         if (isset($data['description'])) {
             $this->setDescription($data['description']);
         }
         if (isset($data['parentRoleId'])) {
             $this->setParentRoleId($data['parentRoleId']);
         }
         if (isset($data['parentRole'])) {
             $this->setParentRoleId($data['parentRole']);
         }
         return;
     }
     throw new RcmUserException('Role data could not be populated, data format not supported');
 }
Example #6
0
 /**
  * createRoleNamespaceId
  *
  * @param AclRole $aclRole  aclRole
  * @param array   $aclRoles aclRoles
  * @param string  $nsChar   nsChar
  *
  * @return string
  */
 public function createRoleNamespaceId(AclRole $aclRole, $aclRoles, $nsChar = '.')
 {
     $parentId = $aclRole->getParentRoleId();
     $ns = $aclRole->getRoleId();
     if (!empty($parentId)) {
         $parent = $aclRoles[$parentId];
         $newns = $this->createRoleNamespaceId($parent, $aclRoles, $nsChar);
         $ns = $newns . $nsChar . $ns;
     }
     return $ns;
 }