This commit is contained in:
Andras Bacsai 2023-06-16 15:56:25 +02:00
parent ab1ea30dec
commit 8f3ef2b1c5
19 changed files with 130 additions and 23 deletions

View File

@ -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
{

View File

@ -0,0 +1,30 @@
<?php
namespace App\Http\Livewire\Team;
use Illuminate\Support\Facades\DB;
use Livewire\Component;
class Delete extends Component
{
public function delete()
{
$currentTeam = session('currentTeam');
$currentTeam->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');
}
}

View File

@ -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;
}
}

View File

@ -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) {

View File

@ -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" />
<path d="M15 6h5v5" />
</template>
<template
v-if="action.icon === 'team' || sequenceState.sequence[sequenceState.currentActionIndex] === 'team'">
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path d="M10 13a2 2 0 1 0 4 0a2 2 0 0 0 -4 0" />
<path d="M8 21v-1a2 2 0 0 1 2 -2h4a2 2 0 0 1 2 2v1" />
<path d="M15 5a2 2 0 1 0 4 0a2 2 0 0 0 -4 0" />
<path d="M17 10h2a2 2 0 0 1 2 2v1" />
<path d="M5 5a2 2 0 1 0 4 0a2 2 0 0 0 -4 0" />
<path d="M3 13v-1a2 2 0 0 1 2 -2h2" />
</template>
</svg>
<div v-if="action.new"
class="absolute top-0 right-0 -mt-2 -mr-2 font-bold text-warning">+
@ -297,7 +307,8 @@ const magicActions = [{
{
id: 8,
name: 'Create: Team',
icon: '/',
icon: 'team',
new: true,
sequence: ['main', 'redirect']
},
{

View File

@ -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-
</svg>
</div>
<div class="mt-4 text-center sm:ml-4 sm:mt-1 sm:text-left">
<h3 class="text-base font-semibold leading-6 text-white" id="modal-title">Delete Resource
<h3 class="text-base font-semibold leading-6 text-white" id="modal-title">{{ $title }}
</h3>
<div class="mt-2">
<p class=" text-neutral-200">{{ $message }}</p>
<p class=" text-neutral-200">{!! $message !!}</p>
</div>
</div>
</div>
<div class="gap-4 mt-5 sm:mt-4 sm:flex sm:flex-row-reverse">
<x-forms.button class="w-24" wire:click='{{ $action }}'
x-on:click="{{ $show }} = false" isWarning type="button">Delete</x-forms.button>
<x-forms.button class="w-24 bg-coolgray-200 hover:bg-coolgray-300"
<div class="gap-4 pt-10 sm:mt-4 sm:flex">
<x-forms.button class="w-24 bg-coolgray-100 hover:bg-coolgray-100"
x-on:click="{{ $show }} = false" type="button">Cancel
</x-forms.button>
<div class="flex-1"></div>
<x-forms.button class="w-24" wire:click='{{ $action }}'
x-on:click="{{ $show }} = false" isWarning type="button">Continue</x-forms.button>
</div>
</div>
</div>

View File

@ -1,5 +1,6 @@
<div x-data="{ deleteDestination: false }">
<x-naked-modal show="deleteDestination" message='Are you sure you would like to delete this destination?' />
<x-naked-modal show="deleteDestination" title="Delete Destination"
message='This destination will be deleted. It is not reversible. <br>Please think again.' />
<form class="flex flex-col">
<div class="flex items-center gap-2">
<h1>Destination</h1>

View File

@ -1,5 +1,6 @@
<div x-data="{ deletePrivateKey: false, showPrivateKey: false }">
<x-naked-modal show="deletePrivateKey" message='Are you sure you would like to delete this private key?' />
<x-naked-modal show="deletePrivateKey" title="Delete Private Key"
message='This private key will be deleted. It is not reversible. <br>Please think again.' />
<form class="flex flex-col gap-2" wire:submit.prevent='changePrivateKey'>
<div class="flex items-end gap-2">
<h1>Private Key</h1>

View File

@ -1,10 +1,11 @@
<div x-data="{ deleteApplication: false }">
<x-naked-modal show="deleteApplication" title="Delete Application"
message='This application will be deleted. It is not reversible. <br>Please think again.' />
<h2>Danger Zone</h2>
<div class="">Woah. I hope you know what are you doing.</div>
<h3 class="pt-4">Delete Application</h3>
<div class="pb-4 ">This will stop your containers, delete all related data, etc. Beware! There is no coming
<div class="pb-4">This will stop your containers, delete all related data, etc. Beware! There is no coming
back!
</div>
<x-naked-modal show="deleteApplication" />
<x-forms.button x-on:click.prevent="deleteApplication = true">Yes, please, delete it.</x-forms.button>
<x-forms.button isWarning x-on:click.prevent="deleteApplication = true">Delete</x-forms.button>
</div>

View File

@ -1,4 +1,6 @@
<div x-data="{ deleteEnvironment: false }">
<x-naked-modal show="deleteEnvironment" title="Delete Environment"
message='This environment will be deleted. It is not reversible. <br>Please think again.' />
<form wire:submit.prevent='submit' class="flex flex-col gap-2 xl:items-end xl:flex-row">
<x-forms.input id="env.key" label="Name" />
<x-forms.input type="password" id="env.value" label="Value" />
@ -12,5 +14,4 @@
</x-forms.button>
</div>
</form>
<x-naked-modal show="deleteEnvironment" message="Are you sure you want to delete {{ $env->key }}?" />
</div>

View File

@ -1,4 +1,6 @@
<div x-data="{ deleteStorage: false }">
<x-naked-modal show="deleteStorage" title="Delete Storage"
message='This storage will be deleted. It is not reversible. <br>Please think again.' />
<form wire:submit.prevent='submit' class="flex flex-col gap-2 xl:items-end xl:flex-row">
<x-forms.input id="storage.name" label="Name" required />
<x-forms.input id="storage.host_path" label="Source Path" />
@ -12,5 +14,4 @@
</x-forms.button>
</div>
</form>
<x-naked-modal show="deleteStorage" message="Are you sure you want to delete {{ $storage->name }}?" />
</div>

View File

@ -1,5 +1,6 @@
<div x-data="{ deleteEnvironment: false }">
<x-naked-modal show="deleteEnvironment" message='Are you sure you would like to delete this environment?' />
<x-naked-modal show="deleteEnvironment" title="Delete Environment"
message='This environment will be deleted. It is not reversible. <br>Please think again.' />
<x-forms.button x-on:click.prevent="deleteEnvironment = true">
Delete Environment
</x-forms.button>

View File

@ -1,5 +1,6 @@
<div x-data="{ deleteProject: false }">
<x-naked-modal show="deleteProject" message='Are you sure you would like to delete this project?' />
<x-naked-modal show="deleteProject" title="Delete Project"
message='This project will be deleted. It is not reversible. <br>Please think again.' />
<x-forms.button x-on:click.prevent="deleteProject = true">
Delete Project
</x-forms.button>

View File

@ -1,5 +1,6 @@
<div x-data="{ deleteServer: false }">
<x-naked-modal show="deleteServer" message='Are you sure you would like to delete this server?' />
<x-naked-modal show="deleteServer" title="Delete Server"
message='This server will be deleted. It is not reversible. <br>Please think again.' />
<form wire:submit.prevent='submit' class="flex flex-col">
<div class="flex gap-2">
<h2>General</h2>

View File

@ -1,6 +1,6 @@
<div x-data="{ stopProxy: false }">
<x-naked-modal show="stopProxy" action="stopProxy"
message='Are you sure you would like to stop the proxy? All resources will be unavailable.' />
<x-naked-modal show="stopProxy" action="stopProxy" title="Stop Proxy"
message='This proxy will be stopped. It is not reversible. <br>All resources will be unavailable. <br>Please think again.' />
@if ($server->settings->is_reachable)
@if ($server->extra_attributes->proxy_type)
<div x-init="$wire.checkProxySettingsInSync">

View File

@ -1,5 +1,6 @@
<div x-data="{ deleteSource: false }">
<x-naked-modal show="deleteSource" message='Are you sure you would like to delete this source?' />
<x-naked-modal show="deleteSource" title="Delete Source"
message='This source will be deleted. It is not reversible. <br>Please think again.' />
<form wire:submit.prevent='submit'>
<div class="flex items-center gap-2">
<h1>GitHub App</h1>

View File

@ -0,0 +1,47 @@
<div x-data="{ deleteTeam: false }">
<x-naked-modal show="deleteTeam" title="Delete Team"
message='This team will be deleted. It is not reversible. <br>Please think again.' />
<h3>Danger Zone</h3>
<div class="pb-4">Woah. I hope you know what are you doing.</div>
<h4 class="pb-4">Delete Team</h4>
@if (session('currentTeam.id') === 0)
<div>This is the default team. You can't delete it.</div>
@elseif(auth()->user()->teams()->get()->count() === 1)
<div>You can't delete your last team.</div>
@else
@if (session('currentTeam')->isEmpty())
<div class="pb-4">This will delete your team. Beware! There is no coming back!</div>
<x-forms.button isWarning x-on:click.prevent="deleteTeam = true">
Delete
</x-forms.button>
@else
<div>
<div class="pb-4">You need to delete the following resources to be able to delete the team:</div>
<h4 class="pb-4">Projects:</h4>
<ul class="pl-8 list-disc">
@foreach (session('currentTeam')->projects as $resource)
<li>{{ $resource->name }}</li>
@endforeach
</ul>
<h4 class="py-4">Servers:</h4>
<ul class="pl-8 list-disc">
@foreach (session('currentTeam')->servers as $resource)
<li>{{ $resource->name }}</li>
@endforeach
</ul>
<h4 class="py-4">Private Keys:</h4>
<ul class="pl-8 list-disc">
@foreach (session('currentTeam')->privateKeys as $resource)
<li>{{ $resource->name }}</li>
@endforeach
</ul>
<h4 class="py-4">Sources:</h4>
<ul class="pl-8 list-disc">
@foreach (session('currentTeam')->sources() as $resource)
<li>{{ $resource->name }}</li>
@endforeach
</ul>
@endif
@endif
</div>

View File

@ -41,4 +41,6 @@ class="underline text-warning">Transactional Emails</a>
</div>
<livewire:team.invitations :invitations="$invitations" />
@endif
<livewire:team.delete />
</x-layout>

View File

@ -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();