Add fileshare storage

This commit is contained in:
philipp lang 2024-06-27 00:19:12 +02:00
parent f16b58dbc6
commit 258093f2c4
6 changed files with 108 additions and 0 deletions

1
.gitignore vendored
View File

@ -16,6 +16,7 @@ Homestead.json
.phpunit.result.cache
/storage/temp/
/storage/debugbar/
/tests/Fileshare/oc_tmp/*
# User data files
/data/

View File

@ -0,0 +1,37 @@
<?php
namespace App\Fileshare\Actions;
use App\Fileshare\Models\FileshareConnection;
use Illuminate\Validation\ValidationException;
use Lorisleiva\Actions\ActionRequest;
use Lorisleiva\Actions\Concerns\AsAction;
class FileshareStoreAction
{
use AsAction;
public function rules(): array
{
return [
'name' => 'required|string|max:255',
'type' => 'required|string|max:255|exclude',
'config' => 'array|exclude',
];
}
public function asController(ActionRequest $request)
{
$type = $request->input('type')::from($request->input('config'));
if (!$type->check()) {
throw ValidationException::withMessages(['type' => 'Verbindung fehlgeschlagen']);
}
FileshareConnection::create([
...$request->validated(),
'type' => $type,
]);
}
}

View File

@ -10,6 +10,8 @@ class FileshareConnection extends Model
{
use HasFactory;
public $guarded = [];
public $casts = [
'type' => ConnectionType::class,
];

View File

@ -10,6 +10,9 @@
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
<testsuite name="Fileshare">
<directory suffix="Test.php">./tests/Fileshare</directory>
</testsuite>
<testsuite name="NamiUnit">
<directory suffix="Test.php">./packages/laravel-nami/tests/Unit</directory>
</testsuite>

View File

@ -19,6 +19,7 @@ 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\FileshareStoreAction;
use App\Form\Actions\ExportAction as ActionsExportAction;
use App\Form\Actions\FormDestroyAction;
use App\Form\Actions\FormIndexAction;
@ -166,4 +167,7 @@ Route::group(['middleware' => 'auth:web'], function (): void {
Route::get('/form/{form}/participants/{parent?}', ParticipantIndexAction::class)->name('form.participant.index');
Route::post('/form/{form}/is-dirty', IsDirtyAction::class)->name('form.is-dirty');
Route::delete('/participant/{participant}', ParticipantDestroyAction::class)->name('participant.destroy');
// ------------------------------------ fileshare -----------------------------------
Route::post('/fileshare', FileshareStoreAction::class)->name('fileshare.store');
});

View File

@ -0,0 +1,61 @@
<?php
namespace Tests\Fileshare;
use App\Fileshare\ConnectionTypes\OwncloudConnection;
use App\Fileshare\Models\FileshareConnection;
use Tests\FileshareTestCase;
class ConnectionStoreActionTest extends FileshareTestCase
{
public function testItStoresAConnection(): void
{
$this->withoutExceptionHandling()->login()->loginNami()->withOwncloudUser('badenpowell', 'secret');
$this->post(route('fileshare.store'), [
'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->withExceptionHandling()->login()->loginNami();
$this->postJson(route('fileshare.store'), [
'name' => 'Lala',
'type' => OwncloudConnection::class,
'config' => [
'user' => 'badenpowell',
'password' => 'secret',
'base_url' => env('TEST_OWNCLOUD_DOMAIN'),
]
])->assertJsonValidationErrors(['type' => 'Verbindung fehlgeschlagen']);
}
public function testItNeedsName(): void
{
$this->withExceptionHandling()->login()->loginNami();
$this->postJson(route('fileshare.store'), [
'name' => '',
'type' => OwncloudConnection::class,
'config' => [
'user' => 'badenpowell',
'password' => 'secret',
'base_url' => env('TEST_OWNCLOUD_DOMAIN'),
]
])->assertJsonValidationErrors(['name' => 'Name ist erforderlich.']);
}
}