Add update for fileshares

This commit is contained in:
philipp lang 2024-06-27 12:48:20 +02:00
parent e9e0be83cc
commit e1c3240290
9 changed files with 109 additions and 9 deletions

View File

@ -8,7 +8,7 @@ use Inertia\Inertia;
use Inertia\Response; use Inertia\Response;
use Lorisleiva\Actions\Concerns\AsAction; use Lorisleiva\Actions\Concerns\AsAction;
class FileshareConnectionIndexAction class FileshareIndexAction
{ {
use AsAction; use AsAction;

View File

@ -7,7 +7,7 @@ use Illuminate\Validation\ValidationException;
use Lorisleiva\Actions\ActionRequest; use Lorisleiva\Actions\ActionRequest;
use Lorisleiva\Actions\Concerns\AsAction; use Lorisleiva\Actions\Concerns\AsAction;
class FileshareConnectionStoreAction class FileshareStoreAction
{ {
use AsAction; use AsAction;
@ -25,7 +25,6 @@ class FileshareConnectionStoreAction
public function asController(ActionRequest $request): void public function asController(ActionRequest $request): void
{ {
$type = $request->input('type')::from($request->input('config')); $type = $request->input('type')::from($request->input('config'));
if (!$type->check()) { if (!$type->check()) {

View File

@ -0,0 +1,39 @@
<?php
namespace App\Fileshare\Actions;
use App\Fileshare\Models\FileshareConnection;
use Illuminate\Validation\ValidationException;
use Lorisleiva\Actions\ActionRequest;
use Lorisleiva\Actions\Concerns\AsAction;
class FileshareUpdateAction
{
use AsAction;
/**
* @return array<string, mixed>
*/
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,
]);
}
}

View File

@ -2,7 +2,7 @@
namespace App\Fileshare; namespace App\Fileshare;
use App\Fileshare\Actions\FileshareConnectionIndexAction; use App\Fileshare\Actions\FileshareIndexAction;
use App\Setting\Contracts\Indexable; use App\Setting\Contracts\Indexable;
use App\Setting\LocalSettings; use App\Setting\LocalSettings;
@ -20,7 +20,7 @@ class FileshareSettings extends LocalSettings implements Indexable
public static function indexAction(): string public static function indexAction(): string
{ {
return FileshareConnectionIndexAction::class; return FileshareIndexAction::class;
} }
public static function title(): string public static function title(): string

View File

@ -30,6 +30,9 @@ class FileshareConnectionResource extends JsonResource
'config' => $this->type->toArray(), 'config' => $this->type->toArray(),
'id' => $this->id, 'id' => $this->id,
'type_human' => $this->type::title(), 'type_human' => $this->type::title(),
'links' => [
'update' => route('fileshare.update', ['fileshare' => $this->getModel()]),
]
]; ];
} }

View File

@ -19,7 +19,8 @@ use App\Invoice\Actions\InvoiceStoreAction;
use App\Course\Actions\CourseUpdateAction; use App\Course\Actions\CourseUpdateAction;
use App\Dashboard\Actions\IndexAction as DashboardIndexAction; use App\Dashboard\Actions\IndexAction as DashboardIndexAction;
use App\Efz\ShowEfzDocumentAction; 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\ExportAction as ActionsExportAction;
use App\Form\Actions\FormDestroyAction; use App\Form\Actions\FormDestroyAction;
use App\Form\Actions\FormIndexAction; 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'); Route::delete('/participant/{participant}', ParticipantDestroyAction::class)->name('participant.destroy');
// ------------------------------------ fileshare ----------------------------------- // ------------------------------------ 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');
}); });

View File

@ -6,7 +6,7 @@ use App\Fileshare\ConnectionTypes\OwncloudConnection;
use App\Fileshare\Models\FileshareConnection; use App\Fileshare\Models\FileshareConnection;
use Tests\FileshareTestCase; use Tests\FileshareTestCase;
class FileshareConnectionIndexActionTest extends FileshareTestCase class FileshareIndexActionTest extends FileshareTestCase
{ {
public function testItListsOwncloudConnectionsThatAreActive(): void public function testItListsOwncloudConnectionsThatAreActive(): void
{ {
@ -25,6 +25,7 @@ class FileshareConnectionIndexActionTest extends FileshareTestCase
->assertInertiaPath('data.data.0.id', $connection->id) ->assertInertiaPath('data.data.0.id', $connection->id)
->assertInertiaPath('data.data.0.is_active', true) ->assertInertiaPath('data.data.0.is_active', true)
->assertInertiaPath('data.data.0.type_human', 'Owncloud') ->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.default.name', '')
->assertInertiaPath('data.meta.links.store', route('fileshare.store')) ->assertInertiaPath('data.meta.links.store', route('fileshare.store'))
->assertInertiaPath('data.meta.types.0.id', OwncloudConnection::class) ->assertInertiaPath('data.meta.types.0.id', OwncloudConnection::class)

View File

@ -6,7 +6,7 @@ use App\Fileshare\ConnectionTypes\OwncloudConnection;
use App\Fileshare\Models\FileshareConnection; use App\Fileshare\Models\FileshareConnection;
use Tests\FileshareTestCase; use Tests\FileshareTestCase;
class FileshareConnectionStoreActionTest extends FileshareTestCase class FileshareStoreActionTest extends FileshareTestCase
{ {
public function testItStoresAConnection(): void public function testItStoresAConnection(): void
{ {

View File

@ -0,0 +1,56 @@
<?php
namespace Tests\Fileshare;
use App\Fileshare\ConnectionTypes\OwncloudConnection;
use App\Fileshare\Models\FileshareConnection;
use Tests\FileshareTestCase;
class FileshareUpdateActionTest extends FileshareTestCase
{
public function testItStoresAConnection(): void
{
$this->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']);
}
}