diff --git a/app/Form/Actions/FormStoreAction.php b/app/Form/Actions/FormStoreAction.php index f5171fd2..2d32e64b 100644 --- a/app/Form/Actions/FormStoreAction.php +++ b/app/Form/Actions/FormStoreAction.php @@ -33,6 +33,7 @@ class FormStoreAction 'header_image' => 'required|exclude', 'mailattachments' => 'present|array|exclude', 'is_active' => 'boolean', + 'is_private' => 'boolean', ]; } diff --git a/app/Form/Actions/FormUpdateAction.php b/app/Form/Actions/FormUpdateAction.php index c765afbf..d682048b 100644 --- a/app/Form/Actions/FormUpdateAction.php +++ b/app/Form/Actions/FormUpdateAction.php @@ -32,6 +32,7 @@ class FormUpdateAction 'mail_top' => 'array', 'mail_bottom' => 'array', 'is_active' => 'boolean', + 'is_private' => 'boolean', ]; } diff --git a/app/Form/Models/Form.php b/app/Form/Models/Form.php index e78b0a6c..b41d9a2d 100644 --- a/app/Form/Models/Form.php +++ b/app/Form/Models/Form.php @@ -32,6 +32,7 @@ class Form extends Model implements HasMedia 'mail_top' => 'json', 'mail_bottom' => 'json', 'is_active' => 'boolean', + 'is_private' => 'boolean', ]; /** @var array */ @@ -135,6 +136,7 @@ class Form extends Model implements HasMedia 'to' => $this->to->timestamp, 'name' => $this->name, 'is_active' => $this->is_active, + 'is_private' => $this->is_private, ]; } diff --git a/app/Form/Resources/FormResource.php b/app/Form/Resources/FormResource.php index db087b4e..5c402015 100644 --- a/app/Form/Resources/FormResource.php +++ b/app/Form/Resources/FormResource.php @@ -44,6 +44,7 @@ class FormResource extends JsonResource 'config' => $this->config, 'participants_count' => $this->participants_count, 'is_active' => $this->is_active, + 'is_private' => $this->is_private, 'links' => [ 'participant_index' => route('form.participant.index', ['form' => $this->getModel()]), 'update' => route('form.update', ['form' => $this->getModel()]), @@ -73,6 +74,7 @@ class FormResource extends JsonResource 'default' => [ 'description' => [], 'is_active' => true, + 'is_private' => false, 'name' => '', 'excerpt' => '', 'from' => null, diff --git a/config/scout.php b/config/scout.php index 19d413f2..451ec719 100644 --- a/config/scout.php +++ b/config/scout.php @@ -146,7 +146,7 @@ return [ ] ], Form::class => [ - 'filterableAttributes' => ['to', 'is_active'], + 'filterableAttributes' => ['to', 'is_active', 'is_private'], 'searchableAttributes' => ['name'], 'sortableAttributes' => ['from'], 'displayedAttributes' => ['from', 'name', 'id', 'to'], diff --git a/database/factories/Form/Models/FormFactory.php b/database/factories/Form/Models/FormFactory.php index 121cea72..668c910f 100644 --- a/database/factories/Form/Models/FormFactory.php +++ b/database/factories/Form/Models/FormFactory.php @@ -47,6 +47,8 @@ class FormFactory extends Factory 'registration_until' => $this->faker->dateTimeBetween('now', '+2 weeks')->format('Y-m-d H:i:s'), 'mail_top' => EditorRequestFactory::new()->create(), 'mail_bottom' => EditorRequestFactory::new()->create(), + 'is_active' => true, + 'is_private' => false, ]; } diff --git a/resources/js/views/form/Index.vue b/resources/js/views/form/Index.vue index 6b6dd968..af335fae 100644 --- a/resources/js/views/form/Index.vue +++ b/resources/js/views/form/Index.vue @@ -42,6 +42,7 @@
+
assertJsonCount(1, 'meta.agegroups'); } + public function testItDoesntDisplayInactiveForms(): void + { + $this->loginNami()->withoutExceptionHandling(); + + Form::factory()->isActive(false)->withImage('headerImage', 'lala-2.jpg')->count(1)->create(); + Form::factory()->isActive(true)->withImage('headerImage', 'lala-2.jpg')->count(2)->create(); + + sleep(1); + $this->get('/api/form?perPage=15&filter=' . $this->filterString(['inactive' => true]))->assertJsonCount(3, 'data'); + $this->get('/api/form?perPage=15&filter=' . $this->filterString(['inactive' => false]))->assertJsonCount(2, 'data'); + $this->get('/api/form?perPage=15&filter=' . $this->filterString([]))->assertJsonCount(2, 'data'); + } + public function testItDisplaysDailyForms(): void { Carbon::setTestNow(Carbon::parse('2023-03-02')); diff --git a/tests/EndToEnd/Form/FormIndexActionTest.php b/tests/EndToEnd/Form/FormIndexActionTest.php index fe8f5396..3d6d87c9 100644 --- a/tests/EndToEnd/Form/FormIndexActionTest.php +++ b/tests/EndToEnd/Form/FormIndexActionTest.php @@ -47,6 +47,7 @@ class FormIndexActionTest extends FormTestCase ->assertInertiaPath('data.data.0.participants_count', 5) ->assertInertiaPath('data.data.0.to', '2023-06-07') ->assertInertiaPath('data.data.0.is_active', true) + ->assertInertiaPath('data.data.0.is_private', false) ->assertInertiaPath('data.data.0.registration_from', '2023-05-06 04:00:00') ->assertInertiaPath('data.data.0.registration_until', '2023-04-01 05:00:00') ->assertInertiaPath('data.data.0.links.participant_index', route('form.participant.index', ['form' => $form])) @@ -58,6 +59,7 @@ class FormIndexActionTest extends FormTestCase ->assertInertiaPath('data.meta.default.description', []) ->assertInertiaPath('data.meta.default.excerpt', '') ->assertInertiaPath('data.meta.default.is_active', true) + ->assertInertiaPath('data.meta.default.is_private', false) ->assertInertiaPath('data.meta.default.mailattachments', []) ->assertInertiaPath('data.meta.default.config', null) ->assertInertiaPath('data.meta.base_url', url('')) diff --git a/tests/Feature/Form/FormUpdateActionTest.php b/tests/Feature/Form/FormUpdateActionTest.php index f99901d1..d6e1020f 100644 --- a/tests/Feature/Form/FormUpdateActionTest.php +++ b/tests/Feature/Form/FormUpdateActionTest.php @@ -59,6 +59,17 @@ class FormUpdateActionTest extends FormTestCase $this->assertTrue($form->fresh()->is_active); } + public function testItUpdatesPrivateState(): void + { + $this->login()->loginNami()->withoutExceptionHandling(); + $form = Form::factory()->create(); + + $this->patchJson(route('form.update', ['form' => $form]), FormRequest::new()->isPrivate(false)->create())->assertSessionDoesntHaveErrors()->assertOk(); + $this->assertFalse($form->fresh()->is_private); + $this->patchJson(route('form.update', ['form' => $form]), FormRequest::new()->isPrivate(true)->create())->assertSessionDoesntHaveErrors()->assertOk(); + $this->assertTrue($form->fresh()->is_private); + } + public function testItUpdatesActiveColumnsWhenFieldsAdded(): void { $this->login()->loginNami()->withoutExceptionHandling();