Skip to content

Authorization Identity can() method need to allow second parms to optional.  #135

@hanumanyadav1989

Description

@hanumanyadav1989

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

image

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions