Have a question about authorisation - not so much how it works but different practises
Reading the Cookbook and the Tutorial - it describe that you would have policy such as
public function canEdit(IdentityInterface $user, Article $article)
{
// logged in users can edit their own articles.
return $this->isAuthor($user, $article);
}
and then in the controller I would have
public function edit($slug)
{
$article = $this->Articles
->findBySlug($slug)
->contain('Tags') // load associated Tags
->firstOrFail();
$this->Authorization->authorize($article);
// Rest of the method.
}
This would use the policy with the current controller name. Alternatively I could use an operation name eg;
$this->Authorization->authorize($article, 'update');
Now all actions in my add are really based on the access level of a user;
- Viewer - Can only view records
- Editor - Can edit some records
- Super Editor - Can edit most records (cape optional )
- Admin - Can do anything
Because I have a lot of models and actions, I’m thinking I’d be best of with policies around the the user level, eg
$this->Authorization->authorize($member, 'super_editor');
This might make is simpler - I only need as many policies as I have access levels and should one need to change, it’s changed in the controller and not digging in to the policies.
Is there anything I’m missing / not considering? What have others done for large applications?