From b5b36a8eb1b4d55e9188a76e3142b28b4f744ada Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 10 May 2023 11:02:59 +0200 Subject: [PATCH] deletion improvement --- app/Http/Livewire/Source/Github/Change.php | 3 --- app/Models/GithubApp.php | 9 +++++++++ resources/views/components/layout.blade.php | 1 + resources/views/source/github/show.blade.php | 1 - 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/Http/Livewire/Source/Github/Change.php b/app/Http/Livewire/Source/Github/Change.php index ad4a9b0c9..488c6fd10 100644 --- a/app/Http/Livewire/Source/Github/Change.php +++ b/app/Http/Livewire/Source/Github/Change.php @@ -4,10 +4,7 @@ namespace App\Http\Livewire\Source\Github; use App\Models\GithubApp; use App\Models\InstanceSettings; -use Illuminate\Support\Facades\Http; -use Illuminate\Support\Facades\Route; use Livewire\Component; -use Illuminate\Support\Str; class Change extends Component { diff --git a/app/Models/GithubApp.php b/app/Models/GithubApp.php index ec18e525e..99eb5b575 100644 --- a/app/Models/GithubApp.php +++ b/app/Models/GithubApp.php @@ -8,6 +8,15 @@ class GithubApp extends BaseModel protected $casts = [ 'is_public' => 'boolean', ]; + protected static function booted(): void + { + static::deleting(function (GithubApp $github_app) { + $applications_count = Application::where('source_id', $github_app->id)->count(); + if ($applications_count > 0) { + throw new \Exception('You cannot delete this GitHub App because it is in use by ' . $applications_count . ' application(s). Delete them first.'); + } + }); + } public function applications() { return $this->morphMany(Application::class, 'source'); diff --git a/resources/views/components/layout.blade.php b/resources/views/components/layout.blade.php index 05a45f111..dc76814f9 100644 --- a/resources/views/components/layout.blade.php +++ b/resources/views/components/layout.blade.php @@ -78,6 +78,7 @@ }) Livewire.on('error', (message) => { console.log(message); + alert(message); }) Livewire.on('saved', (message) => { if (message) console.log(message); diff --git a/resources/views/source/github/show.blade.php b/resources/views/source/github/show.blade.php index b0d705a43..b7c0b0e0b 100644 --- a/resources/views/source/github/show.blade.php +++ b/resources/views/source/github/show.blade.php @@ -64,5 +64,4 @@ Update Repositories @endif -