I am able to control my application using ACL
, everything done perfectly and application is working smooth with ACL
and Auth
.
Now the problem is:
I have two tables, users
and posts
. there is no RBAC
(role based access control).
I am setting deny
and allow
for each user like follow.
//allow User1 to do everything
$user->id=1;
$this->ACL->allow($user,'controllers');
//allow User2 to add, edit and view the posts
$user->id=2;
$this->Acl->deny($user, 'controllers');
$this->Acl->allow($user, 'controllers/Posts');
but here I am getting one problem:
user2
is getting access to edit
the posts
of user1
.
example:
User1
created a post1
.
now User2
logged in now he can edit the User1
's post (i.e. post1- /localhost/myApp/posts/edit/1
)
Question: How can I set ACL permission to this problem, The owner of the post can only edit the post and others can not.
I can achieve this in controller level simply checking
if($_SESSION['Auth']['User']['id'] == $Post['Post']['user_id']){
// you're the owner, so u can edit
}else{
//u cant edit, this is not ur post
}
but I need ACL
to work here, Is it possible?, Please help
Thanks
$this->Acl->allow($user, 'controllers/Posts'/edit/1)
an so on? – Camisolepublic $actsAs = array('Acl' => array('type' => 'controlled'));
and create a node for every post too, the same way you create a node for every user – Camisole$this->Acl->check(...)
. ACL authorization handler just check the permission at an action level. See the manual – Camisole