Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding patch from 'Ceeram' and 'TehTreag' to implement automatic upda…

…ting of Aro/Aco nodes created AclBehavior. Test cases added. Fixes #33 and #4261
  • Loading branch information...
commit d5376e64aadab9597fada0fb2d0a55e2dd315ff2 1 parent b95d9e1
Mark Story markstory authored
30 cake/libs/model/behaviors/acl.php
View
@@ -90,22 +90,22 @@ function node(&$model, $ref = null) {
* @access public
*/
function afterSave(&$model, $created) {
- if ($created) {
- $type = $this->__typeMaps[strtolower($this->settings[$model->name]['type'])];
- $parent = $model->parentNode();
- if (!empty($parent)) {
- $parent = $this->node($model, $parent);
- } else {
- $parent = null;
- }
-
- $model->{$type}->create();
- $model->{$type}->save(array(
- 'parent_id' => Set::extract($parent, "0.{$type}.id"),
- 'model' => $model->name,
- 'foreign_key' => $model->id
- ));
+ $type = $this->__typeMaps[strtolower($this->settings[$model->alias]['type'])];
+ $parent = $model->parentNode();
+ if (!empty($parent)) {
+ $parent = $this->node($model, $parent);
+ }
+ $data = array(
+ 'parent_id' => isset($parent[0][$type]['id']) ? $parent[0][$type]['id'] : null,
+ 'model' => $model->alias,
+ 'foreign_key' => $model->id
+ );
+ if (!$created) {
+ $node = $this->node($model);
+ $data['id'] = isset($node[0][$type]['id']) ? $node[0][$type]['id'] : null;
}
+ $model->{$type}->create();
+ $model->{$type}->save($data);
}
/**
22 cake/tests/cases/libs/model/behaviors/acl.test.php
View
@@ -314,6 +314,28 @@ function testAfterSave() {
$this->assertEqual(sizeof($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);
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.