I’m new to CakePHP, just followed the CMS tutorial and trying to figure out how authorization component works.
Auth on single Entity works fine, but when I create a table policy class for my Entity I don’t know how to implement the actions, this is the actual code:
class utentivaleTablePolicy
{
public function canIndex(IdentityInterface $user, utentivale $utentivale)
{
return true;
}
public function scopeIndex(IdentityInterface $user, utentivale $utentivale )
{
return $user->role_id== $user::TYPE_ADMIN;
}
}
In the controller class, index method:
public function index()
{
Same issue here. I would like to set authorization policy to the users controller, but i cannot figure out because i get stuck at " Policy for Cake\ORM\ResultSet has not been defined" error…
The example is the cms in the toturial. How can i set authorization to the view and index method?
A little help would be much appreciated, thanks in advance.
To send the Table class and accept “UtentivaleTable” object as the second parameter in the policy’s canIndex function:
// In controller’s index() action
$this->Authorization->authorize($this->Utentivale);
// In policy class:
public function canIndex(IdentityInterface $user, UtentivaleTable $utentivale)
{
return true;
}
To send the query and accept Cake\ORM\Query object as the second parameter in the policy’s canIndex function:
// In controller’s index() action
$query = $this->Utentivale->find();
$this->Authorization->authorize($query);
$utentivale = $this->paginate($query);
// In policy class:
public function canIndex(IdentityInterface $user, Cake\ORM\Query $query)
{
return true;
}
There could be more solutions available. But, haven’t tried anything else.
Hope this works.