Authorization Identity can() method need to allow second parms to optional.
I am using Authorization plugin and created Policies and these policies working good in the controller like can index/add/edit/delete but i have issue in the view index.php there i need to hide add button using can() method like below
if($this->request->getAttribute('identity')->can('add')){
echo $this->Html->link("<i class=\"fa fa-plus\"></i> " . __('New User'), ["action" => "add"], ["escape" => false]);
}
There we need second parameter newEmptyEntity object but i am in index function so i don't want to add newEmptyEntity object. when i used above script for hide add button then this error will be appear
(Error: Too few arguments to function Authorization\IdentityDecorator::can(), 1 passed in index.php on line 21 and exactly 2 expected.)
My policy method is this one:
public function canAdd(IdentityInterface $user)
{
if($user->is_supper_admin){
return true;
}
return false;
}
In this case i don't need second parameter so please resolve this issue

Thanks
If you have no resource how would the policy resolvers know which resource you want to check the add permission of?
But some time we don't need availability to resources like below:
When we are going to add() method and we want to set permission for this like only supper admin can able to add records in this case in add() method we have newEmptyEntity object resource so don't have any issue in this scenario.
But in the layout sidebar and index page we have "Add new user" button so we want to set permission also for this button means this button should be hide no need to display to another role users. so please let me know what we need to do in this case.
You could pass an new entity into 'create' permission checks. Or make the create permission use the Table object as a resource.
The possible ways to create/obtain a resource for this to work aside, is there a reason why mapping/resolving class names isn't supported? ie so that one could do something like $user->can('create', Article::class)?
... is there a reason why mapping/resolving class names isn't supported? ie so that one could do something like
$user->can('create', Article::class)?
The only limitation thus far has been a lack of imagination and use cases by previous contributors :smile: The OrmResolver could handle this scenario in addition to handling table/entity instances, it just needs doing :smile:
Weeeelllllll.... maybe I'll find a few minutes of spare time to give it a try :)
This issue is stale because it has been open for 120 days with no activity. Remove the stale label or comment or this will be closed in 15 days
Looks like I did, in fact, not find those few minutes of spare time 😰
This issue is stale because it has been open for 120 days with no activity. Remove the stale label or comment or this will be closed in 15 days
Should we handle this the same as we did in https://github.com/cakephp/authorization/pull/226?
@LordSimal That could work well.
This will be possible in the next major version.