0

I am using cakephp 2.3.0 and working with ACL. I am giving the permission to a group as follows:

$group->id = 2;
$this->Acl->deny($group, 'controllers');
$this->Acl->allow($group, 'controllers/Posts');

Now how can I check 'controllers/Posts' is allowed for $group->id = 2 from same controller?

I am trying

$this->Acl->check('controllers/Posts', '2');

but it always return false and generate warning:

Failed ARO/ACO node lookup in permissions check. Node references:
Aro: controllers/Pages
Aco: Data entry operator

Please help me. Thanks.

Nunser
  • 4,512
  • 8
  • 25
  • 37
Tahmina Khatoon
  • 1,081
  • 3
  • 11
  • 29

2 Answers2

3

Syntax

$this->Acl->check(array(
    'model' => 'ModelName',       # The name of the Model to check agains
    'foreign_key' => $foreign_key # The foreign key the Model is bind to
), 'Controller/action');          # The controller and action to check the permissions for

Which results in the following call:

As a User

$this->Acl->check(array(
    'model' => 'User',
    'foreign_key' => $userId
), 'Posts/index');

As a Group

$this->Acl->check(array(
    'model' => 'Group',
    'foreign_key' => $groupId
), 'Posts/index');

I wrote it down including some linebreaks for readability.

More info at:

Community
  • 1
  • 1
Jelmer
  • 2,663
  • 2
  • 27
  • 45
  • One more question, $this->Acl->check() is very slow. takes too long to check all the resource. Has there any way faster way? – Tahmina Khatoon May 31 '13 at 03:49
  • You could cache every unique entry in an array in you Session. That way you don't have to check it several times. Just extend the AuthComponent and add a new method which tries to check the session data first. *Note: when you updated the ACL table and the user didn't destroy it's session, I won't be known by the session, just keep that in mind ;-)* But no, there aren't any faster ways other than caching. Sad enough. But generally the ACL tables doesn't get changed that often. – Jelmer May 31 '13 at 07:58
0

checking a node permission is very similar to setting that permission ie

$group->id = 2;
 $this->Acl->check($group, 'controllers/Posts');
Faiyaz Alam
  • 1,191
  • 9
  • 27