mirror of
https://github.com/tiennm99/coolify.git
synced 2026-09-03 18:16:43 +00:00
fix(user-deletion): handle GitHub app sources across team cleanup
Limit team cleanup to apps owned by the deleted team and nullify cross-team application source references before deleting team-owned sources. Adds feature tests covering user deletion with GitHub app-backed applications, preserving system-wide apps, and nullifying external source links.
This commit is contained in:
@@ -176,6 +176,23 @@ class User extends Authenticatable implements SendsEmail
|
||||
$project->forceDelete();
|
||||
}
|
||||
|
||||
// Detach applications from other teams that reference this team's sources,
|
||||
// so the GithubApp/GitlabApp deleting guard doesn't block team deletion
|
||||
$githubAppIds = GithubApp::where('team_id', $team->id)->pluck('id');
|
||||
$gitlabAppIds = GitlabApp::where('team_id', $team->id)->pluck('id');
|
||||
|
||||
if ($githubAppIds->isNotEmpty()) {
|
||||
Application::where('source_type', GithubApp::class)
|
||||
->whereIn('source_id', $githubAppIds)
|
||||
->update(['source_id' => null, 'source_type' => null]);
|
||||
}
|
||||
|
||||
if ($gitlabAppIds->isNotEmpty()) {
|
||||
Application::where('source_type', GitlabApp::class)
|
||||
->whereIn('source_id', $gitlabAppIds)
|
||||
->update(['source_id' => null, 'source_type' => null]);
|
||||
}
|
||||
|
||||
$team->members()->detach($user->id);
|
||||
$team->delete();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user