conflict with permissions and custom policies #2372
Replies: 3 comments
-
Hi, you do not offer the necessary information to review laravel-permission/.github/ISSUE_TEMPLATE/bug_report.md Lines 11 to 42 in c7e0eb2 |
Beta Was this translation helpful? Give feedback.
-
Hi. My permissions with laravel-permission are
and I have a policy created namespace App\Policies;
use App\Models\Post;
use App\Models\User;
use Illuminate\Auth\Access\HandlesAuthorization;
class PostPolicy
{
use HandlesAuthorization;
/**
* @param User $user
* @param Post $post
* @return bool
*/
public function edit(User $user, Post $post): bool
{
return $post->user_id == $user->id;
}
} When you create a super admin user, it is necessary to be able to perform all the permissions regardless of whether you have access or not, it was solved with a gate in "app/Providers/AuthServiceProvider.php" Gate::before(function (User $user, $ability) {
return $user->isSuperAdmin() ? true:null;
}); The problem is that the superAdmin can perform all the functions with or without access, but it also gives him the possibility to edit the post of other users and this should not be allowed. |
Beta Was this translation helpful? Give feedback.
-
It's possible you require also a See: https://spatie.be/docs/laravel-permission/v5/basic-usage/super-admin#content-gateafter |
Beta Was this translation helpful? Give feedback.
-
I am currently using Laravel-permission for access management in my Laravel project, but I have a problem, I need to generate a "SuperAdmin" user that consists of passing all access permissions but I also have registered policies that validate other factors
My problem is that I need the user to pass all the permissions of Laravel-permission but to respect the custom policies that were generated.
Beta Was this translation helpful? Give feedback.
All reactions