/** * admin_index * * @param id integer aco id, when null, the root ACO is used * @return void */ function index($id = null, $level = null) { $aco = new Aco(); // $this->data = $aco->generateTreeList(null, null, null, '&a; '); // if (isset($this->request->query['root'])) { // $query = strtolower($this->request->query['root']); // } // // if ($id == null) { // $root = isset($query) ? $query : 'controllers'; // //$root = $this->AclAco->node(str_replace('.', '_', $root)); // $root = $aco->node(str_replace('.', '_', $root)); // $root = $root[0]; // } else { // $root = $aco->read(null, $id); // } //pr($root); //die; // if ($level !== null) { // $level++; // } // $acos = array(); $roles = $this->Groups->find('list'); // if ($root) { // $fields = Hash::merge(array('id', 'parent_id', 'alias'), $fields = array()); //// $acos = $this->children($acoId, true, $fields); // $acos = $aco->children($root['Aco']['id'], true, $fields); // //// foreach ($acos as $key => $acov) { //// $children = $aco->childCount($acov['Aco']['id'], true); //// pr($acos); //// pr($acos[$key]['Aco']); //// $acos[$key]['Aco']['children'][] = $children; //// } // // } // $options = array('conditions' => array('Aco.parent_id' => 1)); $acos = $aco->find('all', $options = null); // pr($roles); // $this->set(compact('acos', 'roles', 'level')); $this->set(compact('acos', 'roles')); // pr($level);die; // $acos = $this->AclAco->getChildren($root['Aco']['id']); }
/** * test After Save * * @return void * @access public */ function testAfterSave() { $Post =& new AclPost(); $data = array('Post' => array('author_id' => 1, 'title' => 'Acl Post', 'body' => 'post body', 'published' => 1)); $Post->save($data); $result = $this->Aco->find('first', array('conditions' => array('Aco.model' => 'Post', 'Aco.foreign_key' => $Post->id))); $this->assertTrue(is_array($result)); $this->assertEqual($result['Aco']['model'], 'Post'); $this->assertEqual($result['Aco']['foreign_key'], $Post->id); $aroData = array('Aro' => array('model' => 'AclPerson', 'foreign_key' => 2, 'parent_id' => null)); $this->Aro->save($aroData); $Person =& new AclPerson(); $data = array('AclPerson' => array('name' => 'Trent', 'mother_id' => 2, 'father_id' => 3)); $Person->save($data); $result = $this->Aro->find('first', array('conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => $Person->id))); $this->assertTrue(is_array($result)); $this->assertEqual($result['Aro']['parent_id'], 5); $node = $Person->node(array('model' => 'AclPerson', 'foreign_key' => 8)); $this->assertEqual(count($node), 2); $this->assertEqual($node[0]['Aro']['parent_id'], 5); $this->assertEqual($node[1]['Aro']['parent_id'], null); $aroData = array('Aro' => array('model' => 'AclPerson', 'foreign_key' => 1, 'parent_id' => null)); $this->Aro->create(); $this->Aro->save($aroData); $Person->read(null, 8); $Person->set('mother_id', 1); $Person->save(); $result = $this->Aro->find('first', array('conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => $Person->id))); $this->assertTrue(is_array($result)); $this->assertEqual($result['Aro']['parent_id'], 7); $node = $Person->node(array('model' => 'AclPerson', 'foreign_key' => 8)); $this->assertEqual(sizeof($node), 2); $this->assertEqual($node[0]['Aro']['parent_id'], 7); $this->assertEqual($node[1]['Aro']['parent_id'], null); }
/** * 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']))); }
/** * metodo simple para actualizacion de acos * no incluye plugins ni pages ni herencia de metodos del app_controller */ private function update_acos() { $aco = new Aco(); // consulta los controladores en archivos reales $controladores = $this->ControllerList->get(); ksort($controladores); foreach ($controladores as $i => $l) { $controladores[ucfirst($i)] = $controladores[$i]; unset($controladores[$i]); sort($controladores[ucfirst($i)]); } // consultando lista de acos en bd $acos = $aco->find('threaded', array('recursive' => 0, 'order' => 'parent_id, alias')); $lista_bd = array(); foreach ($acos as $a) { $lista_bd[$a['Aco']['alias']]['option'] = 0; $lista_bd[$a['Aco']['alias']]['id'] = $a['Aco']['id']; foreach ($a['children'] as $b) { $lista_bd[$a['Aco']['alias']]['children'][$b['Aco']['alias']]['option'] = 0; $lista_bd[$a['Aco']['alias']]['children'][$b['Aco']['alias']]['id'] = $b['Aco']['id']; foreach ($b['children'] as $c) { $lista_bd[$a['Aco']['alias']]['children'][$b['Aco']['alias']]['children'][$c['Aco']['alias']]['option'] = 0; $lista_bd[$a['Aco']['alias']]['children'][$b['Aco']['alias']]['children'][$c['Aco']['alias']]['id'] = $c['Aco']['id']; } } } // insertando elementos a la lista $lista_bd['controllers']['option'] = !isset($lista_bd['controllers']) ? 1 : 2; // insertar : no hacer nada foreach ($controladores as $i => $l) { $lista_bd['controllers']['children'][$i]['option'] = !isset($lista_bd['controllers']['children'][$i]) ? 1 : 2; // insertar : no hacer nada if ($lista_bd['controllers']['children'][$i]['option'] == 1) { $aco->create(); $aco->save(array('Aco' => array('parent_id' => $lista_bd['controllers']['id'], 'alias' => $i))); $lista_bd['controllers']['children'][$i]['id'] = $aco->getLastInsertId(); } foreach ($controladores[$i] as $k) { $lista_bd['controllers']['children'][$i]['children'][$k]['option'] = !isset($lista_bd['controllers']['children'][$i]['children'][$k]) ? 1 : 2; // insertar : no hacer nada if ($lista_bd['controllers']['children'][$i]['children'][$k]['option'] == 1) { $aco->create(); $aco->save(array('Aco' => array('parent_id' => $lista_bd['controllers']['children'][$i]['id'], 'alias' => $k))); $lista_bd['controllers']['children'][$i]['children'][$k]['id'] = $aco->getLastInsertId(); } } } // borrando elementos foreach ($lista_bd['controllers']['children'] as $i => $l) { if ($lista_bd['controllers']['children'][$i]['option'] == 0) { $aco->id = $lista_bd['controllers']['children'][$i]['id']; $aco->delete(); } foreach ($lista_bd['controllers']['children'][$i]['children'] as $k => $m) { if ($lista_bd['controllers']['children'][$i]['children'][$k]['option'] == 0) { $aco->id = $lista_bd['controllers']['children'][$i]['children'][$k]['id']; $aco->delete(); } } } }
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()); } } }
/** * test After Save * * @return void */ public function testAfterSave() { $Post = new AclPost(); $data = array('Post' => array('author_id' => 1, 'title' => 'Acl Post', 'body' => 'post body', 'published' => 1)); $Post->save($data); $result = $this->Aco->find('first', array('conditions' => array('Aco.model' => 'Post', 'Aco.foreign_key' => $Post->id))); $this->assertTrue(is_array($result)); $this->assertEquals('Post', $result['Aco']['model']); $this->assertEquals($Post->id, $result['Aco']['foreign_key']); $aroData = array('Aro' => array('model' => 'AclPerson', 'foreign_key' => 2, 'parent_id' => NULL)); $this->Aro->save($aroData); $acoData = array('Aco' => array('model' => 'AclPerson', 'foreign_key' => 2, 'parent_id' => NULL)); $this->Aco->save($acoData); $Person = new AclPerson(); $data = array('AclPerson' => array('name' => 'Trent', 'mother_id' => 2, 'father_id' => 3)); $Person->save($data); $result = $this->Aro->find('first', array('conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => $Person->id))); $this->assertTrue(is_array($result)); $this->assertEquals(5, $result['Aro']['parent_id']); $node = $Person->node(array('model' => 'AclPerson', 'foreign_key' => 8), 'Aro'); $this->assertEquals(2, count($node)); $this->assertEquals(5, $node[0]['Aro']['parent_id']); $this->assertEquals(NULL, $node[1]['Aro']['parent_id']); $aroData = array('Aro' => array('model' => 'AclPerson', 'foreign_key' => 1, 'parent_id' => NULL)); $this->Aro->create(); $this->Aro->save($aroData); $acoData = array('Aco' => array('model' => 'AclPerson', 'foreign_key' => 1, 'parent_id' => NULL)); $this->Aco->create(); $this->Aco->save($acoData); $Person->read(NULL, 8); $Person->set('mother_id', 1); $Person->save(); $result = $this->Aro->find('first', array('conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => $Person->id))); $this->assertTrue(is_array($result)); $this->assertEquals(7, $result['Aro']['parent_id']); $node = $Person->node(array('model' => 'AclPerson', 'foreign_key' => 8), 'Aro'); $this->assertEquals(2, count($node)); $this->assertEquals(7, $node[0]['Aro']['parent_id']); $this->assertEquals(NULL, $node[1]['Aro']['parent_id']); }