Add private state for forms

This commit is contained in:
philipp lang 2024-05-27 18:49:11 +02:00
parent c4aa9b1051
commit 0c49166392
10 changed files with 36 additions and 1 deletions

View File

@ -33,6 +33,7 @@ class FormStoreAction
'header_image' => 'required|exclude', 'header_image' => 'required|exclude',
'mailattachments' => 'present|array|exclude', 'mailattachments' => 'present|array|exclude',
'is_active' => 'boolean', 'is_active' => 'boolean',
'is_private' => 'boolean',
]; ];
} }

View File

@ -32,6 +32,7 @@ class FormUpdateAction
'mail_top' => 'array', 'mail_top' => 'array',
'mail_bottom' => 'array', 'mail_bottom' => 'array',
'is_active' => 'boolean', 'is_active' => 'boolean',
'is_private' => 'boolean',
]; ];
} }

View File

@ -32,6 +32,7 @@ class Form extends Model implements HasMedia
'mail_top' => 'json', 'mail_top' => 'json',
'mail_bottom' => 'json', 'mail_bottom' => 'json',
'is_active' => 'boolean', 'is_active' => 'boolean',
'is_private' => 'boolean',
]; ];
/** @var array<int, string> */ /** @var array<int, string> */
@ -135,6 +136,7 @@ class Form extends Model implements HasMedia
'to' => $this->to->timestamp, 'to' => $this->to->timestamp,
'name' => $this->name, 'name' => $this->name,
'is_active' => $this->is_active, 'is_active' => $this->is_active,
'is_private' => $this->is_private,
]; ];
} }

View File

@ -44,6 +44,7 @@ class FormResource extends JsonResource
'config' => $this->config, 'config' => $this->config,
'participants_count' => $this->participants_count, 'participants_count' => $this->participants_count,
'is_active' => $this->is_active, 'is_active' => $this->is_active,
'is_private' => $this->is_private,
'links' => [ 'links' => [
'participant_index' => route('form.participant.index', ['form' => $this->getModel()]), 'participant_index' => route('form.participant.index', ['form' => $this->getModel()]),
'update' => route('form.update', ['form' => $this->getModel()]), 'update' => route('form.update', ['form' => $this->getModel()]),
@ -73,6 +74,7 @@ class FormResource extends JsonResource
'default' => [ 'default' => [
'description' => [], 'description' => [],
'is_active' => true, 'is_active' => true,
'is_private' => false,
'name' => '', 'name' => '',
'excerpt' => '', 'excerpt' => '',
'from' => null, 'from' => null,

View File

@ -146,7 +146,7 @@ return [
] ]
], ],
Form::class => [ Form::class => [
'filterableAttributes' => ['to', 'is_active'], 'filterableAttributes' => ['to', 'is_active', 'is_private'],
'searchableAttributes' => ['name'], 'searchableAttributes' => ['name'],
'sortableAttributes' => ['from'], 'sortableAttributes' => ['from'],
'displayedAttributes' => ['from', 'name', 'id', 'to'], 'displayedAttributes' => ['from', 'name', 'id', 'to'],

View File

@ -47,6 +47,8 @@ class FormFactory extends Factory
'registration_until' => $this->faker->dateTimeBetween('now', '+2 weeks')->format('Y-m-d H:i:s'), 'registration_until' => $this->faker->dateTimeBetween('now', '+2 weeks')->format('Y-m-d H:i:s'),
'mail_top' => EditorRequestFactory::new()->create(), 'mail_top' => EditorRequestFactory::new()->create(),
'mail_bottom' => EditorRequestFactory::new()->create(), 'mail_bottom' => EditorRequestFactory::new()->create(),
'is_active' => true,
'is_private' => false,
]; ];
} }

View File

@ -42,6 +42,7 @@
<div class="flex space-x-3"> <div class="flex space-x-3">
<f-text id="name" v-model="single.name" class="grow" name="name" label="Name" required></f-text> <f-text id="name" v-model="single.name" class="grow" name="name" label="Name" required></f-text>
<f-switch id="is_active" v-model="single.is_active" name="is_active" label="Aktiv"></f-switch> <f-switch id="is_active" v-model="single.is_active" name="is_active" label="Aktiv"></f-switch>
<f-switch id="is_private" v-model="single.is_private" name="is_private" label="Privat"></f-switch>
</div> </div>
<f-singlefile <f-singlefile
id="header_image" id="header_image"

View File

@ -74,6 +74,19 @@ class FormApiListActionTest extends FormTestCase
->assertJsonCount(1, 'meta.agegroups'); ->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 public function testItDisplaysDailyForms(): void
{ {
Carbon::setTestNow(Carbon::parse('2023-03-02')); Carbon::setTestNow(Carbon::parse('2023-03-02'));

View File

@ -47,6 +47,7 @@ class FormIndexActionTest extends FormTestCase
->assertInertiaPath('data.data.0.participants_count', 5) ->assertInertiaPath('data.data.0.participants_count', 5)
->assertInertiaPath('data.data.0.to', '2023-06-07') ->assertInertiaPath('data.data.0.to', '2023-06-07')
->assertInertiaPath('data.data.0.is_active', true) ->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_from', '2023-05-06 04:00:00')
->assertInertiaPath('data.data.0.registration_until', '2023-04-01 05: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])) ->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.description', [])
->assertInertiaPath('data.meta.default.excerpt', '') ->assertInertiaPath('data.meta.default.excerpt', '')
->assertInertiaPath('data.meta.default.is_active', true) ->assertInertiaPath('data.meta.default.is_active', true)
->assertInertiaPath('data.meta.default.is_private', false)
->assertInertiaPath('data.meta.default.mailattachments', []) ->assertInertiaPath('data.meta.default.mailattachments', [])
->assertInertiaPath('data.meta.default.config', null) ->assertInertiaPath('data.meta.default.config', null)
->assertInertiaPath('data.meta.base_url', url('')) ->assertInertiaPath('data.meta.base_url', url(''))

View File

@ -59,6 +59,17 @@ class FormUpdateActionTest extends FormTestCase
$this->assertTrue($form->fresh()->is_active); $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 public function testItUpdatesActiveColumnsWhenFieldsAdded(): void
{ {
$this->login()->loginNami()->withoutExceptionHandling(); $this->login()->loginNami()->withoutExceptionHandling();