diff --git a/app/Form/Actions/FormStoreAction.php b/app/Form/Actions/FormStoreAction.php index 14bd1241..f929d8b0 100644 --- a/app/Form/Actions/FormStoreAction.php +++ b/app/Form/Actions/FormStoreAction.php @@ -34,6 +34,7 @@ class FormStoreAction 'mailattachments' => 'present|array|exclude', 'is_active' => 'boolean', 'is_private' => 'boolean', + 'export' => 'nullable|array', ]; } diff --git a/app/Form/Actions/FormUpdateAction.php b/app/Form/Actions/FormUpdateAction.php index 1069e449..3dd3892f 100644 --- a/app/Form/Actions/FormUpdateAction.php +++ b/app/Form/Actions/FormUpdateAction.php @@ -33,6 +33,7 @@ class FormUpdateAction 'mail_bottom' => 'array', 'is_active' => 'boolean', 'is_private' => 'boolean', + 'export' => 'nullable|array', ]; } diff --git a/app/Form/Data/ExportData.php b/app/Form/Data/ExportData.php new file mode 100644 index 00000000..0d2e1567 --- /dev/null +++ b/app/Form/Data/ExportData.php @@ -0,0 +1,19 @@ + 'json', 'is_active' => 'boolean', 'is_private' => 'boolean', + 'export' => ExportData::class, ]; /** @var array */ diff --git a/app/Form/Resources/FormResource.php b/app/Form/Resources/FormResource.php index 80c4e0b0..b937dcd7 100644 --- a/app/Form/Resources/FormResource.php +++ b/app/Form/Resources/FormResource.php @@ -2,6 +2,7 @@ namespace App\Form\Resources; +use App\Form\Data\ExportData; use App\Form\Enums\NamiType; use App\Form\Enums\SpecialType; use App\Form\Fields\Field; @@ -47,6 +48,7 @@ class FormResource extends JsonResource 'is_active' => $this->is_active, 'is_private' => $this->is_private, 'has_nami_field' => $this->getFields()->hasNamiField(), + 'export' => $this->export, 'links' => [ 'participant_index' => route('form.participant.index', ['form' => $this->getModel(), 'parent' => null]), 'participant_root_index' => route('form.participant.index', ['form' => $this->getModel(), 'parent' => -1]), @@ -92,6 +94,7 @@ class FormResource extends JsonResource 'header_image' => null, 'mailattachments' => [], 'id' => null, + 'export' => ExportData::from([]), ], 'section_default' => [ 'name' => '', diff --git a/database/factories/Form/Models/FormFactory.php b/database/factories/Form/Models/FormFactory.php index 6d010f0a..55e2cb25 100644 --- a/database/factories/Form/Models/FormFactory.php +++ b/database/factories/Form/Models/FormFactory.php @@ -2,6 +2,7 @@ namespace Database\Factories\Form\Models; +use App\Form\Data\ExportData; use App\Form\Models\Form; use Database\Factories\Traits\FakesMedia; use Illuminate\Database\Eloquent\Factories\Factory; @@ -19,6 +20,7 @@ use Tests\RequestFactories\EditorRequestFactory; * @method self registrationUntil(string|null $date) * @method self isActive(bool $isActive) * @method self isPrivate(bool $isPrivate) + * @method self export(ExportData $data) */ class FormFactory extends Factory { diff --git a/database/migrations/2024_06_29_175146_create_forms_export_column.php b/database/migrations/2024_06_29_175146_create_forms_export_column.php new file mode 100644 index 00000000..4f326e78 --- /dev/null +++ b/database/migrations/2024_06_29_175146_create_forms_export_column.php @@ -0,0 +1,32 @@ +json('export')->after('config')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('forms', function (Blueprint $table) { + $table->dropColumn('export'); + }); + } +}; diff --git a/tests/EndToEnd/Form/FormIndexActionTest.php b/tests/EndToEnd/Form/FormIndexActionTest.php index b43cf01d..8a384acb 100644 --- a/tests/EndToEnd/Form/FormIndexActionTest.php +++ b/tests/EndToEnd/Form/FormIndexActionTest.php @@ -2,6 +2,8 @@ namespace Tests\EndToEnd\Form; +use App\Fileshare\Data\FileshareResourceData; +use App\Form\Data\ExportData; use App\Form\FormSettings; use App\Form\Models\Form; use App\Form\Models\Formtemplate; @@ -63,6 +65,7 @@ class FormIndexActionTest extends FormTestCase ->assertInertiaPath('data.meta.default.is_active', true) ->assertInertiaPath('data.meta.default.is_private', false) ->assertInertiaPath('data.meta.default.mailattachments', []) + ->assertInertiaPath('data.meta.default.export', ['root' => null, 'group_by' => null, 'to_group_field' => null]) ->assertInertiaPath('data.meta.default.config', null) ->assertInertiaPath('data.meta.base_url', url('')) ->assertInertiaPath('data.meta.namiTypes.0', ['id' => 'Vorname', 'name' => 'Vorname']) @@ -70,6 +73,22 @@ class FormIndexActionTest extends FormTestCase ->assertInertiaPath('data.meta.section_default.name', ''); } + public function testItDisplaysExport(): void + { + $this->login()->loginNami()->withoutExceptionHandling(); + Form::factory() + ->name('lala') + ->export(ExportData::from(['root' => FileshareResourceData::from(['connection_id' => 2, 'resource' => '/dir']), 'group_by' => 'lala', 'to_group_field' => 'abc'])) + ->create(); + + sleep(1); + $this->get(route('form.index')) + ->assertInertiaPath('data.data.0.export.group_by', 'lala') + ->assertInertiaPath('data.data.0.export.root.connection_id', 2) + ->assertInertiaPath('data.data.0.export.root.resource', '/dir') + ->assertInertiaPath('data.data.0.export.to_group_field', 'abc'); + } + public function testItHandlesFullTextSearch(): void { $this->withoutExceptionHandling()->login()->loginNami(); diff --git a/tests/Feature/Form/FormStoreActionTest.php b/tests/Feature/Form/FormStoreActionTest.php index 5e11ac6c..6e0ac957 100644 --- a/tests/Feature/Form/FormStoreActionTest.php +++ b/tests/Feature/Form/FormStoreActionTest.php @@ -2,6 +2,8 @@ namespace Tests\Feature\Form; +use App\Fileshare\Data\FileshareResourceData; +use App\Form\Data\ExportData; use App\Form\Enums\NamiType; use App\Form\Models\Form; use App\Lib\Events\Succeeded; @@ -66,6 +68,16 @@ class FormStoreActionTest extends FormTestCase ]); } + public function testItStoresExport(): void + { + $this->login()->loginNami()->withoutExceptionHandling(); + + $this->postJson(route('form.store'), FormRequest::new()->export(ExportData::from(['root' => FileshareResourceData::from(['connection_id' => 2, 'resource' => '/dir']), 'group_by' => 'lala', 'to_group_field' => 'abc']))->create())->assertOk(); + + $form = Form::first(); + $this->assertEquals(2, $form->export->root->connectionId); + } + public function validationDataProvider(): Generator { yield [FormRequest::new()->name(''), ['name' => 'Name ist erforderlich.']]; diff --git a/tests/Feature/Form/FormUpdateActionTest.php b/tests/Feature/Form/FormUpdateActionTest.php index 0c12f3ce..ee2ba1d6 100644 --- a/tests/Feature/Form/FormUpdateActionTest.php +++ b/tests/Feature/Form/FormUpdateActionTest.php @@ -2,6 +2,8 @@ namespace Tests\Feature\Form; +use App\Fileshare\Data\FileshareResourceData; +use App\Form\Data\ExportData; use App\Form\Models\Form; use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Support\Facades\Http; @@ -39,6 +41,16 @@ class FormUpdateActionTest extends FormTestCase $this->assertFrontendCacheCleared(); } + public function testItUpdatesExport(): void + { + $this->login()->loginNami()->withoutExceptionHandling(); + + $form = Form::factory()->create(); + $this->patchJson(route('form.update', ['form' => $form]), FormRequest::new()->export(ExportData::from(['root' => FileshareResourceData::from(['connection_id' => 2, 'resource' => '/dir']), 'group_by' => 'lala', 'to_group_field' => 'abc']))->create()); + + $this->assertEquals(2, $form->fresh()->export->root->connectionId); + } + public function testItUpdatesActiveColumnsWhenFieldRemoved(): void { $this->login()->loginNami()->withoutExceptionHandling();