Add private state for forms
This commit is contained in:
parent
c4aa9b1051
commit
0c49166392
|
@ -33,6 +33,7 @@ class FormStoreAction
|
|||
'header_image' => 'required|exclude',
|
||||
'mailattachments' => 'present|array|exclude',
|
||||
'is_active' => 'boolean',
|
||||
'is_private' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ class FormUpdateAction
|
|||
'mail_top' => 'array',
|
||||
'mail_bottom' => 'array',
|
||||
'is_active' => 'boolean',
|
||||
'is_private' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ class Form extends Model implements HasMedia
|
|||
'mail_top' => 'json',
|
||||
'mail_bottom' => 'json',
|
||||
'is_active' => 'boolean',
|
||||
'is_private' => 'boolean',
|
||||
];
|
||||
|
||||
/** @var array<int, string> */
|
||||
|
@ -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,
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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'],
|
||||
|
|
|
@ -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,
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
<div class="flex space-x-3">
|
||||
<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_private" v-model="single.is_private" name="is_private" label="Privat"></f-switch>
|
||||
</div>
|
||||
<f-singlefile
|
||||
id="header_image"
|
||||
|
|
|
@ -74,6 +74,19 @@ class FormApiListActionTest extends FormTestCase
|
|||
->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'));
|
||||
|
|
|
@ -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(''))
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue