diff --git a/app/Fileshare/Actions/FileshareConnectionIndexAction.php b/app/Fileshare/Actions/FileshareIndexAction.php similarity index 93% rename from app/Fileshare/Actions/FileshareConnectionIndexAction.php rename to app/Fileshare/Actions/FileshareIndexAction.php index a790f66b..8a75e365 100644 --- a/app/Fileshare/Actions/FileshareConnectionIndexAction.php +++ b/app/Fileshare/Actions/FileshareIndexAction.php @@ -8,7 +8,7 @@ use Inertia\Inertia; use Inertia\Response; use Lorisleiva\Actions\Concerns\AsAction; -class FileshareConnectionIndexAction +class FileshareIndexAction { use AsAction; diff --git a/app/Fileshare/Actions/FileshareConnectionStoreAction.php b/app/Fileshare/Actions/FileshareStoreAction.php similarity index 96% rename from app/Fileshare/Actions/FileshareConnectionStoreAction.php rename to app/Fileshare/Actions/FileshareStoreAction.php index d3b9b28b..b868243a 100644 --- a/app/Fileshare/Actions/FileshareConnectionStoreAction.php +++ b/app/Fileshare/Actions/FileshareStoreAction.php @@ -7,7 +7,7 @@ use Illuminate\Validation\ValidationException; use Lorisleiva\Actions\ActionRequest; use Lorisleiva\Actions\Concerns\AsAction; -class FileshareConnectionStoreAction +class FileshareStoreAction { use AsAction; @@ -25,7 +25,6 @@ class FileshareConnectionStoreAction public function asController(ActionRequest $request): void { - $type = $request->input('type')::from($request->input('config')); if (!$type->check()) { diff --git a/app/Fileshare/Actions/FileshareUpdateAction.php b/app/Fileshare/Actions/FileshareUpdateAction.php new file mode 100644 index 00000000..b10d6602 --- /dev/null +++ b/app/Fileshare/Actions/FileshareUpdateAction.php @@ -0,0 +1,39 @@ + + */ + public function rules(): array + { + return [ + 'name' => 'required|string|max:255', + 'type' => 'required|string|max:255|exclude', + 'config' => 'array|exclude', + ]; + } + + public function handle(ActionRequest $request, FileshareConnection $fileshare): void + { + $type = $request->input('type')::from($request->input('config')); + + if (!$type->check()) { + throw ValidationException::withMessages(['type' => 'Verbindung fehlgeschlagen']); + } + + $fileshare->update([ + ...$request->validated(), + 'type' => $type, + ]); + } +} diff --git a/app/Fileshare/FileshareSettings.php b/app/Fileshare/FileshareSettings.php index 26f75e46..2c4c4812 100644 --- a/app/Fileshare/FileshareSettings.php +++ b/app/Fileshare/FileshareSettings.php @@ -2,7 +2,7 @@ namespace App\Fileshare; -use App\Fileshare\Actions\FileshareConnectionIndexAction; +use App\Fileshare\Actions\FileshareIndexAction; use App\Setting\Contracts\Indexable; use App\Setting\LocalSettings; @@ -20,7 +20,7 @@ class FileshareSettings extends LocalSettings implements Indexable public static function indexAction(): string { - return FileshareConnectionIndexAction::class; + return FileshareIndexAction::class; } public static function title(): string diff --git a/app/Fileshare/Resources/FileshareConnectionResource.php b/app/Fileshare/Resources/FileshareConnectionResource.php index 20f117dc..5bd3b509 100644 --- a/app/Fileshare/Resources/FileshareConnectionResource.php +++ b/app/Fileshare/Resources/FileshareConnectionResource.php @@ -30,6 +30,9 @@ class FileshareConnectionResource extends JsonResource 'config' => $this->type->toArray(), 'id' => $this->id, 'type_human' => $this->type::title(), + 'links' => [ + 'update' => route('fileshare.update', ['fileshare' => $this->getModel()]), + ] ]; } diff --git a/routes/web.php b/routes/web.php index baec75c4..d0f6dcf5 100644 --- a/routes/web.php +++ b/routes/web.php @@ -19,7 +19,8 @@ use App\Invoice\Actions\InvoiceStoreAction; use App\Course\Actions\CourseUpdateAction; use App\Dashboard\Actions\IndexAction as DashboardIndexAction; use App\Efz\ShowEfzDocumentAction; -use App\Fileshare\Actions\FileshareConnectionStoreAction; +use App\Fileshare\Actions\FileshareStoreAction; +use App\Fileshare\Actions\FileshareUpdateAction; use App\Form\Actions\ExportAction as ActionsExportAction; use App\Form\Actions\FormDestroyAction; use App\Form\Actions\FormIndexAction; @@ -169,5 +170,6 @@ Route::group(['middleware' => 'auth:web'], function (): void { Route::delete('/participant/{participant}', ParticipantDestroyAction::class)->name('participant.destroy'); // ------------------------------------ fileshare ----------------------------------- - Route::post('/fileshare', FileshareConnectionStoreAction::class)->name('fileshare.store'); + Route::post('/fileshare', FileshareStoreAction::class)->name('fileshare.store'); + Route::patch('/fileshare/{fileshare}', FileshareUpdateAction::class)->name('fileshare.update'); }); diff --git a/tests/Fileshare/FileshareConnectionIndexActionTest.php b/tests/Fileshare/FileshareIndexActionTest.php similarity index 90% rename from tests/Fileshare/FileshareConnectionIndexActionTest.php rename to tests/Fileshare/FileshareIndexActionTest.php index 70895c76..ad3312b7 100644 --- a/tests/Fileshare/FileshareConnectionIndexActionTest.php +++ b/tests/Fileshare/FileshareIndexActionTest.php @@ -6,7 +6,7 @@ use App\Fileshare\ConnectionTypes\OwncloudConnection; use App\Fileshare\Models\FileshareConnection; use Tests\FileshareTestCase; -class FileshareConnectionIndexActionTest extends FileshareTestCase +class FileshareIndexActionTest extends FileshareTestCase { public function testItListsOwncloudConnectionsThatAreActive(): void { @@ -25,6 +25,7 @@ class FileshareConnectionIndexActionTest extends FileshareTestCase ->assertInertiaPath('data.data.0.id', $connection->id) ->assertInertiaPath('data.data.0.is_active', true) ->assertInertiaPath('data.data.0.type_human', 'Owncloud') + ->assertInertiaPath('data.data.0.links.update', route('fileshare.update', ['fileshare' => $connection])) ->assertInertiaPath('data.meta.default.name', '') ->assertInertiaPath('data.meta.links.store', route('fileshare.store')) ->assertInertiaPath('data.meta.types.0.id', OwncloudConnection::class) diff --git a/tests/Fileshare/FileshareConnectionStoreActionTest.php b/tests/Fileshare/FileshareStoreActionTest.php similarity index 96% rename from tests/Fileshare/FileshareConnectionStoreActionTest.php rename to tests/Fileshare/FileshareStoreActionTest.php index 22b4f9db..447f2c15 100644 --- a/tests/Fileshare/FileshareConnectionStoreActionTest.php +++ b/tests/Fileshare/FileshareStoreActionTest.php @@ -6,7 +6,7 @@ use App\Fileshare\ConnectionTypes\OwncloudConnection; use App\Fileshare\Models\FileshareConnection; use Tests\FileshareTestCase; -class FileshareConnectionStoreActionTest extends FileshareTestCase +class FileshareStoreActionTest extends FileshareTestCase { public function testItStoresAConnection(): void { diff --git a/tests/Fileshare/FileshareUpdateActionTest.php b/tests/Fileshare/FileshareUpdateActionTest.php new file mode 100644 index 00000000..d725a1de --- /dev/null +++ b/tests/Fileshare/FileshareUpdateActionTest.php @@ -0,0 +1,56 @@ +withoutExceptionHandling()->login()->loginNami()->withOwncloudUser('badenpowell', 'secret'); + + $connection = FileshareConnection::factory() + ->type(OwncloudConnection::from(['user' => 'test', 'password' => 'test', 'base_url' => env('TEST_OWNCLOUD_DOMAIN')])) + ->name('lokaler Server') + ->create(); + + $this->patch(route('fileshare.update', ['fileshare' => $connection]), [ + 'name' => 'Lala', + 'type' => OwncloudConnection::class, + 'config' => [ + 'user' => 'badenpowell', + 'password' => 'secret', + 'base_url' => env('TEST_OWNCLOUD_DOMAIN'), + ] + ])->assertOk(); + + $connection = FileshareConnection::firstOrFail(); + $this->assertEquals('badenpowell', $connection->type->user); + $this->assertEquals('secret', $connection->type->password); + $this->assertEquals(env('TEST_OWNCLOUD_DOMAIN'), $connection->type->baseUrl); + $this->assertEquals('Lala', $connection->name); + } + + public function testItChecksConnection(): void + { + $this->login()->loginNami()->withOwncloudUser('test', 'test'); + + $connection = FileshareConnection::factory() + ->type(OwncloudConnection::from(['user' => 'test', 'password' => 'test', 'base_url' => env('TEST_OWNCLOUD_DOMAIN')])) + ->name('lokaler Server') + ->create(); + + $this->patchJson(route('fileshare.update', ['fileshare' => $connection]), [ + 'name' => 'Lala', + 'type' => OwncloudConnection::class, + 'config' => [ + 'user' => 'badenpowell', + 'password' => 'secret', + 'base_url' => env('TEST_OWNCLOUD_DOMAIN'), + ] + ])->assertJsonValidationErrors(['type' => 'Verbindung fehlgeschlagen']); + } +}