How do I (safely) allow only admins and authors to edit data in CakePHP, without referring to hard-coded group IDs?
I'm using Auth and ACL in my CakePHP 2.4 app, so ordinarily I would just restrict the edit action to admins and moderators, but I also need to allow authors to edit data they've created.
I currently have this in my edit method, which works, but uses hard-coded values, which is bad practice: I set the ACLS to allow edit by default, and the controller redirects if the user is neither author nor admin.
Is there a way to respect the ACL settings (thus avoiding hard-coded group ids), while punching a hole through them for post authors?
if ($this->Auth->user('id') != $this->Post->field('user_id')) {
if ($this->Auth->user('group_id') > 2) {
$this->Session->setFlash(__('You are not authorized to edit this post.'), 'flash/error');
$this->redirect(array('action' => 'index'));
}
}