From ff40b9e8058cb6b610bd9d79fc5144e1c5d949c7 Mon Sep 17 00:00:00 2001 From: philipp lang Date: Thu, 4 Jul 2024 21:01:14 +0200 Subject: [PATCH] Add prevention settings --- .../Actions/PreventionIndexAction.php | 19 +++++++++ app/Prevention/Actions/SettingApiAction.php | 19 +++++++++ app/Prevention/Actions/SettingStoreAction.php | 27 ++++++++++++ app/Prevention/PreventionSettings.php | 33 +++++++++++++++ app/Setting/SettingServiceProvider.php | 2 + ...7_04_202013_create_prevention_settings.php | 11 +++++ resources/js/components/form/Editor.vue | 20 ++++----- resources/js/views/setting/Prevention.vue | 37 ++++++++++++++++ routes/api.php | 4 ++ tests/Feature/Prevention/SettingTest.php | 42 +++++++++++++++++++ 10 files changed, 202 insertions(+), 12 deletions(-) create mode 100644 app/Prevention/Actions/PreventionIndexAction.php create mode 100644 app/Prevention/Actions/SettingApiAction.php create mode 100644 app/Prevention/Actions/SettingStoreAction.php create mode 100644 app/Prevention/PreventionSettings.php create mode 100644 database/settings/2024_07_04_202013_create_prevention_settings.php create mode 100644 resources/js/views/setting/Prevention.vue create mode 100644 tests/Feature/Prevention/SettingTest.php diff --git a/app/Prevention/Actions/PreventionIndexAction.php b/app/Prevention/Actions/PreventionIndexAction.php new file mode 100644 index 00000000..476ee170 --- /dev/null +++ b/app/Prevention/Actions/PreventionIndexAction.php @@ -0,0 +1,19 @@ +put('menu', 'setting'); + session()->put('title', 'Prävention'); + + return Inertia::render('setting/Prevention'); + } +} diff --git a/app/Prevention/Actions/SettingApiAction.php b/app/Prevention/Actions/SettingApiAction.php new file mode 100644 index 00000000..edcdd707 --- /dev/null +++ b/app/Prevention/Actions/SettingApiAction.php @@ -0,0 +1,19 @@ +json([ + 'data' => app(PreventionSettings::class)->toArray(), + ]); + } +} diff --git a/app/Prevention/Actions/SettingStoreAction.php b/app/Prevention/Actions/SettingStoreAction.php new file mode 100644 index 00000000..a8d12cb2 --- /dev/null +++ b/app/Prevention/Actions/SettingStoreAction.php @@ -0,0 +1,27 @@ + 'array', + ]; + } + + public function handle(ActionRequest $request): void + { + app(PreventionSettings::class)->fill($request->validated())->save(); + + Succeeded::message('Einstellungen gespeichert.')->dispatch(); + } +} diff --git a/app/Prevention/PreventionSettings.php b/app/Prevention/PreventionSettings.php new file mode 100644 index 00000000..0a24e7f5 --- /dev/null +++ b/app/Prevention/PreventionSettings.php @@ -0,0 +1,33 @@ +register(NamiSettings::class); app(SettingFactory::class)->register(FormSettings::class); app(SettingFactory::class)->register(FileshareSettings::class); + app(SettingFactory::class)->register(PreventionSettings::class); } } diff --git a/database/settings/2024_07_04_202013_create_prevention_settings.php b/database/settings/2024_07_04_202013_create_prevention_settings.php new file mode 100644 index 00000000..5884aaa3 --- /dev/null +++ b/database/settings/2024_07_04_202013_create_prevention_settings.php @@ -0,0 +1,11 @@ +migrator->add('prevention.formmail', ['time' => 1, 'blocks' => []]); + } +}; diff --git a/resources/js/components/form/Editor.vue b/resources/js/components/form/Editor.vue index 1a430eb3..7a356891 100644 --- a/resources/js/components/form/Editor.vue +++ b/resources/js/components/form/Editor.vue @@ -8,22 +8,18 @@ - + diff --git a/routes/api.php b/routes/api.php index 70730f99..9e751f3a 100644 --- a/routes/api.php +++ b/routes/api.php @@ -3,9 +3,13 @@ use App\Contribution\Actions\GenerateApiAction as ContributionGenerateApiAction; use App\Form\Actions\FormApiListAction; use App\Form\Actions\RegisterAction; +use App\Prevention\Actions\SettingStoreAction as PreventionStoreAction; use App\Group\Actions\GroupApiIndexAction; +use App\Prevention\Actions\SettingApiAction; Route::post('/contribution-generate', ContributionGenerateApiAction::class)->name('api.contribution.generate')->middleware('client:contribution-generate'); Route::post('/form/{form}/register', RegisterAction::class)->name('form.register'); Route::get('/group/{group?}', GroupApiIndexAction::class)->name('api.group'); Route::get('/form', FormApiListAction::class)->name('api.form.index'); +Route::get('/prevention', SettingApiAction::class)->name('api.prevention.index'); +Route::post('/prevention', PreventionStoreAction::class)->name('api.prevention.store'); diff --git a/tests/Feature/Prevention/SettingTest.php b/tests/Feature/Prevention/SettingTest.php new file mode 100644 index 00000000..46c983eb --- /dev/null +++ b/tests/Feature/Prevention/SettingTest.php @@ -0,0 +1,42 @@ +login()->loginNami(); + + $this->get('/setting/prevention')->assertComponent('prevention/Index')->assertOk(); + } + + public function testItReceivesSettings(): void + { + $this->login()->loginNami(); + + $text = EditorRequestFactory::new()->text(50, 'lorem ipsum')->create(); + app(PreventionSettings::class)->fill(['formmail' => $text])->save(); + + $this->get('/api/prevention') + ->assertJsonPath('data.formmail.blocks.0.data.text', 'lorem ipsum'); + } + + public function testItStoresSettings(): void + { + $this->login()->loginNami(); + + $text = EditorRequestFactory::new()->text(50, 'new lorem')->create(); + + $this->post('/api/prevention', ['formmail' => $text])->assertOk(); + $this->assertEquals($text, app(PreventionSettings::class)->formmail); + } +}