mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Fixing permissions setting for ACL
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4493 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
45bff19372
commit
b50b478f8a
4 changed files with 61 additions and 8 deletions
|
@ -262,12 +262,10 @@ class DB_ACL extends AclBase {
|
||||||
$Link = new Permission();
|
$Link = new Permission();
|
||||||
|
|
||||||
$obj = array();
|
$obj = array();
|
||||||
$obj['Aro'] = $Aro->find($Aro->_resolveID($aro));
|
$obj['Aro'] = $Aro->node($aro);
|
||||||
$obj['Aco'] = $Aco->find($Aco->_resolveID($aco));
|
$obj['Aco'] = $Aco->node($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) {
|
if (empty($obj['Aro']) || empty($obj['Aco'])) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,6 +52,47 @@ class AclNode extends AppModel {
|
||||||
* @var mixed
|
* @var mixed
|
||||||
*/
|
*/
|
||||||
var $actsAs = array('Tree' => 'nested');
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -58,5 +58,11 @@ class Permission extends AppModel {
|
||||||
* @var unknown_type
|
* @var unknown_type
|
||||||
*/
|
*/
|
||||||
var $useTable = 'aros_acos';
|
var $useTable = 'aros_acos';
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @var unknown_type
|
||||||
|
*/
|
||||||
|
var $actsAs = null;
|
||||||
}
|
}
|
||||||
?>
|
?>
|
|
@ -62,7 +62,6 @@ class AclBehavior extends ModelBehavior {
|
||||||
trigger_error("Callback parentNode() not defined in {$model->name}", E_USER_WARNING);
|
trigger_error("Callback parentNode() not defined in {$model->name}", E_USER_WARNING);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the Aro/Aco node for this model
|
* Retrieves the Aro/Aco node for this model
|
||||||
*
|
*
|
||||||
|
@ -105,7 +104,12 @@ class AclBehavior extends ModelBehavior {
|
||||||
}
|
}
|
||||||
return $result;
|
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) {
|
function afterSave(&$model, $created) {
|
||||||
if ($created) {
|
if ($created) {
|
||||||
$type = $this->__typeMaps[low($this->settings[$model->name]['type'])];
|
$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) {
|
function afterDelete(&$model) {
|
||||||
$node = $this->node($model);
|
$node = $this->node($model);
|
||||||
$type = $this->__typeMaps[low($this->settings[$model->name]['type'])];
|
$type = $this->__typeMaps[low($this->settings[$model->name]['type'])];
|
||||||
|
|
Loading…
Add table
Reference in a new issue