fix: refuse deleting a document assigned to a season task

This commit is contained in:
fromme committed 2026-10-15 13:02:13 +02:00
1 parent 4aa2d7a5e6
commit 3116d23199
7 files changed
+271 -14

No files matched your search

@@ -31,6 +31,7 @@
</thead>
<tbody>
{% for document in pagination %}
{% set assignments = seasonTaskDocuments[document.id] ?? [] %}
<tr>
<td>
{{ document.displayName ? document.displayName : document.originalFilename }}
@@ -38,7 +39,10 @@
<td>
{# A slot belongs to exactly one document, so this is what tells staff
which file a feature actually picks up. #}
{{ document.token ? document.token.label() : '-' }}
{% set usages = (document.token ? [document.token.label()] : [])|merge(
assignments|filter(a => a.task)|map(a => 'Saisonteam: ' ~ a.task.label())
) %}
{{ usages is empty ? '-' : usages|join(', ') }}
</td>
<td>
{{ document.size|file_size }}
@@ -51,13 +55,21 @@
</td>
<td>
<div class="flex items-center space-x-2 justify-end">
<button type="button"
class="text-red-500"
hx-get="{{ path('app_administrative_system_document_delete', { 'uuid': document.uuid }) }}"
hx-target="body"
hx-swap="beforeend">
{{ icon('delete') }}
</button>
{% if assignments is empty %}
<button type="button"
class="text-red-500"
hx-get="{{ path('app_administrative_system_document_delete', { 'uuid': document.uuid }) }}"
hx-target="body"
hx-swap="beforeend">
{{ icon('delete') }}
</button>
{% else %}
{# Held by a NOT NULL foreign key; replace it under Saisonteam-Dokumente first. #}
<span class="text-gray-300 cursor-not-allowed"
title="Als Saisonteam-Dokument hinterlegt, kann nicht gelöscht werden">
{{ icon('delete') }}
</span>
{% endif %}
<button type="button"
hx-get="{{ path('app_administrative_system_document_replace', { 'uuid': document.uuid }) }}"
hx-target="body"
@@ -1,7 +1,25 @@
{% extends 'htmx_confirmation_modal.html.twig' %}
{% block title %}{{ seasonTaskDocuments is empty ? 'Bist du sicher?' : 'Löschen nicht möglich' }}{% endblock %}
{% block content %}
<div>
Möchtest du das Dokument <em>{{ document }}</em> wirklich löschen?
</div>
{% endblock %}
{% if seasonTaskDocuments is empty %}
<div>
Möchtest du das Dokument <em>{{ document }}</em> wirklich löschen?
</div>
{% else %}
<div>
Das Dokument <em>{{ document }}</em> ist als Saisonteam-Dokument hinterlegt
{%- set labels = seasonTaskDocuments|map(m => m.task ? m.task.label() : null)|filter(l => l is not null) -%}
{%- if labels is not empty %} ({{ labels|join(', ') }}){% endif %}
und kann deshalb nicht gelöscht werden. Ersetze es zuerst unter
<a class="underline" href="{{ path('app_administrative_system_season_task_document_index') }}">Saisonteam-Dokumente</a>.
</div>
{% endif %}
{% endblock %}
{% block confirm %}
{% if seasonTaskDocuments is empty %}{{ parent() }}{% endif %}
{% endblock %}
{% block button_cancel %}{{ seasonTaskDocuments is empty ? 'Abbrechen' : 'Schließen' }}{% endblock %}
@@ -14,9 +14,11 @@
</div>
{% block content %}{% endblock %}
<div class="mt-6 flex items-center justify-between">
{% block confirm %}
<button type="button" class="btn bg-red-500" {% block button_attribute %}hx-post="{{ app.request.uri }}"{% endblock %}>
{% block button_confirm %}Ja{% endblock %}
</button>
{% endblock %}
<button type="button" class="btn" {{ stimulus_action('modal', 'close') }}>
{% block button_cancel %}Abbrechen{% endblock %}
</button>