From 8924774ed0ddf668224405eb0cda9379e38e5994 Mon Sep 17 00:00:00 2001 From: philipp lang Date: Tue, 11 Nov 2025 00:53:26 +0100 Subject: [PATCH] Add Soft deletes to participants Fix tests --- app/Form/Actions/ParticipantDestroyAction.php | 2 +- app/Form/Scopes/ParticipantFilterScope.php | 2 ++ ...reate_participants_cancelled_at_column.php | 28 +++++++++++++++++++ packages/table-document | 2 +- .../Form/ParticipantIndexActionTest.php | 9 ++++++ .../Form/ParticipantDestroyActionTest.php | 6 +++- 6 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 database/migrations/2025_11_11_221048_create_participants_cancelled_at_column.php diff --git a/app/Form/Actions/ParticipantDestroyAction.php b/app/Form/Actions/ParticipantDestroyAction.php index bc6777a6..8100c34c 100644 --- a/app/Form/Actions/ParticipantDestroyAction.php +++ b/app/Form/Actions/ParticipantDestroyAction.php @@ -15,7 +15,7 @@ class ParticipantDestroyAction public function handle(int $participantId): void { - Participant::findOrFail($participantId)->delete(); + Participant::findOrFail($participantId)->update(['cancelled_at' => now()]); } public function asController(Participant $participant): void diff --git a/app/Form/Scopes/ParticipantFilterScope.php b/app/Form/Scopes/ParticipantFilterScope.php index 1f8fc69e..d29c0a11 100644 --- a/app/Form/Scopes/ParticipantFilterScope.php +++ b/app/Form/Scopes/ParticipantFilterScope.php @@ -54,6 +54,8 @@ class ParticipantFilterScope extends ScoutFilter $filter->push('parent-id IS NULL'); } + $filter->push('cancelled_at IS NULL'); + if ($this->parent !== null && $this->parent !== -1) { $filter->push('parent-id = ' . $this->parent); } diff --git a/database/migrations/2025_11_11_221048_create_participants_cancelled_at_column.php b/database/migrations/2025_11_11_221048_create_participants_cancelled_at_column.php new file mode 100644 index 00000000..a32c6ae4 --- /dev/null +++ b/database/migrations/2025_11_11_221048_create_participants_cancelled_at_column.php @@ -0,0 +1,28 @@ +datetime('cancelled_at')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('participants', function (Blueprint $table) { + $table->dropColumn('cancelled_at'); + }); + } +}; diff --git a/packages/table-document b/packages/table-document index 73049633..f7b04591 160000 --- a/packages/table-document +++ b/packages/table-document @@ -1 +1 @@ -Subproject commit 7304963370ff64fb5accf08da4864981cc424301 +Subproject commit f7b04591830ebdeaddf76236e4cbc87a8b3eec8f diff --git a/tests/EndToEnd/Form/ParticipantIndexActionTest.php b/tests/EndToEnd/Form/ParticipantIndexActionTest.php index 9f279b9b..cc1382b0 100644 --- a/tests/EndToEnd/Form/ParticipantIndexActionTest.php +++ b/tests/EndToEnd/Form/ParticipantIndexActionTest.php @@ -269,6 +269,15 @@ it('testItShowsPreventionState', function () { ->assertJsonPath('data.0.prevention_items.0.tooltip', 'erweitertes Führungszeugnis nicht vorhanden'); }); +it('doesnt show cancelled participants', function () { + $this->login()->loginNami()->withoutExceptionHandling(); + $participant = Participant::factory()->for(Form::factory())->create(['cancelled_at' => now()]); + + sleep(2); + $this->callFilter('form.participant.index', [], ['form' => $participant->form]) + ->assertJsonCount(0, 'data'); +}); + it('test it orders participants by value', function (array $values, array $sorting, array $expected) { list($key, $direction) = $sorting; $this->login()->loginNami()->withoutExceptionHandling(); diff --git a/tests/Feature/Form/ParticipantDestroyActionTest.php b/tests/Feature/Form/ParticipantDestroyActionTest.php index e27954e0..df445dfb 100644 --- a/tests/Feature/Form/ParticipantDestroyActionTest.php +++ b/tests/Feature/Form/ParticipantDestroyActionTest.php @@ -24,5 +24,9 @@ it('testItCanDestroyAParticipant', function () { $this->deleteJson(route('participant.destroy', ['participant' => $form->participants->first()])) ->assertOk(); - $this->assertDatabaseCount('participants', 0); + $this->assertDatabaseCount('participants', 1); + $this->assertDatabaseHas('participants', [ + 'cancelled_at' => now(), + 'id' => $form->participants->first()->id, + ]); });