This commit is contained in:
Andras Bacsai
2023-06-19 09:44:39 +02:00
parent 716c9aa860
commit 7bcbfc13b0
10 changed files with 45 additions and 17 deletions

View File

@@ -22,9 +22,12 @@ class Change extends Component
public function delete()
{
try {
PrivateKey::where('uuid', $this->private_key_uuid)->delete();
session('currentTeam')->privateKeys = PrivateKey::where('team_id', session('currentTeam')->id)->get();
redirect()->route('dashboard');
if ($this->private_key->isEmpty()) {
$this->private_key->delete();
session('currentTeam')->privateKeys = PrivateKey::where('team_id', session('currentTeam')->id)->get();
return redirect()->route('private-key.all');
}
$this->emit('error', 'This private key is in use and cannot be deleted. Please delete all servers, applications, and GitHub/GitLab apps that use this private key before deleting it.');
} catch (\Exception $e) {
return general_error_handler(err: $e, that: $this);
}

View File

@@ -65,7 +65,7 @@ class Form extends Component
return;
}
$this->server->delete();
redirect()->route('dashboard');
redirect()->route('server.all');
}
public function submit()
{

View File

@@ -57,7 +57,7 @@ class Change extends Component
{
try {
$this->github_app->delete();
redirect()->route('dashboard');
redirect()->route('source.all');
} catch (\Exception $e) {
return general_error_handler(err: $e, that: $this);
}

View File

@@ -16,9 +16,27 @@ class PrivateKey extends BaseModel
$selectArray = collect($select)->concat(['id']);
return PrivateKey::whereTeamId(session('currentTeam')->id)->where('id', '>', 0)->select($selectArray->all());
}
public function applications()
{
return $this->hasMany(Application::class);
}
public function githubApps()
{
return $this->hasMany(GithubApp::class);
}
public function gitlabApps()
{
return $this->hasMany(GitlabApp::class);
}
public function servers()
{
return $this->hasMany(Server::class);
}
public function isEmpty()
{
if ($this->servers()->count() === 0 && $this->applications()->count() === 0 && $this->githubApps()->count() === 0 && $this->gitlabApps()->count() === 0) {
return true;
}
return false;
}
}