예제 #1
0
 function permissions($id)
 {
     // primero actualiza los permisos
     $this->update_acos();
     // importando las clases
     App::import('Model', 'UserGroup');
     App::import('Model', 'Aro');
     App::import('Model', 'ArosAco');
     // consulta todos los acos
     $aco = new Aco();
     $this->set('acos', $aco->find('threaded', array('recursive' => 0)));
     // consulta el id del aro
     $aro = new Aro();
     $aro_row = $aro->find('first', array('conditions' => array('model' => 'UserGroup', 'foreign_key' => $id)));
     $this->UserGroup = new UserGroup();
     $this->set('userGroup', $this->UserGroup->read(null, $id));
     $this->set('aro_foreignkey', $id);
     if (!empty($this->data)) {
         // guarda los permisos
         $group =& $this->UserGroup;
         $group->id = $id;
         $aro_aco_del = new ArosAco();
         foreach ($this->data['Acos'] as $aco_id => $mode) {
             switch ($mode['option']) {
                 case 1:
                     // allow
                     $this->Acl->allow($group, $mode['url']);
                     break;
                 case 2:
                     // deny
                     $this->Acl->deny($group, $mode['url']);
                     break;
                 default:
                     // lo borra
                     $aro_aco_del->deleteAll(array('aro_id' => $aro_row['Aro']['id'], 'aco_id' => $aco_id));
                     break;
             }
         }
         $this->Session->setFlash(__('UserGroup permissions changed successfully', true));
         $this->redirect(array('action' => 'index'));
     }
     // consulta la relacion de aros_acos
     $aros_aco = new ArosAco();
     $this->set('aros_acos', $aros_aco->find('all', array('conditions' => array('aro_id' => $aro_row['Aro']['id']))));
 }
예제 #2
0
 /**
  * Get an array of access-control links between the given Aro and Aco
  *
  * @param mixed $aro
  * @param mixed $aco
  * @return array
  * @access public
  */
 function getAclLink($aro, $aco)
 {
     $Aro = new Aro();
     $Aco = new Aco();
     $Link = new ArosAco();
     $obj = array();
     $obj['Aro'] = $Aro->find($Aro->_resolveID($aro));
     $obj['Aco'] = $Aco->find($Aco->_resolveID($aco));
     $obj['Aro'] = $obj['Aro']['Aro'];
     $obj['Aco'] = $obj['Aco']['Aco'];
     if ($obj['Aro'] == null || count($obj['Aro']) == 0 || $obj['Aco'] == null || count($obj['Aco']) == 0) {
         return false;
     }
     return array('aro' => $obj['Aro']['id'], 'aco' => $obj['Aco']['id'], 'link' => $Link->findAll(array('ArosAco.aro_id' => $obj['Aro']['id'], 'ArosAco.aco_id' => $obj['Aco']['id'])));
 }
예제 #3
0
 function beforeFilter()
 {
     $this->Auth->loginRedirect = '/';
     // for the authorizations
     $this->Auth->authorize = 'actions';
     $this->Auth->actionPath = 'controllers/';
     // if the user is not logged and it requests the root '/' url
     // redirects to '/login'
     if (!$this->Session->read('Auth.User.id')) {
         if ($this->params['url']['url'] == '/') {
             $this->redirect('/login');
         }
     }
     App::import('Model', 'User');
     if ($this->Session->read('Auth.User.id')) {
         if ($this->params['url']['url'] == '/') {
             $user = new User();
             $user = $user->read(null, $this->Session->read('Auth.User.id'));
             $this->redirect($user['UserGroup']['home_url']);
         }
     }
     if ($this->layout == 'default' && $this->Session->read('Auth.User.id')) {
         // creating an array with all the permissions for this user
         // and in the view we check if it has permissions to show the link
         // getting all the acos with permissions
         App::import('Model', 'Aco');
         App::import('Model', 'Aro');
         App::import('Model', 'ArosAco');
         $aco = new Aco();
         $aro = new Aro();
         $aros_aco = new ArosAco();
         $acos = $aco->find('threaded', array('recursive' => 0));
         // consulta el id del aro
         $aro_row = $aro->find('first', array('conditions' => array('model' => 'UserGroup', 'foreign_key' => $this->Session->read('Auth.User.user_group_id'))));
         // consulta la relacion de aros_acos
         $aros_acos = $aros_aco->find('all', array('conditions' => array('aro_id' => $aro_row['Aro']['id'])));
         $this->set('acl_lists', $this->AclGetList->get($this->Session->read('Auth.User.user_group_id'), $acos, $aros_acos));
     }
     // rendering the menu for "default" layout
     // checking if there is a logged user
     if ($this->layout == 'default' && $this->Session->read('Auth.User.id')) {
         // renders the menu according the user group
         App::import('Model', 'Menu');
         $menu = new Menu();
         $this->set('layout_menus', $menu->find_for_show($this->Session->read('Auth.User.user_group_id')));
         // selecting the current menu
         $this->set('layout_current', $this->params['url']['url']);
         //$route = Router::parse('/'.$this->params['url']['url']);
         //$aco_alias = 'controllers/'.$route['controller'].'/'.$route['action'];
         //$this->set('layout_acos', $this->Acl->Aco->node('controllers/'.$route['controller'].'/'.$route['action']));
         // asks the controller for selecting the correct link in the menu
         $cont = split('_', $this->params['controller']);
         $newcont = '';
         foreach ($cont as $c) {
             $newcont .= ucfirst($c);
         }
         $current_aco = $this->Acl->Aco->node('controllers/' . $newcont . '/' . $this->params['action']);
         $this->set('layout_aco_id', $current_aco[0]['Aco']['id']);
         //$route = Router::parse('/profile');
         //$this->set('menu_url', '/'.$this->params['controller'].'/'.$this->params['action']);
         if ($this->Session->read('Auth.User.type') == 'web') {
             $user = new User();
             $user->id = $this->Session->read('Auth.User.id');
             $user->updatecredit_expiration();
             $this->set('user_balance', $user->getBalance());
             $this->set('user_expirationdate', $user->getExpirationDate());
         }
     }
 }