getRole() public method

Get User Role
public getRole ( boolean $forceReload = false ) : Model
$forceReload boolean Force reload
return Gc\User\Role\Model
Exemplo n.º 1
0
 /**
  * List all resources by group
  *
  * @param array $group Resource group
  *
  * @return array
  */
 public function listResourcesByGroup($group)
 {
     $result = null;
     $select = new Select();
     $select->from(array('uar' => 'user_acl_resource'))->join(array('uap' => 'user_acl_permission'), 'uar.id = uap.user_acl_resource_id')->where->equalTo('uar.resource', $group);
     $group = $this->roleTable->fetchAll($select);
     foreach ($group as $key => $value) {
         if ($this->isAllowed($this->user->getRole()->getName(), $value['resource'], $value['permission'])) {
             $result[] = $value['permission'];
         }
     }
     return $result;
 }
Exemplo n.º 2
0
 /**
  * Test
  *
  * @return void
  */
 public function testGetRole()
 {
     $this->assertInstanceOf('Gc\\User\\Role\\Model', $this->object->getRole());
 }
Exemplo n.º 3
0
 /**
  * Constructor
  *
  * @param UserModel $user User model to retrieve Acl, role name and check permission
  */
 public function __construct(UserModel $user)
 {
     $this->acl = $user->getAcl(true);
     $this->roleName = $user->getRole()->getName();
 }
Exemplo n.º 4
0
 /**
  * Check user acl
  *
  * @param UserModel $userModel User model
  *
  * @return \Zend\Http\Response|null
  */
 protected function checkAcl(UserModel $userModel)
 {
     if (!empty($this->aclPage) and $userModel->getRole()->getName() !== RoleModel::PROTECTED_NAME) {
         $permission = null;
         $acl = $userModel->getAcl(true);
         if ($this->aclPage['resource'] == 'modules') {
             $moduleId = $this->getRouteMatch()->getParam('m');
             if (empty($moduleId)) {
                 $action = $this->getRouteMatch()->getParam('action');
                 $permission = $action === 'index' ? 'list' : $action;
             } else {
                 $moduleModel = ModuleModel::fromId($moduleId);
                 if (!empty($moduleModel)) {
                     $permission = $moduleModel->getName();
                 }
             }
         } else {
             $permission = empty($this->aclPage['permission']) ? null : $this->aclPage['permission'];
             if ($this->aclPage['permission'] != 'index' and !in_array($this->aclPage['resource'], array('content', 'stats'))) {
                 $action = $this->getRouteMatch()->getParam('action');
                 $permission .= (!empty($permission) ? '/' : '') . ($action === 'index' ? 'list' : $action);
             }
         }
         if (!$acl->isAllowed($userModel->getRole()->getName(), $this->aclPage['resource'], $permission)) {
             return $this->redirect()->toRoute('config/user/forbidden');
         }
     }
 }