diff --git a/app/Http/Livewire/PrivateKey/Change.php b/app/Http/Livewire/PrivateKey/Change.php
index 28b18494e..568ed7486 100644
--- a/app/Http/Livewire/PrivateKey/Change.php
+++ b/app/Http/Livewire/PrivateKey/Change.php
@@ -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);
}
diff --git a/app/Http/Livewire/Server/Form.php b/app/Http/Livewire/Server/Form.php
index 39aff9b95..f1435ea28 100644
--- a/app/Http/Livewire/Server/Form.php
+++ b/app/Http/Livewire/Server/Form.php
@@ -65,7 +65,7 @@ public function delete()
return;
}
$this->server->delete();
- redirect()->route('dashboard');
+ redirect()->route('server.all');
}
public function submit()
{
diff --git a/app/Http/Livewire/Source/Github/Change.php b/app/Http/Livewire/Source/Github/Change.php
index b2bb9f75a..7908b179c 100644
--- a/app/Http/Livewire/Source/Github/Change.php
+++ b/app/Http/Livewire/Source/Github/Change.php
@@ -57,7 +57,7 @@ public function delete()
{
try {
$this->github_app->delete();
- redirect()->route('dashboard');
+ redirect()->route('source.all');
} catch (\Exception $e) {
return general_error_handler(err: $e, that: $this);
}
diff --git a/app/Models/PrivateKey.php b/app/Models/PrivateKey.php
index 39a6a8c8c..337e1555a 100644
--- a/app/Models/PrivateKey.php
+++ b/app/Models/PrivateKey.php
@@ -16,9 +16,27 @@ static public function ownedByCurrentTeam(array $select = ['*'])
$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;
+ }
}
diff --git a/config/toaster.php b/config/toaster.php
index 805927210..4dd1244b1 100644
--- a/config/toaster.php
+++ b/config/toaster.php
@@ -30,7 +30,7 @@
*
* Minimum: 3000 (in milliseconds)
*/
- 'duration' => 3000,
+ 'duration' => 5000,
/**
* The horizontal position of each toast.
diff --git a/config/version.php b/config/version.php
index b6e6dc283..b71f4008d 100644
--- a/config/version.php
+++ b/config/version.php
@@ -1,3 +1,3 @@