Add update for fileshares
This commit is contained in:
parent
e9e0be83cc
commit
e1c3240290
|
@ -8,7 +8,7 @@ use Inertia\Inertia;
|
|||
use Inertia\Response;
|
||||
use Lorisleiva\Actions\Concerns\AsAction;
|
||||
|
||||
class FileshareConnectionIndexAction
|
||||
class FileshareIndexAction
|
||||
{
|
||||
use AsAction;
|
||||
|
|
@ -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()) {
|
|
@ -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,
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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()]),
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -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');
|
||||
});
|
||||
|
|
|
@ -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)
|
|
@ -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
|
||||
{
|
|
@ -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']);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue