Ejemplo n.º 1
0
 public function getAcl()
 {
     if ($this->acl) {
         return $this->acl;
     }
     $cache = $this->getCache();
     if ($cache && ($data = $cache->get('acl'))) {
         return $this->acl = $data;
     }
     $acl = new MemoryAcl();
     $acl->setDefaultAction(Acl::DENY);
     $roles = Entities\Roles::find();
     foreach ($roles as $role) {
         $roleName = $role->name ? $role->name : $role->roleKey;
         $acl->addRole($role->roleKey, $role->roleKey);
     }
     $resources = Entities\Resources::find();
     foreach ($resources as $resource) {
         $acl->addResource($resource->resourceKey);
     }
     $operations = Entities\Operations::find();
     foreach ($operations as $operation) {
         $acl->addResourceAccess($operation->resourceKey, $operation->operationKey);
         if ($operation->roles) {
             foreach ($operation->roles as $role) {
                 $acl->allow($role->roleKey, $operation->resourceKey, $operation->operationKey);
             }
         }
     }
     if ($cache) {
         $cache->save('acl', $acl);
     }
     return $this->acl = $acl;
 }
Ejemplo n.º 2
0
 /**
  * @operationName("Operation List")
  * @operationDescription("Get operation list")
  */
 public function indexAction()
 {
     $query = array('q' => $this->request->getQuery('q', 'string'), 'rid' => $this->request->getQuery('rid', 'int'), 'roleid' => $this->request->getQuery('roleid', 'int'), 'group' => $this->request->getQuery('group', 'string'), 'limit' => 1000, 'page' => $this->request->getQuery('page', 'int', 1));
     $form = new Forms\OperationFilterForm();
     $form->setValues($this->request->getQuery());
     $this->view->setVar('form', $form);
     $operation = new Models\Operation();
     $operations = $operation->findOperations($query);
     $paginator = new \Eva\EvaEngine\Paginator(array("builder" => $operations, "limit" => $query['limit'], "page" => $query['page']));
     $paginator->setQuery($query);
     $pager = $paginator->getPaginate();
     $this->view->setVar('pager', $pager);
     $this->view->setVar('roles', Entities\Roles::find());
 }
Ejemplo n.º 3
0
 public function addRole()
 {
     if ($this->roleid) {
         return $this->roleid;
     }
     $roles = Entities\Roles::find();
     $options = array('All Roles');
     if ($roles) {
         foreach ($roles as $role) {
             $options[$role->id] = $role->roleKey . ' | ' . $role->name;
         }
     }
     $element = new Select('roleid', $options);
     $this->add($element);
     return $this->roleid = $element;
 }
Ejemplo n.º 4
0
 /**
  * @operationName("Remove Role")
  * @operationDescription("Remove Role")
  */
 public function deleteAction()
 {
     $this->response->setContentType('application/json', 'utf-8');
     if (!$this->request->isDelete()) {
         $this->response->setStatusCode('405', 'Method Not Allowed');
         return $this->response->setJsonContent(array('errors' => array(array('code' => 405, 'message' => 'ERR_POST_REQUEST_METHOD_NOT_ALLOW'))));
     }
     $id = $this->dispatcher->getParam('id');
     $role = Entities\Roles::findFirst($id);
     try {
         $role->delete();
     } catch (\Exception $e) {
         return $this->showExceptionAsJson($e, $role->getMessages());
     }
     return $this->response->setJsonContent($role);
 }