Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "cakephp/acl",
"name": "itnovum/acl",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will need to be reverted in order to be merged.

"description": "Acl Plugin for CakePHP framework",
"type": "cakephp-plugin",
"keywords": [
Expand All @@ -21,7 +21,7 @@
"source": "https://github.com/cakephp/acl"
},
"require": {
"php": "^7.2",
"php": ">=7.2",
"cakephp/cakephp": "^4.0",
"cakephp/plugin-installer": "^1.2"
},
Expand Down
18 changes: 13 additions & 5 deletions src/Model/Behavior/AclBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,16 @@ public function __construct(Table $model, array $config = [])
}
foreach ($types as $type) {
$alias = Inflector::pluralize($type);
$className = App::className($alias . 'Table', 'Model/Table');
$className = App::className($alias, 'Model/Table', 'Table');
if ($className == false) {
$className = App::className('Acl.' . $alias . 'Table', 'Model/Table');
$className = App::className('Acl.' . $alias, 'Model/Table', 'Table');
}
$config = [];
if (!TableRegistry::getTableLocator()->exists($alias)) {
$config = ['className' => $className];
}
$model->hasMany($type, [

$model->hasMany($alias, [
'targetTable' => TableRegistry::getTableLocator()->get($alias, $config),
]);
}
Expand All @@ -94,7 +95,7 @@ public function __construct(Table $model, array $config = [])
* Retrieves the Aro/Aco node for this model
*
* @param string|array|Model $ref Array with 'model' and 'foreign_key', model object, or string value
* @param string $type Only needed when Acl is set up as 'both', specify 'Aro' or 'Aco' to get the correct node
* @param string $type Pluralized! Only needed when Acl is set up as 'both', specify 'Aros' or 'Acos' to get the correct node
* @return \Cake\ORM\Query
* @link http://book.cakephp.org/2.0/en/core-libraries/behaviors/acl.html#node
* @throws \Cake\Core\Exception\Exception
Expand All @@ -113,7 +114,12 @@ public function node($ref = null, $type = null)
throw new Exception\Exception(__d('cake_dev', 'ref parameter must be a string or an Entity'));
}

return $this->_table->{$type}->node($ref);
if(property_exists($this->_table, $type)){
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(property_exists($this->_table, $type)){
if (property_exists($this->_table, $type)){

You'll need to apply the code formatting standards. You can do that with vendor/phpcbf src tests

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @markstory sorry for my late response to this.
I have created a new branch to merge the upstream changes. I also executed phpcbf but this had made so many code changes, that I would recommend to do this in a second step.

A TOTAL OF 526 ERRORS WERE FIXED IN 53 FILES

I guess otherwise the diff is getting to large. What do you think?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, we can update phpcs separately.

return $this->_table->{$type}->node($ref);
}else{
$type = Inflector::pluralize($type);
return $this->_table->{$type}->node($ref);
}
}

/**
Expand All @@ -131,6 +137,7 @@ public function afterSave(Event $event, Entity $entity)
$types = [$types];
}
foreach ($types as $type) {
$type = Inflector::pluralize($type);
$parent = $entity->parentNode();
if (!empty($parent)) {
$parent = $this->node($parent, $type)->first();
Expand Down Expand Up @@ -171,6 +178,7 @@ public function afterDelete(Event $event, Entity $entity)
$types = [$types];
}
foreach ($types as $type) {
$type = Inflector::pluralize($type);
$node = $this->node($entity, $type)->toArray();
if (!empty($node)) {
$event->getSubject()->{$type}->delete($node[0]);
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Table/AclNodesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function node($ref = null)

if (empty($ref)) {
return null;
} elseif (is_int($ref) || ctype_digit($ref)) {
} elseif (is_numeric($ref)) {
$ref = [
'id' => $ref,
];
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Table/AcoActionsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class AcoActionsTable extends Table
public function initialize(array $config) :void
{
$this->belongsTo('Acos', [
'className' => App::className('Acl.AcosTable', 'Model/Table'),
'className' => 'Acl.Acos'
]);
}
}
8 changes: 4 additions & 4 deletions src/Model/Table/AcosTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ public function initialize(array $config) :void
$this->addBehavior('Tree', ['type' => 'nested']);

$this->belongsToMany('Aros', [
'through' => App::className('Acl.PermissionsTable', 'Model/Table'),
'className' => App::className('Acl.ArosTable', 'Model/Table'),
'through' => 'Acl.Permissions',
'className' => 'Acl.Aros',
]);
$this->hasMany('AcoChildren', [
'className' => App::className('Acl.AcosTable', 'Model/Table'),
'className' => 'Acl.Acos',
'foreignKey' => 'parent_id',
]);
$this->setEntityClass(App::className('Acl.Aco', 'Model/Entity'));
$this->setEntityClass('Acl.Aco');
}
}
6 changes: 3 additions & 3 deletions src/Model/Table/ArosTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ public function initialize(array $config) :void
$this->addBehavior('Tree', ['type' => 'nested']);

$this->belongsToMany('Acos', [
'through' => App::className('Acl.PermissionsTable', 'Model/Table'),
'className' => App::className('Acl.AcosTable', 'Model/Table'),
'through' => 'Acl.Permissions',
'className' => 'Acl.Acos',
]);
$this->hasMany('AroChildren', [
'className' => App::className('Acl.ArosTable', 'Model/Table'),
'className' => 'Acl.Aros',
'foreignKey' => 'parent_id',
]);

Expand Down
8 changes: 4 additions & 4 deletions src/Model/Table/PermissionsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ public function initialize(array $config) :void
$this->setAlias('Permissions');
$this->setTable('aros_acos');
$this->belongsTo('Aros', [
'className' => App::className('Acl.ArosTable', 'Model/Table'),
'className' => 'Acl.Aros'
]);
$this->belongsTo('Acos', [
'className' => App::className('Acl.AcosTable', 'Model/Table'),
'className' => 'Acl.Acos'
]);
$this->Aro = $this->Aros->getTarget();
$this->Aco = $this->Acos->getTarget();
Expand Down Expand Up @@ -230,8 +230,8 @@ public function getAclLink($aro, $aco)
if (empty($obj['Aro']) || empty($obj['Aco'])) {
return false;
}
$aro = $obj['Aro']->extract('id')->toArray();
$aco = $obj['Aco']->extract('id')->toArray();
$aro = $obj['Aro']->all()->extract('id')->toArray();
$aco = $obj['Aco']->all()->extract('id')->toArray();
$aro = current($aro);
$aco = current($aco);
$alias = $this->getAlias();
Expand Down