Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group-only seem to doesn't work #30

Closed
Xety opened this issue Jan 17, 2015 · 5 comments
Closed

Group-only seem to doesn't work #30

Xety opened this issue Jan 17, 2015 · 5 comments
Labels
Milestone

Comments

@Xety
Copy link
Contributor

Xety commented Jan 17, 2015

Hello,

Because this plugin has been ported from Cake2, i assume that the "Group-only" must work as well, but no.
I have followed the instruction here : http://book.cakephp.org/2.0/en/tutorials-and-examples/simple-acl-controlled-application/simple-acl-controlled-application.html#group-only-acl but it actually doesn't work.
The key 'enabled' => false look like it isn't checked. I have also check all ACL releated files in Cake2 and i saw nothing about that.

In my UsersTable :

$this->addBehavior('Acl.Acl', [
    'type' => 'requester',
    'enabled' => false
]);

$this->belongsTo('Groups', [
    'foreignKey' => 'group_id'
]);

In my GroupTable :

$this->addBehavior('Acl.Acl', [
    'type' => 'requester'
]);

$this->hasMany('Users', [
    'foreignKey' => 'group_id'
]);

In my UserEntity :

public function parentNode() {
    if (!$this->id) {
        return null;
    }
    if (isset($this->group_id)) {
        $groupId = $this->group_id;
    }
    if (!$groupId) {
        return null;
    }

    return ['Groups' => ['id' => $groupId]];
}

public function bindNode($user) {
    return ['model' => 'Groups', 'foreign_key' => $user->group_id];
}

In my GroupEntity :

public function parentNode() {
    return null;
}

In my database the aros table look like that :
zplpm5g

And i got this error when i try to make a request:

AclNode::node() - Couldn't find Aros node identified by "Array ( [Aros0.model] => Users [Aros0.foreign_key] => 1 ) " 

Where 1 is the user_id and not the group_id.

I have also noticed that when i add an user, it doesn't create the ARO, so that look like to work well.

@lorenzo
Copy link
Member

lorenzo commented Jan 17, 2015

Just out of curiosity, try:

$this->addBehavior('Acl.Acl', [
    'type' => 'requester'
]);
$this->eventManager()->detach($this->behaviors()->get('Acl'));

@lorenzo lorenzo added this to the 1.0 milestone Jan 17, 2015
@Xety
Copy link
Contributor Author

Xety commented Jan 17, 2015

I just tested and it changed nothing.

Edit: I found the problem, i do some tests before to post the problem.

@Xety
Copy link
Contributor Author

Xety commented Jan 17, 2015

Ok, so the problem is this line :
https://github.com/cakephp/acl/blob/master/src/Model/Table/AclNodesTable.php#L113
The $this->entityClass() return all times Acl\Model\Entity\Aro. That's why the function bindNode() in the UserEntity was never executed. I just changed this line by :

\Cake\Core\App::className(\Cake\Utility\Inflector::singularize($name), 'Model/Entity')

and it return the correct entity App\Model\Entity\User so the function bindNode() is correctly executed here :
https://github.com/cakephp/acl/blob/master/src/Model/Table/AclNodesTable.php#L123-L124

I saw this problem by checking again the Cake2 ACL :
https://github.com/cakephp/cakephp/blob/master/lib/Cake/Model/AclNode.php#L131

@markstory markstory added the bug label Jan 18, 2015
@markstory
Copy link
Member

We can't assume that people will always have concrete Entity classes. It might be best to get the correct Table class and use that to get an entity instance:

$table = TableRegistry::get($name);
$entityClass = $table->entityClass();

@Xety
Copy link
Contributor Author

Xety commented Jan 18, 2015

@markstory Yes you're right, thank for your help !

I close because #31 is open now.

@Xety Xety closed this as completed Jan 18, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants