Skip to content

Commit

Permalink
Upgrading to version 2.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Dorsman committed Aug 13, 2013
1 parent 5ae0130 commit ce96fb2
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 139 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
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
Expand Down
10 changes: 5 additions & 5 deletions Config/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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);
?>
2 changes: 1 addition & 1 deletion Controller/AcosController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
10 changes: 5 additions & 5 deletions Controller/ArosController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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'];
}
Expand All @@ -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');
}
Expand Down
191 changes: 67 additions & 124 deletions Controller/Component/AclManagerComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
}
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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'])))
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions Locale/fre/LC_MESSAGES/acl.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions README
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
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.
Expand Down

0 comments on commit ce96fb2

Please sign in to comment.