diff --git a/app/Actions/SshKey/CreateSshKey.php b/app/Actions/SshKey/CreateSshKey.php index d21d462f..06419b12 100644 --- a/app/Actions/SshKey/CreateSshKey.php +++ b/app/Actions/SshKey/CreateSshKey.php @@ -5,6 +5,7 @@ use App\Models\SshKey; use App\Models\User; use App\ValidationRules\SshKeyRule; +use Illuminate\Support\Facades\Validator; use Illuminate\Validation\ValidationException; class CreateSshKey @@ -16,6 +17,8 @@ class CreateSshKey */ public function create(User $user, array $input): SshKey { + Validator::make($input, self::rules())->validate(); + $key = new SshKey([ 'user_id' => $user->id, 'name' => $input['name'], diff --git a/app/Http/Controllers/API/ServerSSHKeyController.php b/app/Http/Controllers/API/ServerSSHKeyController.php index ceae773b..35123a8f 100644 --- a/app/Http/Controllers/API/ServerSSHKeyController.php +++ b/app/Http/Controllers/API/ServerSSHKeyController.php @@ -65,7 +65,6 @@ public function create(Request $request, Project $project, Server $server): SshK } if (! $sshKey) { - $this->validate($request, CreateSshKey::rules()); /** @var SshKey $sshKey */ $sshKey = app(CreateSshKey::class)->create($user, $request->all()); } diff --git a/app/Http/Controllers/SSHKeyController.php b/app/Http/Controllers/SSHKeyController.php new file mode 100644 index 00000000..9bf88d9d --- /dev/null +++ b/app/Http/Controllers/SSHKeyController.php @@ -0,0 +1,51 @@ +authorize('viewAny', SshKey::class); + + return Inertia::render('ssh-keys/index', [ + 'sshKeys' => SshKeyResource::collection(user()->sshKeys()->simplePaginate(config('web.pagination_size'))), + ]); + } + + #[Post('/', name: 'ssh-keys.store')] + public function store(Request $request): RedirectResponse + { + $this->authorize('create', SshKey::class); + + app(CreateSshKey::class)->create(user(), $request->input()); + + return back()->with('success', 'SSH key created.'); + } + + #[Delete('/{sshKey}', name: 'ssh-keys.destroy')] + public function destroy(SshKey $sshKey): RedirectResponse + { + $this->authorize('delete', $sshKey); + + $sshKey->delete(); + + return back()->with('success', 'SSH key deleted.'); + } +} diff --git a/resources/js/components/ui/textarea.tsx b/resources/js/components/ui/textarea.tsx new file mode 100644 index 00000000..5f558e74 --- /dev/null +++ b/resources/js/components/ui/textarea.tsx @@ -0,0 +1,18 @@ +import * as React from 'react'; + +import { cn } from '@/lib/utils'; + +function Textarea({ className, ...props }: React.ComponentProps<'textarea'>) { + return ( +