Skip to content

Commit

Permalink
revert auth gate back
Browse files Browse the repository at this point in the history
  • Loading branch information
atoff committed Dec 1, 2024
1 parent ddbafa2 commit 22fa7fd
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions app/Providers/AuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Gate;
use Spatie\Permission\Exceptions\PermissionDoesNotExist;
use Spatie\Permission\Models\Role;
use Spatie\Permission\PermissionRegistrar;

Expand Down Expand Up @@ -82,11 +83,18 @@ public function boot()
$permissionLoader->registerPermissions($gate);
});

if (config()->get('app.env') != 'production') {
// Allow for a global superadmin role on non-production environments
Gate::before(function ($user, $abilityOrPermission) {
return $user->hasRole('privacc') ?? null;
});
}
// TODO: Remove 'use-permission' across codebase - use user()->can instead
Gate::define('use-permission', function ($user, $permission) {
// Superadmin override
if ($user->hasRole('privacc') && config()->get('app.env') != 'production') {
return true;
}

try {
return auth()->user()->hasPermissionTo($permission);
} catch (PermissionDoesNotExist $e) {
return false;
}
});
}
}

0 comments on commit 22fa7fd

Please sign in to comment.