mirror of
https://github.com/tiennm99/coolify.git
synced 2026-08-21 08:25:45 +00:00
fix(auth): enforce authorization checks across API and Livewire components
- 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
This commit is contained in:
@@ -20,8 +20,9 @@ class EnvironmentPolicy
|
||||
*/
|
||||
public function view(User $user, Environment $environment): bool
|
||||
{
|
||||
// return $user->teams->contains('id', $environment->project->team_id);
|
||||
return true;
|
||||
$teamId = $this->getTeamId($environment);
|
||||
|
||||
return $teamId !== null && $user->teams->contains('id', $teamId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -29,8 +30,7 @@ class EnvironmentPolicy
|
||||
*/
|
||||
public function create(User $user): bool
|
||||
{
|
||||
// return $user->isAdmin();
|
||||
return true;
|
||||
return $user->isAdmin();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -38,8 +38,9 @@ class EnvironmentPolicy
|
||||
*/
|
||||
public function update(User $user, Environment $environment): bool
|
||||
{
|
||||
// return $user->isAdmin() && $user->teams->contains('id', $environment->project->team_id);
|
||||
return true;
|
||||
$teamId = $this->getTeamId($environment);
|
||||
|
||||
return $teamId !== null && $user->isAdminOfTeam($teamId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -47,8 +48,9 @@ class EnvironmentPolicy
|
||||
*/
|
||||
public function delete(User $user, Environment $environment): bool
|
||||
{
|
||||
// return $user->isAdmin() && $user->teams->contains('id', $environment->project->team_id);
|
||||
return true;
|
||||
$teamId = $this->getTeamId($environment);
|
||||
|
||||
return $teamId !== null && $user->isAdminOfTeam($teamId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,8 +58,7 @@ class EnvironmentPolicy
|
||||
*/
|
||||
public function restore(User $user, Environment $environment): bool
|
||||
{
|
||||
// return $user->isAdmin() && $user->teams->contains('id', $environment->project->team_id);
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,7 +66,11 @@ class EnvironmentPolicy
|
||||
*/
|
||||
public function forceDelete(User $user, Environment $environment): bool
|
||||
{
|
||||
// return $user->isAdmin() && $user->teams->contains('id', $environment->project->team_id);
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private function getTeamId(Environment $environment): ?int
|
||||
{
|
||||
return $environment->project?->team_id;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user