diff --git a/cake/libs/controller/components/dbacl/db_acl.php b/cake/libs/controller/components/dbacl/db_acl.php index eb6c0c185..66e15ac65 100644 --- a/cake/libs/controller/components/dbacl/db_acl.php +++ b/cake/libs/controller/components/dbacl/db_acl.php @@ -262,12 +262,10 @@ class DB_ACL extends AclBase { $Link = new Permission(); $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']; + $obj['Aro'] = $Aro->node($aro); + $obj['Aco'] = $Aco->node($aco); - if ($obj['Aro'] == null || count($obj['Aro']) == 0 || $obj['Aco'] == null || count($obj['Aco']) == 0) { + if (empty($obj['Aro']) || empty($obj['Aco'])) { return false; } diff --git a/cake/libs/controller/components/dbacl/models/aclnode.php b/cake/libs/controller/components/dbacl/models/aclnode.php index 5e74ab048..652dfab8d 100644 --- a/cake/libs/controller/components/dbacl/models/aclnode.php +++ b/cake/libs/controller/components/dbacl/models/aclnode.php @@ -52,6 +52,47 @@ class AclNode extends AppModel { * @var mixed */ var $actsAs = array('Tree' => 'nested'); +/** + * Retrieves the Aro/Aco node for this model + * + * @param mixed $ref + * @return array + */ + function node($ref = null) { + $db =& ConnectionManager::getDataSource($this->useDbConfig); + $type = $this->name; + $table = low($type) . 's'; + $prefix = $this->tablePrefix; + + if (empty($ref)) { + $ref = array('model' => $this->name, 'foreign_key' => $this->id); + } elseif (is_string($ref)) { + $path = explode('/', $ref); + $start = $path[count($path) - 1]; + unset($path[count($path) - 1]); + + $query = "SELECT {$type}0.* From {$prefix}{$table} AS {$type}0 "; + foreach ($path as $i => $alias) { + $j = $i - 1; + $k = $i + 1; + $query .= "LEFT JOIN {$prefix}{$table} AS {$type}{$k} "; + $query .= "ON {$type}{$k}.lft > {$type}{$i}.lft && {$type}{$k}.rght < {$type}{$i}.rght "; + $query .= "AND {$type}{$k}.alias = " . $db->value($alias) . " "; + } + $result = $this->query("{$query} WHERE {$type}0.alias = " . $db->value($start)); + + if (!empty($result)) { + $result = $result[0]["{$type}0"]; + } + } elseif (is_object($ref) && is_a($ref, 'Model')) { + $ref = array('model' => $ref->name, 'foreign_key' => $ref->id); + } + + if (is_array($ref)) { + list($result) = array_values($this->find($ref, null, null, -1)); + } + return $result; + } } ?> \ No newline at end of file diff --git a/cake/libs/controller/components/dbacl/models/permission.php b/cake/libs/controller/components/dbacl/models/permission.php index f40e231ba..ca2bcd25a 100644 --- a/cake/libs/controller/components/dbacl/models/permission.php +++ b/cake/libs/controller/components/dbacl/models/permission.php @@ -58,5 +58,11 @@ class Permission extends AppModel { * @var unknown_type */ var $useTable = 'aros_acos'; +/** + * Enter description here... + * + * @var unknown_type + */ + var $actsAs = null; } ?> \ No newline at end of file diff --git a/cake/libs/model/behaviors/acl.php b/cake/libs/model/behaviors/acl.php index 80ca7811a..1f1b9d52c 100644 --- a/cake/libs/model/behaviors/acl.php +++ b/cake/libs/model/behaviors/acl.php @@ -62,7 +62,6 @@ class AclBehavior extends ModelBehavior { trigger_error("Callback parentNode() not defined in {$model->name}", E_USER_WARNING); } } - /** * Retrieves the Aro/Aco node for this model * @@ -105,7 +104,12 @@ class AclBehavior extends ModelBehavior { } return $result; } - +/** + * Creates a new ARO/ACO node bound to this record + * + * @param boolean $created True if this is a new record + * @return void + */ function afterSave(&$model, $created) { if ($created) { $type = $this->__typeMaps[low($this->settings[$model->name]['type'])]; @@ -116,7 +120,11 @@ class AclBehavior extends ModelBehavior { )); } } - +/** + * Destroys the ARO/ACO node bound to the deleted record + * + * @return void + */ function afterDelete(&$model) { $node = $this->node($model); $type = $this->__typeMaps[low($this->settings[$model->name]['type'])];