mirror of
https://github.com/coollabsio/coolify.git
synced 2026-03-11 08:55:47 +00:00
Restrict sensitive operations to admins/owners and hide sensitive data from team members: - Add authorization checks to Livewire components and API endpoints - Restrict team members from accessing sensitive permissions and data - Hide environment variable values from non-admin team members - Update policies to enforce team-level admin status requirement - Add useSensitivePermissions policy for read:sensitive tokens - Improve disabled button UX with auth-specific tooltips - Add authorization checks in middleware for API tokens Closes authorization gaps in project management, server management, and settings components.
89 lines
2.2 KiB
PHP
89 lines
2.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();
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can use read:sensitive permissions for API tokens.
|
|
*/
|
|
public function useSensitivePermissions(User $user): bool
|
|
{
|
|
return $user->isAdmin() || $user->isOwner();
|
|
}
|
|
}
|