diff --git a/app/Form/Actions/ParticipantDestroyAction.php b/app/Form/Actions/ParticipantDestroyAction.php index 8100c34c..a83931ff 100644 --- a/app/Form/Actions/ParticipantDestroyAction.php +++ b/app/Form/Actions/ParticipantDestroyAction.php @@ -6,6 +6,7 @@ use App\Form\Models\Participant; use App\Lib\JobMiddleware\JobChannels; use App\Lib\JobMiddleware\WithJobState; use App\Lib\Queue\TracksJob; +use Lorisleiva\Actions\ActionRequest; use Lorisleiva\Actions\Concerns\AsAction; class ParticipantDestroyAction @@ -13,14 +14,20 @@ class ParticipantDestroyAction use AsAction; use TracksJob; - public function handle(int $participantId): void + public function handle(int $participantId, bool $force): void { - Participant::findOrFail($participantId)->update(['cancelled_at' => now()]); + $participant = Participant::findOrFail($participantId); + + if ($force) { + $participant->delete(); + } else { + $participant->update(['cancelled_at' => now()]); + } } - public function asController(Participant $participant): void + public function asController(ActionRequest $request, Participant $participant): void { - $this->startJob($participant->id); + $this->startJob($participant->id, $request->header('X-Force') === '1'); } /** diff --git a/resources/js/composables/useApiIndex.js b/resources/js/composables/useApiIndex.js index e5e5007e..7af11661 100644 --- a/resources/js/composables/useApiIndex.js +++ b/resources/js/composables/useApiIndex.js @@ -47,8 +47,10 @@ export function useApiIndex(firstUrl, siteName = null) { single.value = null; } - async function remove(model) { - await axios.delete(model.links.destroy); + async function remove(model, force = true) { + await axios.delete(model.links.destroy, { + headers: { 'X-Force': force ? '1' : '0' } + }); await reload(); } diff --git a/resources/js/views/form/Participants.vue b/resources/js/views/form/Participants.vue index b02220c0..2a4800aa 100644 --- a/resources/js/views/form/Participants.vue +++ b/resources/js/views/form/Participants.vue @@ -11,9 +11,10 @@ - +
-

Den*Die Teilnehmer*in löschen?

+

Den*Die Teilnehmer*in abmelden?

+
Mitglied loschen Abbrechen @@ -96,7 +97,7 @@ - + @@ -210,7 +211,7 @@ const sortingConfig = computed({ }); async function handleDelete() { - await remove(deleting.value); + await remove(deleting.value.model, deleting.value.force); deleting.value = null; } diff --git a/tests/Feature/Form/ParticipantDestroyActionTest.php b/tests/Feature/Form/ParticipantDestroyActionTest.php index df445dfb..86bfec01 100644 --- a/tests/Feature/Form/ParticipantDestroyActionTest.php +++ b/tests/Feature/Form/ParticipantDestroyActionTest.php @@ -14,7 +14,7 @@ beforeEach(function () { test()->setUpForm(); }); -it('testItCanDestroyAParticipant', function () { +it('cancels a participant', function () { $this->login()->loginNami()->withoutExceptionHandling(); $form = Form::factory() ->has(Participant::factory()) @@ -30,3 +30,16 @@ it('testItCanDestroyAParticipant', function () { 'id' => $form->participants->first()->id, ]); }); + +it('testItCanDestroyAParticipant', function () { + $this->login()->loginNami()->withoutExceptionHandling(); + $form = Form::factory() + ->has(Participant::factory()) + ->sections([]) + ->create(); + + $this->deleteJson(route('participant.destroy', ['participant' => $form->participants->first()]), [], ['X-Force' => '1']) + ->assertOk(); + + $this->assertDatabaseCount('participants', 0); +});