Can I override the models of acl acos?
What do I have to put in the table and entity classes so that it doesn’t give me the exception AclNode::node() - Couldn’t find Acos node identified by "Array
(
[Acos0.model] => MyAcos
[Acos0.foreign_key] => 8
)
"
when I try to allow and aco for an aro?
This is the code for the action permissions in GroupsController:
public function permissions()
{
$this->loadModel('MyAcos');
if ($this->request->is(['post'])) {
$group = $this->Groups->get($this->request->getData('group_id'));
$aco = $this->MyAcos->get($this->request->getData('aco_id'));
$this->Acl->allow($group, $aco);
return $this->redirect(['action' => 'index']);
}
$acos = $this->MyAcos->find('list', ['limit' => 200])->order('id');
$groups = $this->Groups->find('list', ['limit' => 200]);
$this->set(compact('acos', 'groups'));
}
This is the code for permissions.php template:
<?php
/**
* @var \App\View\AppView $this
* @var \App\Model\Entity\User $user
* @var \Cake\Collection\CollectionInterface|string[] $groups
* @var \Cake\Collection\CollectionInterface|string[] $enterprises
*/
?>
<div class="row">
<aside class="column">
<div class="side-nav">
<h4 class="heading"><?= __('Acciones') ?></h4>
<?= $this->Html->link(__('Listar Grupos'), ['action' => 'index'], ['class' => 'side-nav-item']) ?>
</div>
</aside>
<div class="column-responsive column-80">
<div class="users form content">
<?= $this->Form->create() ?>
<fieldset>
<legend><?= __('Crear permisos') ?></legend>
<?php
echo $this->Form->control('group_id', ['label' => 'Grupo', 'options' => $groups, 'empty' => '- Seleccione un grupo -']);
echo $this->Form->control('aco_id', ['label' => 'Control de acceso', 'options' => $acos, 'empty' => '- Seleccione un control de acceso -']);
?>
</fieldset>
<?= $this->Form->button(__('Crear')) ?>
<?= $this->Form->end() ?>
</div>
</div>
</div>
This is the code for MyAcosTable.php:
<?php
declare(strict_types=1);
namespace App\Model\Table;
use Acl\Model\Table\AcosTable;
class MyAcosTable extends AcosTable
{
/**
* Initialize method
*
* @param array $config The configuration for the Table.
* @return void
*/
public function initialize(array $config): void
{
parent::initialize($config);
$this->setDisplayField('alias');
}
}
And this is the code for MyAcos.php:
<?php
declare(strict_types=1);
namespace App\Model\Entity;
use Acl\Model\Entity\Aco;
class MyAcos extends Aco
{
public function bindNode($user) {
return ['model' => 'Groups', 'foreign_key' => $user['Users']['group_id']];
}
}