From ce96fb2738660a7dfd398d26be95dee40e9f6fa5 Mon Sep 17 00:00:00 2001 From: Jan Dorsman Date: Tue, 13 Aug 2013 18:22:14 +0200 Subject: [PATCH] Upgrading to version 2.3.0 --- CHANGELOG | 9 +- Config/bootstrap.php | 10 +- Controller/AcosController.php | 2 +- Controller/ArosController.php | 10 +- Controller/Component/AclManagerComponent.php | 191 +++++++------------ Locale/fre/LC_MESSAGES/acl.po | 4 + README | 6 +- 7 files changed, 93 insertions(+), 139 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 37ffe71..7cdcca3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,10 +1,17 @@ ACL Plugin for CakePHP 2.x ========================== -Website: http://www.alaxos.net/blaxos/pages/view/plugin_acl +Website: http://www.alaxos.net/blaxos/pages/view/plugin_acl_2.0 Author: Nicolas Rod License: http://www.opensource.org/licenses/mit-license.php The MIT License +Version: 2.3.0 +-------------- +Date: 2013-05-02 + +- corrected code to support CakePHP 2.3 find() function that returns an empty array instead of 'false' when no records are found in the datasource +- updated the creation of ACOs to be more efficient when there are many records in the 'acos' datatable + Version: 2.2.0 -------------- Date: 2012-09-24 diff --git a/Config/bootstrap.php b/Config/bootstrap.php index e11e5d3..c285de3 100644 --- a/Config/bootstrap.php +++ b/Config/bootstrap.php @@ -11,7 +11,7 @@ /* * The model name used for the user role (typically 'Role' or 'Group') */ -Configure :: write('acl.aro.role.model', 'Group'); +Configure :: write('acl.aro.role.model', 'Role'); /* * The primary key of the role model @@ -48,13 +48,13 @@ * You can add here role id(s) that are always allowed to access the ACL plugin (by bypassing the ACL check) * (This may prevent a user from being rejected from the ACL plugin after a ACL permission update) */ -Configure :: write('acl.role.access_plugin_role_ids', array(1)); +Configure :: write('acl.role.access_plugin_role_ids', array()); /* * You can add here users id(s) that are always allowed to access the ACL plugin (by bypassing the ACL check) * (This may prevent a user from being rejected from the ACL plugin after a ACL permission update) */ -Configure :: write('acl.role.access_plugin_user_ids', array()); +Configure :: write('acl.role.access_plugin_user_ids', array(1)); /* * The users table field used as username in the views @@ -75,10 +75,10 @@ /* * Indicates whether the roles permissions page must load through Ajax */ -Configure :: write('acl.gui.roles_permissions.ajax', false); +Configure :: write('acl.gui.roles_permissions.ajax', true); /* * Indicates whether the users permissions page must load through Ajax */ -Configure :: write('acl.gui.users_permissions.ajax', false); +Configure :: write('acl.gui.users_permissions.ajax', true); ?> \ No newline at end of file diff --git a/Controller/AcosController.php b/Controller/AcosController.php index 7f0c9e5..8279f42 100644 --- a/Controller/AcosController.php +++ b/Controller/AcosController.php @@ -25,7 +25,7 @@ function admin_empty_acos($run = null) */ $controller_aco = $this->Aco->findByAlias('controllers'); - if($controller_aco !== false) + if(!empty($controller_aco)) { $this->set('actions_exist', true); diff --git a/Controller/ArosController.php b/Controller/ArosController.php index 3a31663..5a428c5 100644 --- a/Controller/ArosController.php +++ b/Controller/ArosController.php @@ -54,7 +54,7 @@ function admin_check($run = null) */ $aro = $this->Aro->find('first', array('conditions' => array('model' => $role_model_name, 'foreign_key' => $role[$role_model_name][$this->_get_role_primary_key_name()]))); - if($aro === false) + if(empty($aro)) { $missing_aros['roles'][] = $role; } @@ -68,7 +68,7 @@ function admin_check($run = null) */ $aro = $this->Aro->find('first', array('conditions' => array('model' => $user_model_name, 'foreign_key' => $user[$user_model_name][$this->_get_user_primary_key_name()]))); - if($aro === false) + if(empty($aro)) { $missing_aros['users'][] = $user; } @@ -110,7 +110,7 @@ function admin_check($run = null) */ $parent_id = $this->Aro->field('id', array('model' => $role_model_name, 'foreign_key' => $user[$user_model_name][$this->_get_role_foreign_key_name()])); - if($parent_id !== false) + if(!empty($parent_id)) { $this->Aro->create(array('parent_id' => $parent_id, 'model' => $user_model_name, @@ -178,7 +178,7 @@ function admin_users() { $aro = $this->Acl->Aro->find('first', array('conditions' => array('model' => $user_model_name, 'foreign_key' => $user[$user_model_name][$this->_get_user_primary_key_name()]))); - if($aro !== false) + if(!empty($aro)) { $user['Aro'] = $aro['Aro']; } @@ -199,7 +199,7 @@ function admin_update_user_role() $data = array($user_model_name => array($this->_get_user_primary_key_name() => $this->params['named']['user'], $this->_get_role_foreign_key_name() => $this->params['named']['role'])); - if($this->{$user_model_name}->save($data, false)) + if($this->{$user_model_name}->save($data)) { $this->Session->setFlash(__d('acl', 'The user role has been updated'), 'flash_message', null, 'plugin_acl'); } diff --git a/Controller/Component/AclManagerComponent.php b/Controller/Component/AclManagerComponent.php index 8d808eb..2b2d3b6 100644 --- a/Controller/Component/AclManagerComponent.php +++ b/Controller/Component/AclManagerComponent.php @@ -225,7 +225,15 @@ function get_missing_acos() $aco =& $this->Acl->Aco; - $acos = $aco->find('all', array('recursive' => -1)); + $acos = array(); + + $controllers_aco = $aco->find('first', array('fields' => array('id'), 'conditions' => array('alias' => 'controllers'), 'recursive' => -1)); + + if(!empty($controllers_aco)) + { + $acos = $aco->children($controllers_aco['Aco']['id'], false, 'id'); + array_unshift($acos, $controllers_aco); + } $existing_aco_paths = array(); foreach($acos as $aco_node) @@ -256,129 +264,56 @@ public function create_acos() $log = array(); - $controllers = $this->AclReflector->get_all_controllers(); - - /****************************************** - * Create 'controllers' node if it does not exist - */ - $root = $aco->node('controllers'); - if (empty($root)) - { - /* - * root node does not exist -> create it - */ - - $aco->create(array('parent_id' => null, 'model' => null, 'alias' => 'controllers')); - $root = $aco->save(); - $root['Aco']['id'] = $aco->id; - - $log[] = __d('acl', 'Created Aco node for controllers'); - } - else - { - $root = $root[0]; - } + $missing_acos = $this->get_missing_acos(); - foreach($controllers as $controller) + foreach($missing_acos as $missing_aco) { - $controller_name = $controller['name']; + $aco_path_parts = explode('/', $missing_aco); + + $path = ''; + $parent_node = null; - if($controller_name !== 'App') + foreach($aco_path_parts as $aco_path_part) { - $plugin_name = $this->AclReflector->getPluginName($controller_name); - $pluginNode = null; - - if(!empty($plugin_name)) - { - /* - * Case of plugin controller - */ - - $controller_name = $this->AclReflector->getPluginControllerName($controller_name); - - /****************************************** - * Check plugin node - */ - $pluginNode = $aco->node('controllers/' . $plugin_name); - if(empty($pluginNode)) - { - /* - * plugin node does not exist -> create it - */ - - $aco->create(array('parent_id' => $root['Aco']['id'], 'model' => null, 'alias' => $plugin_name)); - $pluginNode = $aco->save(); - $pluginNode['Aco']['id'] = $aco->id; - - $log[] = sprintf(__d('acl', 'Created Aco node for %s plugin'), $plugin_name); - } - } - - - /****************************************** - * Check controller node - */ - $controllerNode = $aco->node('controllers/' . (!empty($plugin_name) ? $plugin_name . '/' : '') . $controller_name); - if(empty($controllerNode)) - { - /* - * controller node does not exist -> create it - */ - - if(isset($pluginNode)) - { - /* - * The controller belongs to a plugin - */ - - $plugin_node_aco_id = isset($pluginNode[0]) ? $pluginNode[0]['Aco']['id'] : $pluginNode['Aco']['id']; - - $aco->create(array('parent_id' => $plugin_node_aco_id, 'model' => null, 'alias' => $controller_name)); - $controllerNode = $aco->save(); - $controllerNode['Aco']['id'] = $aco->id; - - $log[] = sprintf(__d('acl', 'Created Aco node for %s/%s'), $plugin_name, $controller_name); - } - else - { - /* - * The controller is an app controller - */ - - $aco->create(array('parent_id' => $root['Aco']['id'], 'model' => null, 'alias' => $controller_name)); - $controllerNode = $aco->save(); - $controllerNode['Aco']['id'] = $aco->id; - - $log[] = sprintf(__d('acl', 'Created Aco node for %s'), $controller_name); - } - } - else - { - $controllerNode = $controllerNode[0]; - } - - - /****************************************** - * Check controller actions node - */ - $actions = $this->AclReflector->get_controller_actions($controller_name); - - foreach($actions as $action) - { - $actionNode = $aco->node('controllers/' . (!empty($plugin_name) ? $plugin_name . '/' : '') . $controller_name . '/' . $action); - - if(empty($actionNode)) - { - /* - * action node does not exist -> create it - */ - - $aco->create(array('parent_id' => $controllerNode['Aco']['id'], 'model' => null, 'alias' => $action)); - $methodNode = $aco->save(); - - $log[] = sprintf(__d('acl', 'Created Aco node for %s'), (!empty($plugin_name) ? $plugin_name . '/' : '') . $controller_name . '/' . $action); - } - } + $path .= '/' . $aco_path_part; + + $look_path = substr($path, 1); + + /* + * Check if the ACO exists + */ + $node = $aco->node($look_path); + + if(empty($node)) + { + $parent_id = null; + + if(isset($parent_node)) + { + $parent_id = isset($parent_node) ? $parent_node[0]['Aco']['id'] : null; + } + + $alias = substr($path, strrpos($path, '/') + 1); + + $aco->create(array('parent_id' => $parent_id, 'model' => null, 'alias' => $alias)); + if($aco->save()) + { + $log[] = sprintf(__d('acl', "Aco node '%s' created"), $look_path); + + /* + * The newly created ACO node is the parent of the next ones to create (if there are some left to create) + */ + $new_node = $aco->findById($aco->getLastInsertID()); + if(!empty($new_node)) + { + $parent_node = array($new_node); + } + } + } + else + { + $parent_node = $node; + } } } @@ -432,7 +367,15 @@ public function get_acos_to_prune() $aco =& $this->Acl->Aco; - $acos = $aco->find('all', array('recursive' => -1)); + $acos = array(); + + $controllers_aco = $aco->find('first', array('fields' => array('id'), 'conditions' => array('alias' => 'controllers'), 'recursive' => -1)); + + if(!empty($controllers_aco)) + { + $acos = $aco->children($controllers_aco['Aco']['id'], false, 'id'); + array_unshift($acos, $controllers_aco); + } $existing_aco_paths = array(); foreach($acos as $aco_node) @@ -596,7 +539,7 @@ public function save_permission($aro_nodes, $aco_path, $permission_type) $specific_permission = $this->Acl->Aro->Permission->find('first', array('conditions' => array('aro_id' => $aro_id, 'aco_id' => $aco_id))); - if($specific_permission !== false) + if(!empty($specific_permission)) { if($this->Acl->Aro->Permission->delete(array('Permission.id' => $specific_permission['Permission']['id']))) { @@ -673,7 +616,7 @@ private function get_specific_permission_right($aro_node, $aco_path) $specific_permission = $this->Acl->Aro->Permission->find('first', array('conditions' => array('aro_id' => $aro_id, 'aco_id' => $aco_id))); - if($specific_permission !== false) + if(!empty($specific_permission)) { /* * Check the right (grant => true / deny => false) of this specific permission @@ -720,7 +663,7 @@ private function get_first_parent_permission_right($aro_node, $aco_path) $parent_permission = $this->Acl->Aro->Permission->find('first', array('conditions' => array('aro_id' => $aro_id, 'aco_id' => $parent_aco_id))); - if($parent_permission !== false) + if(!empty($parent_permission)) { /* * Check the right (grant => true / deny => false) of this first parent permission diff --git a/Locale/fre/LC_MESSAGES/acl.po b/Locale/fre/LC_MESSAGES/acl.po index 37c1fba..b7e8439 100644 --- a/Locale/fre/LC_MESSAGES/acl.po +++ b/Locale/fre/LC_MESSAGES/acl.po @@ -77,6 +77,10 @@ msgstr "le dossier %s est interdit en écriture" msgid "Created Aco node for controllers" msgstr "noeud ACO créé pour les contrôleurs" +#: Controller/Component/AclManagerComponent.php:297 +msgid "Aco node '%s' created" +msgstr "Le noeud ACO '%s' a été créé" + #: Controller/Component/AclManagerComponent.php:312 #, php-format msgid "Created Aco node for %s plugin" diff --git a/README b/README index 865a478..7ec2082 100644 --- a/README +++ b/README @@ -1,10 +1,10 @@ ACL Plugin for CakePHP 2.0 =========================== -Version: 2.2.0 -Date: 2012-09-24 +Version: 2.3.0 +Date: 2013-05-02 Author: Nicolas Rod -Website: http://www.alaxos.net/blaxos/pages/view/plugin_acl +Website: http://www.alaxos.net/blaxos/pages/view/plugin_acl_2.0 License: http://www.opensource.org/licenses/mit-license.php The MIT License This CakePHP plugin is an interface to manage an ACL protected web application.