Files
coolify/app/Policies/GitlabAppPolicy.php
Andras Bacsai 5b370713c3 fix(sources): prevent 500 when deleting GitLab/GitHub apps
After delete, Livewire still re-renders the source change view (modal
$refresh / morph). Policy @can checks then call isAdminOfTeam() with a
null team_id and throw a TypeError (HTTP 500) before the redirect.

Guard null team_id in GitlabAppPolicy and GithubAppPolicy, clear the
Livewire model after delete, and skip @can when the model is gone.
2026-08-01 18:34:38 +02:00

88 lines
2.0 KiB
PHP

<?php
namespace App\Policies;
use App\Models\GitlabApp;
use App\Models\User;
class GitlabAppPolicy
{
/**
* Determine whether the user can view any models.
*/
public function viewAny(User $user): bool
{
return true;
}
/**
* Determine whether the user can view the model.
*/
public function view(User $user, GitlabApp $gitlabApp): bool
{
if ($gitlabApp->is_system_wide) {
return true;
}
return $user->teams->contains('id', $gitlabApp->team_id);
}
/**
* Determine whether the user can create models.
*/
public function create(User $user): bool
{
return $user->isAdmin();
}
/**
* Determine whether the user can update the model.
*/
public function update(User $user, GitlabApp $gitlabApp): bool
{
if ($gitlabApp->is_system_wide) {
return $user->canAccessSystemResources();
}
// Guard null team_id (e.g. post-delete Livewire re-render of @can checks).
if ($gitlabApp->team_id === null) {
return false;
}
return $user->isAdminOfTeam($gitlabApp->team_id);
}
/**
* Determine whether the user can delete the model.
*/
public function delete(User $user, GitlabApp $gitlabApp): bool
{
if ($gitlabApp->is_system_wide) {
return $user->canAccessSystemResources();
}
// Guard null team_id (e.g. post-delete Livewire re-render of @can checks).
if ($gitlabApp->team_id === null) {
return false;
}
return $user->isAdminOfTeam($gitlabApp->team_id);
}
/**
* Determine whether the user can restore the model.
*/
public function restore(User $user, GitlabApp $gitlabApp): bool
{
return false;
}
/**
* Determine whether the user can permanently delete the model.
*/
public function forceDelete(User $user, GitlabApp $gitlabApp): bool
{
return false;
}
}