From 8f3ef2b1c507de375fdf1c21eeb331d9e7387a01 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Fri, 16 Jun 2023 15:56:25 +0200 Subject: [PATCH] fixes --- app/Http/Controllers/Controller.php | 1 + app/Http/Livewire/Team/Delete.php | 30 ++++++++++++ app/Models/Team.php | 7 +++ app/Models/User.php | 2 +- resources/js/components/MagicBar.vue | 13 ++++- .../views/components/naked-modal.blade.php | 14 +++--- .../views/livewire/destination/form.blade.php | 3 +- .../livewire/private-key/change.blade.php | 3 +- .../project/application/danger.blade.php | 7 +-- .../environment-variable/show.blade.php | 3 +- .../application/storages/show.blade.php | 3 +- .../project/delete-environment.blade.php | 3 +- .../livewire/project/delete-project.blade.php | 3 +- .../views/livewire/server/form.blade.php | 3 +- .../views/livewire/server/proxy.blade.php | 4 +- .../livewire/source/github/change.blade.php | 3 +- .../views/livewire/team/delete.blade.php | 47 +++++++++++++++++++ resources/views/team/show.blade.php | 2 + routes/web.php | 2 - 19 files changed, 130 insertions(+), 23 deletions(-) create mode 100644 app/Http/Livewire/Team/Delete.php create mode 100644 resources/views/livewire/team/delete.blade.php diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index 5c14a7b9a..e7a7e0b5d 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -11,6 +11,7 @@ use Illuminate\Foundation\Auth\Access\AuthorizesRequests; use Illuminate\Foundation\Validation\ValidatesRequests; use Illuminate\Routing\Controller as BaseController; +use Illuminate\Support\Facades\DB; class Controller extends BaseController { diff --git a/app/Http/Livewire/Team/Delete.php b/app/Http/Livewire/Team/Delete.php new file mode 100644 index 000000000..f25a8b8d8 --- /dev/null +++ b/app/Http/Livewire/Team/Delete.php @@ -0,0 +1,30 @@ +delete(); + + $team = auth()->user()->teams()->first(); + $currentTeam->members->each(function ($user) use ($currentTeam) { + if ($user->id === auth()->user()->id) { + return; + } + $user->teams()->detach($currentTeam); + $session = DB::table('sessions')->where('user_id', $user->id)->first(); + if ($session) { + DB::table('sessions')->where('id', $session->id)->delete(); + } + }); + + session(['currentTeam' => $team]); + return redirect()->route('team.show'); + } +} diff --git a/app/Models/Team.php b/app/Models/Team.php index b1c93c4ac..5029df7eb 100644 --- a/app/Models/Team.php +++ b/app/Models/Team.php @@ -79,4 +79,11 @@ public function sources() $sources = $sources->merge($github_apps)->merge($gitlab_apps); return $sources; } + public function isEmpty() + { + if ($this->projects()->count() === 0 && $this->servers()->count() === 0 && $this->privateKeys()->count() === 0 && $this->sources()->count() === 0) { + return true; + } + return false; + } } diff --git a/app/Models/User.php b/app/Models/User.php index b1804d7b4..fa3b83859 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -30,7 +30,6 @@ class User extends Authenticatable implements SendsEmail protected static function boot() { parent::boot(); - static::created(function (User $user) { $team = [ 'name' => $user->name . "'s Team", @@ -48,6 +47,7 @@ public function routeNotificationForEmail() { return $this->email; } + public function isAdmin() { if (auth()->user()->id === 0) { diff --git a/resources/js/components/MagicBar.vue b/resources/js/components/MagicBar.vue index d93e4cf0d..58b485e40 100644 --- a/resources/js/components/MagicBar.vue +++ b/resources/js/components/MagicBar.vue @@ -163,6 +163,16 @@ d="M3 8a9 9 0 0 1 9 9v1l1.428 -4.285a12 12 0 0 1 6.018 -6.938l.554 -.277" /> +
+ @@ -297,7 +307,8 @@ const magicActions = [{ { id: 8, name: 'Create: Team', - icon: '/', + icon: 'team', + new: true, sequence: ['main', 'redirect'] }, { diff --git a/resources/views/components/naked-modal.blade.php b/resources/views/components/naked-modal.blade.php index 2448be400..203f041e8 100644 --- a/resources/views/components/naked-modal.blade.php +++ b/resources/views/components/naked-modal.blade.php @@ -1,5 +1,6 @@ @props([ 'show' => null, + 'title' => 'Delete', 'message' => 'Are you sure you want to delete this?', 'action' => 'delete', ]) @@ -20,19 +21,20 @@ class="flex items-center justify-center flex-shrink-0 w-12 h-12 mx-auto rounded-
-
-

{{ $message }}

+

{!! $message !!}

-
- Delete - + Cancel +
+ Continue
diff --git a/resources/views/livewire/destination/form.blade.php b/resources/views/livewire/destination/form.blade.php index 6c137de13..f87e160df 100644 --- a/resources/views/livewire/destination/form.blade.php +++ b/resources/views/livewire/destination/form.blade.php @@ -1,5 +1,6 @@
- +

Destination

diff --git a/resources/views/livewire/private-key/change.blade.php b/resources/views/livewire/private-key/change.blade.php index b5801183c..fabb1f4db 100644 --- a/resources/views/livewire/private-key/change.blade.php +++ b/resources/views/livewire/private-key/change.blade.php @@ -1,5 +1,6 @@
- +

Private Key

diff --git a/resources/views/livewire/project/application/danger.blade.php b/resources/views/livewire/project/application/danger.blade.php index fd3295731..79b9caefd 100644 --- a/resources/views/livewire/project/application/danger.blade.php +++ b/resources/views/livewire/project/application/danger.blade.php @@ -1,10 +1,11 @@
+

Danger Zone

Woah. I hope you know what are you doing.

Delete Application

-
This will stop your containers, delete all related data, etc. Beware! There is no coming +
This will stop your containers, delete all related data, etc. Beware! There is no coming back!
- - Yes, please, delete it. + Delete
diff --git a/resources/views/livewire/project/application/environment-variable/show.blade.php b/resources/views/livewire/project/application/environment-variable/show.blade.php index 30a172a88..abbde06c3 100644 --- a/resources/views/livewire/project/application/environment-variable/show.blade.php +++ b/resources/views/livewire/project/application/environment-variable/show.blade.php @@ -1,4 +1,6 @@
+ @@ -12,5 +14,4 @@
-
diff --git a/resources/views/livewire/project/application/storages/show.blade.php b/resources/views/livewire/project/application/storages/show.blade.php index c7f9fe32c..ecaa72a3c 100644 --- a/resources/views/livewire/project/application/storages/show.blade.php +++ b/resources/views/livewire/project/application/storages/show.blade.php @@ -1,4 +1,6 @@
+
@@ -12,5 +14,4 @@
-
diff --git a/resources/views/livewire/project/delete-environment.blade.php b/resources/views/livewire/project/delete-environment.blade.php index 716a06bc7..ef9650af5 100644 --- a/resources/views/livewire/project/delete-environment.blade.php +++ b/resources/views/livewire/project/delete-environment.blade.php @@ -1,5 +1,6 @@
- + Delete Environment diff --git a/resources/views/livewire/project/delete-project.blade.php b/resources/views/livewire/project/delete-project.blade.php index 4168f2dc8..169586ed0 100644 --- a/resources/views/livewire/project/delete-project.blade.php +++ b/resources/views/livewire/project/delete-project.blade.php @@ -1,5 +1,6 @@
- + Delete Project diff --git a/resources/views/livewire/server/form.blade.php b/resources/views/livewire/server/form.blade.php index d2887896b..1ac087e2a 100644 --- a/resources/views/livewire/server/form.blade.php +++ b/resources/views/livewire/server/form.blade.php @@ -1,5 +1,6 @@
- +

General

diff --git a/resources/views/livewire/server/proxy.blade.php b/resources/views/livewire/server/proxy.blade.php index 74efc8310..2a8cce4fd 100644 --- a/resources/views/livewire/server/proxy.blade.php +++ b/resources/views/livewire/server/proxy.blade.php @@ -1,6 +1,6 @@
- + @if ($server->settings->is_reachable) @if ($server->extra_attributes->proxy_type)
diff --git a/resources/views/livewire/source/github/change.blade.php b/resources/views/livewire/source/github/change.blade.php index 8f3965935..97bc8a071 100644 --- a/resources/views/livewire/source/github/change.blade.php +++ b/resources/views/livewire/source/github/change.blade.php @@ -1,5 +1,6 @@
- +

GitHub App

diff --git a/resources/views/livewire/team/delete.blade.php b/resources/views/livewire/team/delete.blade.php new file mode 100644 index 000000000..6c8e82a6f --- /dev/null +++ b/resources/views/livewire/team/delete.blade.php @@ -0,0 +1,47 @@ +
+ +

Danger Zone

+
Woah. I hope you know what are you doing.
+

Delete Team

+ @if (session('currentTeam.id') === 0) +
This is the default team. You can't delete it.
+ @elseif(auth()->user()->teams()->get()->count() === 1) +
You can't delete your last team.
+ @else + @if (session('currentTeam')->isEmpty()) +
This will delete your team. Beware! There is no coming back!
+ + Delete + + @else +
+
You need to delete the following resources to be able to delete the team:
+

Projects:

+
    + @foreach (session('currentTeam')->projects as $resource) +
  • {{ $resource->name }}
  • + @endforeach +
+

Servers:

+
    + @foreach (session('currentTeam')->servers as $resource) +
  • {{ $resource->name }}
  • + @endforeach +
+

Private Keys:

+
    + @foreach (session('currentTeam')->privateKeys as $resource) +
  • {{ $resource->name }}
  • + @endforeach +
+

Sources:

+
    + @foreach (session('currentTeam')->sources() as $resource) +
  • {{ $resource->name }}
  • + @endforeach +
+ @endif + @endif + +
diff --git a/resources/views/team/show.blade.php b/resources/views/team/show.blade.php index 2657ec5b3..57639b2b8 100644 --- a/resources/views/team/show.blade.php +++ b/resources/views/team/show.blade.php @@ -41,4 +41,6 @@ class="underline text-warning">Transactional Emails
@endif + + diff --git a/routes/web.php b/routes/web.php index be1075fc5..80d080424 100644 --- a/routes/web.php +++ b/routes/web.php @@ -19,8 +19,6 @@ use Laravel\Fortify\Contracts\SuccessfulPasswordResetLinkRequestResponse; use Laravel\Fortify\Fortify; - - Route::post('/forgot-password', function (Request $request) { if (is_transactional_emails_active()) { set_transanctional_email_settings();