Skip to content

Commit

Permalink
Only run gate checks if the user is a statamic user
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmitchell committed Sep 26, 2024
1 parent 6e5d6a2 commit 01e943b
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/Providers/AuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Statamic\Contracts\Auth\RoleRepository;
use Statamic\Contracts\Auth\UserGroupRepository;
use Statamic\Contracts\Auth\UserRepository;
use Statamic\Contracts\Auth\User as UserContract;
use Statamic\Facades\User;
use Statamic\Policies;

Expand Down Expand Up @@ -84,11 +85,19 @@ public function boot()
});

Gate::before(function ($user, $ability) {
return optional(User::fromUser($user))->isSuper() ? true : null;
if (! $user instanceof UserContract) {
return null;
}

return $user->isSuper() ? true : null;
});

Gate::after(function ($user, $ability) {
return optional(User::fromUser($user))->hasPermission($ability) === true ? true : null;
if (! $user instanceof UserContract) {
return null;
}

return $user->hasPermission($ability) === true ? true : null;
});

foreach ($this->policies as $key => $policy) {
Expand Down

0 comments on commit 01e943b

Please sign in to comment.