Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call to a member function hasPermissionTo() on null #192

Open
Ibragim091986 opened this issue Jan 6, 2024 · 0 comments
Open

Call to a member function hasPermissionTo() on null #192

Ibragim091986 opened this issue Jan 6, 2024 · 0 comments
Assignees
Labels

Comments

@Ibragim091986
Copy link

Apiato Core Version

8.7.0

PHP Version

8.2

Database Driver & Version

No response

Description

protected function hasAnyPermissionAccess($user): array
{
if (!array_key_exists('permissions', $this->access) || !$this->access['permissions']) {
return [];
}
$permissions = is_array($this->access['permissions']) ? $this->access['permissions'] :
explode('|', $this->access['permissions']);
return array_map(static function ($permission) use ($user) {
return $user->hasPermissionTo($permission);
}, $permissions);
}

This method triggers a "Call to a member function hasPermissionTo() on null" error if the middleware is removed from the Route, for example.

1

And if there is any value in the Permissions block in the Request.

2

I think the solution would be to check for the existence of $user in the closure before passing it to the anonymous function.

return array_map(static function ($permission) use ($user) {
return $user->hasPermissionTo($permission);
}, $permissions);

Steps To Reproduce

  1. Set values for checking in the Permissions block in the Request.
    2
  2. Remove the middleware method from the Route if it exists.
    1
  3. Pass this Request to a WebController.
    3
  4. Make a request to this Route.
@Mohammad-Alavi Mohammad-Alavi self-assigned this Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants