mirror of
https://github.com/coollabsio/coolify.git
synced 2026-03-11 08:55:47 +00:00
- Add authorization checks to API controller endpoints (view, create, update, delete) - Wrap Livewire component methods with try-catch for consistent error handling - Add AuthorizesRequests trait to components requiring authorization checks - Ensure all sensitive operations verify user permissions before execution - Implement unified error handling with handleError() helper function
81 lines
2 KiB
PHP
81 lines
2 KiB
PHP
<?php
|
|
|
|
namespace App\Policies;
|
|
|
|
use App\Models\User;
|
|
use Laravel\Sanctum\PersonalAccessToken;
|
|
|
|
class ApiTokenPolicy
|
|
{
|
|
/**
|
|
* Determine whether the user can view any API tokens.
|
|
*/
|
|
public function viewAny(User $user): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can view the API token.
|
|
*/
|
|
public function view(User $user, PersonalAccessToken $token): bool
|
|
{
|
|
return $user->id === $token->tokenable_id && $token->tokenable_type === User::class;
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can create API tokens.
|
|
*/
|
|
public function create(User $user): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can update the API token.
|
|
*/
|
|
public function update(User $user, PersonalAccessToken $token): bool
|
|
{
|
|
return $user->id === $token->tokenable_id && $token->tokenable_type === User::class;
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can delete the API token.
|
|
*/
|
|
public function delete(User $user, PersonalAccessToken $token): bool
|
|
{
|
|
return $user->id === $token->tokenable_id && $token->tokenable_type === User::class;
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can manage their own API tokens.
|
|
*/
|
|
public function manage(User $user): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can use root permissions for API tokens.
|
|
*/
|
|
public function useRootPermissions(User $user): bool
|
|
{
|
|
return $user->isAdmin() || $user->isOwner();
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can use write permissions for API tokens.
|
|
*/
|
|
public function useWritePermissions(User $user): bool
|
|
{
|
|
return $user->isAdmin() || $user->isOwner();
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can use deploy permissions for API tokens.
|
|
*/
|
|
public function useDeployPermissions(User $user): bool
|
|
{
|
|
return $user->isAdmin() || $user->isOwner();
|
|
}
|
|
}
|