Re: Sending ACL information to the client
On Tue, Mar 6, 2012 at 8:04 PM, Roland <roland.schuetz.vienna@gmail.com> wrote:
> Hmm.. that wasn't what I wanted to ask, let me try it new:
>
> Is there an efficient way to get for all 'articles' the allowed CRUD
> actions for the currently logged in user?
>
> So I can get something like this:
> array(array(
> 'id' => 34, // the article id
> '_read' => true,
> '_create' => true,
> '_update' => true,
> '_delete' => true,
> ), .... )
I had to do something like that once. Here's the code modified for
your models. Permission is just an alias for aros_acos.
$perms = $this->Acl->Aco->find(
'all',
array(
'fields' => array(
'Aco.foreign_key',
'Permission._create',
'Permission._read',
'Permission._update',
'Permission._delete'
),
'conditions' => array(
'Aco.model' => 'Article',
'Aco.id = Permission.aco_id'
),
'recursive' => -1,
'joins' => array(
array(
'table' => 'aros',
'alias' => 'Aro',
'type' => 'INNER',
'conditions'=> array(
'Aro.model' => 'User',
"Aro.foreign_key = ${user_id}"
)
),
array(
'table' => 'aros_acos',
'alias' => 'Permission',
'type' => 'INNER',
'conditions'=> array(
'Permission.aro_id = Aro.id',
'Permission._read >= 0'
)
)
)
)
);
--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home