From 8b383d2552b481dc8c2fec801fc31394d935f655 Mon Sep 17 00:00:00 2001 From: Marco Morath Date: Thu, 26 Nov 2026 08:48:14 +0100 Subject: [PATCH] feature:verlauf backup papierkorb --- README.md | 60 + docs/betrieb.md | 1 + docs/datenschutz.md | 33 +- docs/sicherheit.md | 18 +- surveybox/accounts/audit.py | 3 + surveybox/erasure_journal.py | 3 +- surveybox/forms/booking.py | 5 + surveybox/forms/erasure.py | 19 +- surveybox/forms/history.py | 1136 +++++++++++++++++ surveybox/forms/retention.py | 4 +- surveybox/forms/service.py | 1 + surveybox/locale/de/LC_MESSAGES/messages.po | 557 ++++++-- surveybox/locale/en/LC_MESSAGES/messages.po | 552 ++++++-- surveybox/locale/fr/LC_MESSAGES/messages.po | 560 ++++++-- surveybox/locale/messages.pot | 904 +++++++++---- surveybox/media/service.py | 5 + .../migrations/versions/0018_form_history.py | 83 ++ surveybox/models/__init__.py | 3 + surveybox/models/forms.py | 3 + surveybox/models/history.py | 78 ++ surveybox/web/app.py | 2 + surveybox/web/form_deps.py | 12 +- surveybox/web/routes/admin.py | 3 + surveybox/web/routes/admin_settings.py | 27 +- surveybox/web/routes/form_history.py | 199 +++ surveybox/web/routes/form_media.py | 14 +- surveybox/web/routes/form_results.py | 10 +- surveybox/web/routes/forms.py | 22 +- surveybox/web/static/css/app.css | 10 + surveybox/web/templates/admin_settings.html | 14 + surveybox/web/templates/form_designer.html | 6 + surveybox/web/templates/form_history.html | 37 + .../web/templates/form_history_compare.html | 102 ++ surveybox/web/templates/form_responses.html | 4 +- surveybox/web/templates/form_settings.html | 1 + surveybox/web/templates/forms_list.html | 27 + surveybox/web/templating.py | 5 + surveybox/worker.py | 16 + tests/test_history.py | 337 +++++ tests/test_history_units.py | 132 ++ tests/test_security_matrix.py | 2 +- 41 files changed, 4369 insertions(+), 641 deletions(-) create mode 100644 surveybox/forms/history.py create mode 100644 surveybox/migrations/versions/0018_form_history.py create mode 100644 surveybox/models/history.py create mode 100644 surveybox/web/routes/form_history.py create mode 100644 surveybox/web/templates/form_history.html create mode 100644 surveybox/web/templates/form_history_compare.html create mode 100644 tests/test_history.py create mode 100644 tests/test_history_units.py diff --git a/README.md b/README.md index 6ef46ab..f9de703 100644 --- a/README.md +++ b/README.md @@ -567,6 +567,65 @@ Prüfsumme über das Formular und nichts zur Person). Bei sehr wenigen Antworten lassen die Zahlen Rückschlüsse auf einzelne Personen zu; darauf weist die Einstellung hin. +### Verlauf und Papierkorb + +Neben den Komplettsicherungen (siehe Sicherungen) führt Surveybox für jedes +Formular einen eigenen Verlauf. Damit lassen sich versehentliche Änderungen +gezielt zurücknehmen, ohne den ganzen Bestand zurückzuspielen: Alles, was +inzwischen weiter ausgefüllt wurde, bleibt erhalten. + +**Wann ein Stand entsteht:** + +- bevor Fragen, Optionen, Bilder und Videos einer Frage, Einstellungen oder + die Freigabe geändert werden, +- bevor Verwaltende eine Antwort ändern oder löschen, +- einmal täglich (Worker), wenn sich am Formular oder seinen Antworten etwas + geändert hat, +- vor jeder Wiederherstellung (sie lässt sich so selbst zurücknehmen) und + beim Löschen des Formulars. + +Wer mehrere Änderungen kurz hintereinander macht, bekommt nicht für jede einen +eigenen Stand: Innerhalb von 15 Minuten entsteht kein neuer, solange sich an +den Antworten nichts geändert hat. Weil einzeln wiederhergestellt wird, reicht +der Stand vom Beginn der Bearbeitung. + +**Wiederherstellen:** im Designer unter *Verlauf* einen Stand wählen. Die Seite +zeigt, was sich seither unterscheidet und einzeln zurückholen lässt: + +| Eintrag | Was zurückkommt | +| --- | --- | +| Einstellung | der damalige Wert (z. B. Titel, Enddatum, Löschfrist) | +| Freigabe | die damalige Liste der Personen und Gruppen | +| gelöschte Frage | die Frage an ihrem alten Platz mit allen Antworten, Buchungen und Dateien | +| gestrichene Option | die Option an ihrem alten Platz mit ihren Buchungen und ihrem Bild | +| geänderte Frage | Text, Pflicht und Einstellungen wie damals; heutige Optionen bleiben | +| von Verwaltenden gelöschte Antwort | die Antwort mit Buchungen, Vermerken und Dateien | +| von Verwaltenden geänderte Antwort | die damaligen Werte, mit Vermerk „Aus dem Verlauf wiederhergestellt“ | + +Plätze werden dabei nicht geprüft. Reichen sie nicht mehr (der Platz einer +gelöschten Antwort ist inzwischen vergeben), sind alle Buchungen wieder da, die +Option ist **überbucht**: Designer, Verlauf und Antwortenseite weisen darauf +hin. Niemand rückt dabei auf die Warteliste. + +Änderungen und Löschungen durch Teilnehmende selbst gelten als deren Wille und +werden nicht angeboten. Was Teilnehmende löschen, verschwindet sofort auch aus +allen Ständen; ebenso alles zu einer gelöschten Person (Konto oder +Gast-Adresse). Den Verlauf sehen und nutzen Eigentümer, Mitbearbeitende, +Gruppenadministratoren und Administratoren, nicht aber Auswertende. + +**Papierkorb:** Ein gelöschtes Formular kommt in den Papierkorb unten in der +Formularliste und lässt sich dort mit allen Fragen, Antworten, Kommentaren und +Folge-Mails wiederherstellen. Das dürfen Eigentümer, wer gelöscht hat, +Gruppenadministratoren der Gruppe und Administratoren. Gibt es den Eigentümer +nicht mehr, übernimmt es, wer wiederherstellt. + +**Aufbewahrung:** unter *Administration → Einstellungen → Verlauf und +Papierkorb*. Stände standardmäßig 90 Tage (1 bis 365), Papierkorb 14 Tage +(1 bis 90). Stände enthalten die Antworten und überdauern sie nie: Endet die +Löschfrist eines Formulars, entfallen auch seine Stände; ein endgültig +gelöschtes Formular nimmt seine Stände mit. Dateien, auf die ein Stand noch +verweist, bleiben so lange im Volume. + ### Löschfristen Antworten bleiben nicht unbegrenzt gespeichert. Die Frist beginnt mit dem Ende @@ -619,6 +678,7 @@ Vor jeder Löschung zeigt eine Übersicht, was geschieht: | Plätze in laufenden Formularen | freigegeben, die Warteliste rückt nach | | Plätze in beendeten Formularen | bleiben beim Anonymisieren als anonyme Teilnahme gezählt | | Kommentare eines Kontos | bleiben, Autor „Gelöschter Benutzer“ | +| Verlauf und Papierkorb | Antworten der Person entfernt; Formulare, die mit dem Konto gelöscht werden, samt Verlauf endgültig gelöscht | | Protokoll | nur „Gelöschtes Konto Nr. …“, ohne Namen oder Adresse | Gelöschte Daten bleiben bis zur Rotation in den Sicherungen. Jede Löschung diff --git a/docs/betrieb.md b/docs/betrieb.md index c171dae..cf0ce90 100644 --- a/docs/betrieb.md +++ b/docs/betrieb.md @@ -19,6 +19,7 @@ Einstellungen und das Vorgehen bei Störungen. | Wann | Was | Wie | | --- | --- | --- | | täglich (automatisch) | Sicherung der Datenbank samt Dateiliste, Prüfung, Aufräumen | Worker ab `SURVEYBOX_BACKUP_HOUR`; Ergebnis unter *Protokoll* | +| täglich (automatisch) | Verlauf der Formulare: Stand für jedes geänderte Formular, abgelaufene Stände und Papierkorb-Einträge entfernen | Worker (Aufgabe `form_history`); Fristen unter *Administration → Einstellungen → Verlauf und Papierkorb* | | stündlich (automatisch) | Löschfristen, abgelaufene Sitzungen, Tokens, unbestätigte Gast-Adressen, Mail-Warteschlange | Worker | | wöchentlich | Sicherungen außerhalb des Hosts kopieren (`/data/backups`, inkl. `media/`) | eigener Backup-Job (z. B. Borgmatic) | | wöchentlich (CI) | bekannte Lücken in Abhängigkeiten | CI-Job `audit`; bei Fund: `UPGRADE=1 scripts/lock.sh`, testen, ausliefern | diff --git a/docs/datenschutz.md b/docs/datenschutz.md index 2564f0f..d2e486b 100644 --- a/docs/datenschutz.md +++ b/docs/datenschutz.md @@ -18,7 +18,7 @@ oder seinem Datenschutzbeauftragten. | Besondere Kategorien (Art. 9) | Keine vorgesehen. Wer Formulare mit solchen Fragen erstellt (z. B. Gesundheit, Unverträglichkeiten), prüft das je Formular und markiert die Fragen als personenbezogen | | Empfänger | Innerhalb der Organisation: Verwalter und Auswertende des jeweiligen Formulars. Auftragsverarbeiter: [Betreiber des SMTP-Relays], [Hoster/Rechenzentrum, falls nicht selbst betrieben] | | Drittland | Keine Übermittlung durch Surveybox. [Prüfen: SMTP-Relay, Hoster] | -| Löschfristen | Antworten: Löschfrist je Formular (Standard [730] Tage nach Ende), danach anonymisieren oder löschen; Konten: bis zur Löschung durch Admin oder Person selbst; Gast-Adressen ohne Bestätigung: 7 Tage; Protokoll: `SURVEYBOX_AUDIT_RETENTION_DAYS` (Standard 365 Tage); Mail-Warteschlange: nach Versand ohne Inhalt; Sicherungen: täglich `SURVEYBOX_BACKUP_KEEP_DAILY` Stück, Löschjournal sorgt nach dem Zurückspielen für erneutes Löschen | +| Löschfristen | Antworten: Löschfrist je Formular (Standard [730] Tage nach Ende), danach anonymisieren oder löschen; Konten: bis zur Löschung durch Admin oder Person selbst; Gast-Adressen ohne Bestätigung: 7 Tage; Protokoll: `SURVEYBOX_AUDIT_RETENTION_DAYS` (Standard 365 Tage); Mail-Warteschlange: nach Versand ohne Inhalt; Verlauf der Formulare (Stände mit Antworten zum punktuellen Wiederherstellen): [90] Tage, höchstens bis zum Ende der Löschfrist des Formulars; Papierkorb gelöschter Formulare: [14] Tage; Sicherungen: täglich `SURVEYBOX_BACKUP_KEEP_DAILY` Stück, Löschjournal sorgt nach dem Zurückspielen für erneutes Löschen | | TOM | Siehe Abschnitt 3 und `docs/sicherheit.md` | ## 2. Rechtsgrundlagen (Anhaltspunkte) @@ -39,7 +39,8 @@ oder seinem Datenschutzbeauftragten. | Verfügbarkeit | Tägliche Sicherung mit Prüfung; Sicherung vor jedem Update; Update in einer Transaktion mit Rücksprung | Sicherungen (`/data/backups`) zusätzlich außerhalb des Hosts aufbewahren; Wiederherstellung jährlich proben | | Belastbarkeit | Container ohne Root, schreibgeschützt, ohne Capabilities; Begrenzung von Anmeldeversuchen und Uploads | Host aktuell halten; Image nach Updates neu bauen | | Datenminimierung | Anonyme Formulare ohne Bezug zur Person; Gast-Adressen nur mit Bestätigung; Adressen für Organisatoren unsichtbar, wenn das Formular es vorsieht; Exporte ohne personenbezogene Daten wählbar | Formulare sparsam gestalten; personenbezogene Fragen markieren | -| Löschung | Löschfristen je Formular; Löschen von Konten, Gästen und einzelnen Antworten mit Vorschau; Löschjournal für zurückgespielte Sicherungen | Löschfristen passend einstellen | +| Löschung | Löschfristen je Formular; Löschen von Konten, Gästen und einzelnen Antworten mit Vorschau; Löschjournal für zurückgespielte Sicherungen; Verlauf und Papierkorb mit eigener Frist, Löschungen durch Teilnehmende und gelöschte Personen sofort auch dort entfernt | Löschfristen, Verlauf und Papierkorb passend einstellen | +| Integrität (Fehlbedienung) | Verlauf je Formular: Stände vor Änderungen und täglich; einzelne Fragen, Optionen, Einstellungen und von Verwaltenden geänderte oder gelöschte Antworten wiederherstellbar; Papierkorb für gelöschte Formulare; jede Wiederherstellung im Protokoll | Verwaltende auf Verlauf und Papierkorb hinweisen | ## 4. Cookies und ähnliche Techniken @@ -66,12 +67,33 @@ Ohne https (nur zum Testen) entfällt das Präfix `__Host-`. | --- | --- | | Auskunft, Übertragbarkeit (Art. 15, 20) | Konto → „Meine Daten herunterladen“ (JSON); Gäste über „Meine Links“ per Mail-Link oder über den persönlichen Link; Admins in der Benutzerverwaltung bzw. für Gast-Adressen | | Berichtigung (Art. 16) | Eigene Antwort ändern (sofern das Formular es erlaubt) oder durch Verwalter mit Vermerk; Profil im Konto | -| Löschung (Art. 17) | Konto löschen (selbst oder durch Admin); Gäste über „Meine Links“ oder den persönlichen Link; einzelne Antworten durch Verwalter; Löschjournal wirkt auch nach dem Zurückspielen einer Sicherung | +| Löschung (Art. 17) | Konto löschen (selbst oder durch Admin); Gäste über „Meine Links“ oder den persönlichen Link; einzelne Antworten durch Verwalter; Löschjournal wirkt auch nach dem Zurückspielen einer Sicherung; was Betroffene selbst löschen und alles zu gelöschten Personen verschwindet sofort auch aus Verlauf und Papierkorb. Von Verwaltenden gelöschte Antworten bleiben dort bis zum Ablauf der Frist wiederherstellbar | | Widerspruch, Widerruf (Art. 21, 7) | Benachrichtigungen im Konto oder per Abmeldelink abbestellen; Gast-Adresse widerrufen über „Meine Links“ | Anfragen, die nicht über die Oberfläche gehen, beantwortet [Stelle] innerhalb eines Monats; Auskunft und Löschung erledigt ein Administrator wie oben. +### Verlauf und Papierkorb + +Stände sind Kopien des Formulars mit seinen Antworten. Sie dienen der +Integrität (Art. 32 Abs. 1 lit. b, c DSGVO): Fehlbedienungen lassen sich +gezielt zurücknehmen, ohne eine Komplettsicherung einzuspielen. Regeln: + +- Aufbewahrung nach Instanzeinstellung (Standard 90 Tage, Papierkorb 14 Tage), + nie länger als die Antworten selbst: Mit der Löschfrist des Formulars + entfallen seine Stände, mit dem endgültigen Löschen eines Formulars ebenso. +- Gelöschte Personen (Konto, Gast-Adresse) und Antworten, die Teilnehmende + selbst löschen, werden sofort aus allen Ständen und dem Papierkorb entfernt + (auch nach dem Zurückspielen einer Sicherung, über das Löschjournal). +- Wiederherstellen dürfen nur Eigentümer, Mitbearbeitende, + Gruppenadministratoren und Administratoren; Auswertende nicht. Jede + Wiederherstellung steht im Protokoll. +- Ändert eine teilnehmende Person ihre Antwort selbst, kann die frühere + Fassung bis zum Ablauf der Frist in älteren Ständen liegen; sie wird aber + nie zur Wiederherstellung angeboten. Kommentare, Teilnahme-Merker und der + Versandstand der Folge-Mails stehen nur im Stand beim Löschen eines + Formulars (Papierkorb). + ## 6. Baustein für die Datenschutzerklärung > **Umfragen und Anmeldungen (Surveybox)** @@ -88,7 +110,10 @@ eines Monats; Auskunft und Löschung erledigt ein Administrator wie oben. > Zweck ist die Durchführung und Auswertung des jeweiligen Formulars; > Rechtsgrundlage ist [Art. 6 Abs. 1 lit. … DSGVO]. Die Antworten sehen nur die > für das Formular zuständigen Personen. Wir löschen oder anonymisieren -> Antworten [Frist] nach dem Ende des Formulars. Mails versenden wir über +> Antworten [Frist] nach dem Ende des Formulars. Zum Schutz vor Fehlbedienung +> bewahren wir frühere Stände eines Formulars mit seinen Antworten bis zu +> [90] Tage auf, längstens bis zu dieser Frist; was Sie selbst löschen, +> entfernen wir sofort auch dort. Mails versenden wir über > [SMTP-Anbieter]. Surveybox setzt nur technisch notwendige Cookies (Anmeldung, > Sprache, Schutz vor Missbrauch) und lädt keine Inhalte von Dritten. > diff --git a/docs/sicherheit.md b/docs/sicherheit.md index cc44c3c..1731003 100644 --- a/docs/sicherheit.md +++ b/docs/sicherheit.md @@ -13,11 +13,11 @@ ausgefüllt. | V1 | Architektur | Ein Image für Web und Worker, PostgreSQL, Volume `/data`; keine externen Dienste außer SMTP-Relay | Review | | V2 | Authentisierung | Argon2id; Passkeys (WebAuthn); TOTP mit Wiederherstellungscodes; zweiter Faktor Pflicht für Administratoren; Sperre nach Fehlversuchen; Begrenzung je IP und Konto; „Passwort vergessen“ antwortet immer gleich | `test_accounts`, `test_passkeys_groups`, `test_mail` | | V3 | Sitzungen | Zufällige Sitzungs-ID (serverseitig), Cookie `__Host-…` mit `Secure`, `HttpOnly`, `SameSite=Lax`; Leerlauf- und Höchstdauer; Abmelden auf allen Geräten; neue Sitzung nach Anmeldung | `test_accounts`, `test_security_matrix` | -| V4 | Zugriffskontrolle | Jede Anfrage prüft Rolle, Gruppe und Freigabe auf dem Server; Formular-IDs, Links und Tokens sind zufällig (UUID bzw. 128 Bit und mehr) | `test_security_matrix` (alle Routen), `test_group_scope`, `test_media_team` | +| V4 | Zugriffskontrolle | Jede Anfrage prüft Rolle, Gruppe und Freigabe auf dem Server; Formular-IDs, Links und Tokens sind zufällig (UUID bzw. 128 Bit und mehr); Verlauf nur ab Mitbearbeitung, Papierkorb nur für Eigentümer, Löschende, Gruppen- und Instanz-Admins | `test_security_matrix` (alle Routen), `test_group_scope`, `test_media_team`, `test_history` | | V5 | Eingaben und Ausgaben | Typisierte Prüfung (FastAPI/Pydantic und eigene Prüfungen je Fragetyp); SQL nur über SQLAlchemy mit Parametern; Jinja mit automatischem Escaping; Mail- und Gestaltungsvorlagen ohne ausführbare Syntax; Exporte entschärfen Formeln (CSV), schreiben Text immer als Text (XLSX, ODS) und maskieren PDF-Markup | `test_question_types`, `test_xlsx_units`, `test_phase8c_units`, `test_mail_custom_units` | | V6 | Kryptografie | Geheimnisse aus `SURVEYBOX_SECRET_KEY` abgeleitet (HKDF je Zweck); TOTP-Geheimnisse und SMTP-Passwort verschlüsselt; Mail-Inhalte in der Warteschlange verschlüsselt | `test_security_units`, `test_mail` | | V7 | Fehler und Protokoll | Keine Stacktraces an Benutzer; Protokoll für Anmeldungen, Admin-Aktionen, Exporte, Löschungen, ohne Antwortinhalte; Aufbewahrung `SURVEYBOX_AUDIT_RETENTION_DAYS` | `test_audit_actions` | -| V8 | Datenschutz | Datensparsamkeit, Löschfristen, Löschjournal, Auskunft (Art. 15/20), keine externen Ressourcen, `Cache-Control: no-store` | `test_retention`, `test_erasure`, `test_subject_export` | +| V8 | Datenschutz | Datensparsamkeit, Löschfristen, Löschjournal, Auskunft (Art. 15/20), keine externen Ressourcen, `Cache-Control: no-store`; Verlauf und Papierkorb mit eigener Frist, nie länger als die Antworten, Löschungen durch Teilnehmende und gelöschte Personen sofort auch dort entfernt | `test_retention`, `test_erasure`, `test_subject_export`, `test_history` | | V9 | Kommunikation | TLS am Reverse Proxy; HSTS; SMTP mit STARTTLS oder TLS | Konfiguration, ZAP | | V10 | Schadcode | Feste Versionen mit Hashes (`requirements.lock`); `pip-audit` bei jedem Lauf und wöchentlich; Image-Scan mit Trivy | CI | | V12 | Dateien | Typprüfung am Inhalt, Größenlimits, Speicherung außerhalb des Web-Pfads, Auslieferung nur nach Rechteprüfung, Bilder neu berechnet ohne Metadaten, kein SVG; Dokumente nur als Download mit `sandbox`-CSP | `test_media_units`, `test_form_files` | @@ -80,8 +80,12 @@ produktive Instanz. zurückspielen (`restore`), anmelden, Stichproben prüfen, Löschjournal wird angewendet. 6. **Stichproben von Hand**: - - Anmelden mit falschem Passwort, bis die Sperre greift; Meldung verrät - nicht, ob das Konto existiert. + - Fünfmal mit falschem Passwort anmelden, dann mit dem richtigen: auch das + scheitert (Konto 15 Minuten gesperrt), im Protokoll steht „Konto + gesperrt“. Die Meldung ist bei falschem Passwort, gesperrtem und + unbekanntem Konto dieselbe – sie verrät nicht, ob das Konto existiert. + Nach 30 Fehlversuchen von derselben Adresse in 15 Minuten erscheint + „Zu viele Versuche“. - Formular-Link eines Formulars mit Zugriff „Ausgewählte Benutzer“ als nicht eingeladene Person öffnen: kein Zugriff. - Antwort-ID einer fremden Antwort in die Adresse einsetzen: 404. @@ -96,9 +100,9 @@ produktive Instanz. | --- | --- | --- | --- | --- | | 25.11.2026 | `bfe9712` | CI | bestanden | checks (467 Tests, ruff, mypy, pip-audit, Migrationen) und image (Installation, Update, Sicherung/Wiederherstellung, Trivy ohne Befund) | | 26.11.2026 | Testinstanz | ZAP Baseline | bestanden | 0 FAIL, 61 PASS, 6 WARN – alle bewertet, siehe unten | -| | | Lasttest (95 %) | | | -| | | Update mit Daten | | | -| | | Wiederherstellung | | | +| 26.11.2026 | Testinstanz, 2 Web-Prozesse | Lasttest (95 %) | bestanden | 20 gleichzeitige Abrufe, je 100: `/` 142 ms, `/login` 169 ms, `/f/` 179 ms; einzeln ~30 ms; ~270 Abrufe/s | +| 26.11.2026 | Testinstanz | Update mit Daten | bestanden mit Bemerkung | Neues Image (Debian-Updates, ohne pip) auf bestehende Daten: „Datenbank ist aktuell (0017_response_note)“, Formulare, Antworten, Gestaltung und Anmeldung unverändert. Kein Schemawechsel seit 0017; Migrationen mit Daten bei den Phasen-Updates erfolgt. Voller Weg mit `OLD_IMAGE` und Sicherung vor dem Update beim nächsten Release mit Migration | +| 26.11.2026 | Testinstanz | Wiederherstellung | bestanden | Manuelle Sicherung zurückgespielt: Stand der Sicherung vollständig (Formulare, Antworten, Medien, Gestaltung, Anmeldung); nach der Sicherung angelegtes Formular entfernt; nach der Sicherung gelöschtes Konto blieb durch das Löschjournal gelöscht | | | | Stichproben | | | ### Bewertung ZAP Baseline (26.11.2026) diff --git a/surveybox/accounts/audit.py b/surveybox/accounts/audit.py index 3a09c27..ec5927c 100644 --- a/surveybox/accounts/audit.py +++ b/surveybox/accounts/audit.py @@ -70,6 +70,9 @@ ACTIONS = { "response.deleted", "response.edited", "guest.deleted", + "form.history_restored", + "form.trash_restored", + "admin.history_changed", } diff --git a/surveybox/erasure_journal.py b/surveybox/erasure_journal.py index 887ff89..a74a540 100644 --- a/surveybox/erasure_journal.py +++ b/surveybox/erasure_journal.py @@ -163,7 +163,8 @@ def replay(db: Any, settings: Settings, since: datetime) -> int: response = db.scalar(select(Response).where(Response.public_id == pid)) if response is None: continue - erasure.delete_response(db, settings, response) + erasure.delete_response(db, settings, response, + by_manager=entry.extra.get("by") == "manager") elif entry.kind == "retention": form = db.scalar(select(Form).where(Form.public_id == pid)) if form is None: diff --git a/surveybox/forms/booking.py b/surveybox/forms/booking.py index c204aa6..30bb5f9 100644 --- a/surveybox/forms/booking.py +++ b/surveybox/forms/booking.py @@ -47,6 +47,11 @@ class Availability: def full(self) -> bool: return self.capacity is not None and self.confirmed >= self.capacity + @property + def overbooked(self) -> bool: + """Mehr bestätigt als Plätze (nach einer Wiederherstellung aus dem Verlauf).""" + return self.capacity is not None and self.confirmed > self.capacity + def _capacity(question: Question, option_id: str) -> int | None: for option in types.options_of(question): diff --git a/surveybox/forms/erasure.py b/surveybox/forms/erasure.py index 56ff885..b3ea7a4 100644 --- a/surveybox/forms/erasure.py +++ b/surveybox/forms/erasure.py @@ -20,7 +20,7 @@ from sqlalchemy import delete, select, update from sqlalchemy.orm import Session from surveybox.accounts import audit -from surveybox.forms import booking, retention +from surveybox.forms import booking, history, retention from surveybox.forms.service import FillState, fill_state, participation_marker from surveybox.models import ( Comment, @@ -34,6 +34,7 @@ from surveybox.models import ( Response, UserAccount, ) +from surveybox.security.tokens import derive_key, keyed_hash from surveybox.settings import Settings RUNNING = (FillState.OPEN, FillState.SCHEDULED) @@ -117,10 +118,16 @@ def erase_responses( return summary -def delete_response(db: Session, settings: Settings, response: Response) -> None: - """Einzelne Antwort vollständig löschen (persönlicher Link); Plätze werden frei.""" +def delete_response( + db: Session, settings: Settings, response: Response, *, by_manager: bool = False +) -> None: + """Einzelne Antwort vollständig löschen; Plätze werden frei. Löscht die Person + sie selbst, verschwindet sie auch aus dem Verlauf; von Verwaltern gelöschte + Antworten bleiben dort wiederherstellbar.""" from surveybox.mail import notify + if not by_manager: + history.scrub_responses(db, response.form_id, [response.id]) form = db.get(Form, response.form_id) if form is not None: events = booking.Events() @@ -191,6 +198,10 @@ def erase_user( FormParticipation.form_id == form.id, FormParticipation.marker == participation_marker(secret, form, user))) transferred = removed = 0 + history.scrub_user( + db, user.id, f"u:{user.public_id}", + lambda form_id: keyed_hash(derive_key(secret, "participation"), f"{form_id}:{user.id}")) + history.purge_owner_trash(db, user.id) for form in owned_forms(db, user): target = form_targets.get(form.id) if target is not None and target.id != user.id: @@ -199,6 +210,7 @@ def erase_user( FormMember.form_id == form.id, FormMember.user_id == target.id)) transferred += 1 else: + history.purge_form(db, form.id) db.delete(form) removed += 1 summary.comments = int(db.execute( @@ -236,6 +248,7 @@ def erase_guest( ) -> Summary: """Alles, was an einer Gast-Adresse hängt: Antworten, Versandstand, Mailprotokoll.""" now = now or datetime.now(UTC) + history.scrub_guest(db, contact.id, f"g:{contact.public_id}") summary = erase_responses(db, settings, _guest_responses(db, contact), now) db.execute(delete(FollowupDelivery).where( FollowupDelivery.recipient == f"g:{contact.public_id}")) diff --git a/surveybox/forms/history.py b/surveybox/forms/history.py new file mode 100644 index 0000000..f7c4dd1 --- /dev/null +++ b/surveybox/forms/history.py @@ -0,0 +1,1136 @@ +# SPDX-License-Identifier: AGPL-3.0-or-later +"""Verlauf eines Formulars: Stände anlegen, vergleichen, punktuell wiederherstellen. + +Ein Stand hält das Formular mit seinen Einstellungen, Freigaben, Fragen, +Antworten, Buchungen, Vermerken und Medienverweisen als komprimiertes JSON. +Stände entstehen + +- vor Änderungen an Fragen, Optionen, Einstellungen und Freigaben, +- bevor ein Verwalter eine Antwort ändert oder löscht, +- einmal täglich, wenn sich seit dem letzten Stand etwas geändert hat, +- vor jeder Wiederherstellung (so lässt sie sich selbst zurücknehmen), +- beim Löschen eines Formulars (Papierkorb; nur dieser Stand enthält auch + Kommentare, Folge-Mails und Teilnahme-Merker, damit das Formular vollständig + zurückkommt). + +Beim Bearbeiten wird entprellt: Innerhalb von 15 Minuten entsteht kein neuer +Stand, solange sich an den Antworten nichts geändert hat. Weil einzeln +wiederhergestellt wird, reicht der Stand vom Beginn der Bearbeitung. + +Wiederhergestellt wird punktuell: einzelne Einstellungen, die Freigabe, eine +gelöschte oder geänderte Frage, eine gestrichene Option (mit ihren Buchungen), +eine von Verwaltern gelöschte oder geänderte Antwort. Alles andere bleibt, wie +es ist. Plätze werden dabei nicht geprüft: Reichen sie nicht mehr, ist die +Option überbucht und wird so angezeigt. + +Änderungen und Löschungen durch Teilnehmende gelten als deren Wille und werden +nicht zurückgenommen. Was Teilnehmende selbst löschen, verschwindet auch aus den +Ständen (scrub_responses), ebenso alles zu gelöschten Personen (scrub_person). +Läuft die Löschfrist eines Formulars ab, entfallen seine Stände (purge_form). + +Aufbewahrung: Instanzeinstellung, Standard 90 Tage; Papierkorb 14 Tage. +""" + +from __future__ import annotations + +import base64 +import hashlib +import json +import uuid +import zlib +from collections.abc import Callable, Iterable, Sequence +from dataclasses import dataclass, field +from datetime import UTC, date, datetime, time, timedelta +from decimal import Decimal +from typing import Any + +from sqlalchemy import Table, delete, func, insert, select, update +from sqlalchemy.orm import Session + +from surveybox.models import ( + AppSetting, + Base, + Form, + FormSnapshot, + FormTrash, + UserAccount, +) + +FORMAT = 1 +DEBOUNCE = timedelta(minutes=15) +SETTING_KEY = "history" +DEFAULT_HISTORY_DAYS = 90 +DEFAULT_TRASH_DAYS = 14 +HISTORY_DAYS_RANGE = (1, 365) +TRASH_DAYS_RANGE = (1, 90) + +# Anlässe; bei den ersten wird entprellt +EDIT_REASONS = frozenset({"edit", "answer_edit", "answer_delete"}) +REASONS = EDIT_REASONS | {"daily", "before_restore", "deleted"} + +# Tabellen eines Formulars, ausgewählt über die Spalte form_id (form: id) ... +BY_FORM = ("form", "form_access", "form_member", "question", "response", "booking", + "media_file", "comment", "form_participation", "followup", "form_mute") +# ... über die Antworten ... +BY_RESPONSE = ("answer", "response_note") +# ... und über die Folge-Mails +BY_FOLLOWUP = ("followup_document", "followup_delivery") +# Nur im Stand beim Löschen (Papierkorb): punktuell lässt sich daraus nichts +# zurückholen, also werden sie sonst nicht aufbewahrt (Datensparsamkeit) +TRASH_ONLY = frozenset({"comment", "form_participation", "followup", "form_mute", + "followup_document", "followup_delivery"}) +# Reihenfolge beim Einfügen (Fremdschlüssel) +INSERT_ORDER = ("form", "form_access", "form_member", "question", "response", "answer", + "booking", "media_file", "response_note", "comment", "form_participation", + "followup", "followup_document", "followup_delivery", "form_mute") +# Antworten und was dazugehört (fürs Entprellen) +DATA_TABLES = frozenset({"response", "answer", "booking", "response_note", + "form_participation", "followup_delivery"}) + +# Einstellungen, die sich einzeln zurücknehmen lassen (nicht: Status, +# Anonymität, Eigentümer, Links und Kennungen, Vorlagen) +SETTINGS = ("title", "description", "opens_at", "closes_at", "access", "link_password_hash", + "allow_multiple", "allow_edit", "guest_email", "results_visibility", + "retention_days", "deletion_mode", "privacy_notice", "require_consent", + "consent_text", "slot_names", "slots_max_per_person", "reminder_days", + "calendar_mode", "comments_mode", "comments_anonymous", "reply_to", + "comments_notify", "group_id") +QUESTION_FIELDS = ("label", "help_text", "required", "personal") +VALUE_COLUMNS = ("value_text", "value_number", "value_bool", "value_date", "value_time", + "value_datetime", "value_json") + +Rows = list[dict[str, Any]] + + +class HistoryError(ValueError): + def __init__(self, code: str) -> None: + super().__init__(code) + self.code = code + + +# -------------------------------------------------------------------------- +# Instanzeinstellungen +# -------------------------------------------------------------------------- + + +def _setting(db: Session, name: str, default: int, bounds: tuple[int, int]) -> int: + row = db.get(AppSetting, SETTING_KEY) + value = (row.value or {}).get(name) if row is not None else None + low, high = bounds + if isinstance(value, bool) or not isinstance(value, int): + return default + return value if low <= value <= high else default + + +def history_days(db: Session) -> int: + return _setting(db, "history_days", DEFAULT_HISTORY_DAYS, HISTORY_DAYS_RANGE) + + +def trash_days(db: Session) -> int: + return _setting(db, "trash_days", DEFAULT_TRASH_DAYS, TRASH_DAYS_RANGE) + + +def set_days(db: Session, history: int, trash: int) -> None: + if not HISTORY_DAYS_RANGE[0] <= history <= HISTORY_DAYS_RANGE[1]: + raise HistoryError("history_days_invalid") + if not TRASH_DAYS_RANGE[0] <= trash <= TRASH_DAYS_RANGE[1]: + raise HistoryError("trash_days_invalid") + row = db.get(AppSetting, SETTING_KEY) + value = {"history_days": history, "trash_days": trash} + if row is None: + db.add(AppSetting(key=SETTING_KEY, value=value)) + else: + row.value = {**(row.value or {}), **value} + row.updated_at = datetime.now(UTC) + + +# -------------------------------------------------------------------------- +# Kodieren +# -------------------------------------------------------------------------- + + +def _table(name: str) -> Table: + return Base.metadata.tables[name] + + +def encode_value(value: Any) -> Any: + if value is None or isinstance(value, (bool, int, float, str)): + return value + if isinstance(value, Decimal): + return {"$d": str(value)} + if isinstance(value, datetime): + return {"$dt": value.isoformat()} + if isinstance(value, date): + return {"$date": value.isoformat()} + if isinstance(value, time): + return {"$t": value.isoformat()} + if isinstance(value, uuid.UUID): + return {"$u": str(value)} + if isinstance(value, (bytes, bytearray, memoryview)): + return {"$b": base64.b64encode(bytes(value)).decode("ascii")} + return {"$j": value} # JSONB-Inhalt (dict, list) + + +def decode_value(value: Any) -> Any: + if not isinstance(value, dict): + return value + ((tag, raw),) = value.items() + decoders: dict[str, Callable[[Any], Any]] = { + "$d": Decimal, "$dt": datetime.fromisoformat, "$date": date.fromisoformat, + "$t": time.fromisoformat, "$u": uuid.UUID, "$b": base64.b64decode, + } + return decoders[tag](raw) if tag in decoders else raw + + +@dataclass +class Payload: + """Ein Stand ausgepackt: Tabelle -> Zeilen (Spalte -> Wert).""" + + form_id: int + tables: dict[str, Rows] = field(default_factory=dict) + + def rows(self, name: str) -> Rows: + return self.tables.get(name, []) + + def form(self) -> dict[str, Any]: + rows = self.rows("form") + return rows[0] if rows else {} + + def by_id(self, name: str) -> dict[Any, dict[str, Any]]: + return {r["id"]: r for r in self.rows(name)} + + def questions(self) -> Rows: + return sorted(self.rows("question"), key=lambda q: (q["position"], q["id"])) + + +def _select(db: Session, name: str, column: str, ids: Sequence[Any]) -> Rows: + if not ids: + return [] + table = _table(name) + stmt = (select(table).where(table.c[column].in_(list(ids))) + .order_by(*table.primary_key.columns)) + return [dict(row._mapping) for row in db.execute(stmt)] + + +def collect(db: Session, form_id: int, *, full: bool = False) -> Payload: + """Aktuellen Stand eines Formulars aus der Datenbank lesen.""" + db.flush() + payload = Payload(form_id) + for name in BY_FORM: + if full or name not in TRASH_ONLY: + payload.tables[name] = _select(db, name, "id" if name == "form" else "form_id", + [form_id]) + response_ids = [r["id"] for r in payload.rows("response")] + for name in BY_RESPONSE: + payload.tables[name] = _select(db, name, "response_id", response_ids) + if full: + followup_ids = [r["id"] for r in payload.rows("followup")] + for name in BY_FOLLOWUP: + payload.tables[name] = _select(db, name, "followup_id", followup_ids) + return payload + + +def _encode_tables(tables: dict[str, Rows]) -> dict[str, Any]: + encoded: dict[str, Any] = {} + for name in sorted(tables): + cols = [c.name for c in _table(name).columns] + encoded[name] = {"cols": cols, "rows": [[encode_value(row.get(c)) for c in cols] + for row in tables[name]]} + return encoded + + +def _decode_tables(raw: dict[str, Any]) -> dict[str, Rows]: + """Spalten, die es (nach einem Update) nicht mehr gibt, fallen weg; neue Spalten + fehlen und bekommen beim Einfügen ihren Standardwert.""" + tables: dict[str, Rows] = {} + for name, block in raw.items(): + if name not in Base.metadata.tables: + continue + known = set(_table(name).columns.keys()) + cols = block["cols"] + tables[name] = [{c: decode_value(v) for c, v in zip(cols, row, strict=True) + if c in known} for row in block["rows"]] + return tables + + +def _digest(data: Any) -> bytes: + text = json.dumps(data, sort_keys=True, separators=(",", ":"), ensure_ascii=False) + return hashlib.sha256(text.encode()).digest() + + +def _hashes(encoded: dict[str, Any]) -> tuple[bytes, bytes]: + """(alles, nur Antworten). Dateien Teilnehmender zählen zu den Antworten; + `updated_at` des Formulars zählt nicht (ändert sich auch ohne Inhalt).""" + data: dict[str, Any] = {} + rest: dict[str, Any] = {} + for name, block in encoded.items(): + if name in DATA_TABLES: + data[name] = block + elif name == "media_file": + idx = block["cols"].index("response_id") + data[name] = [r for r in block["rows"] if r[idx] is not None] + rest[name] = [r for r in block["rows"] if r[idx] is None] + elif name == "form": + idx = block["cols"].index("updated_at") + rest[name] = [[v for i, v in enumerate(r) if i != idx] for r in block["rows"]] + else: + rest[name] = block + data_hash = _digest(data) + return _digest({"data": data_hash.hex(), "rest": rest}), data_hash + + +def _people(payload: Payload) -> tuple[list[int], list[int]]: + users: set[int] = set() + for name, column in (("response", "user_id"), ("comment", "user_id"), + ("form_access", "user_id"), ("form_member", "user_id"), + ("form", "owner_id"), ("form_mute", "user_id"), + ("response_note", "author_id")): + users.update(int(r[column]) for r in payload.rows(name) if r.get(column) is not None) + guests = {int(r["guest_contact_id"]) for r in payload.rows("response") + if r.get("guest_contact_id") is not None} + return sorted(users), sorted(guests) + + +def _media_keys(payload: Payload) -> list[str]: + keys: set[str] = set() + for row in payload.rows("media_file"): + keys.add(str(row["storage_key"])) + if row.get("thumb_key"): + keys.add(str(row["thumb_key"])) + return sorted(keys) + + +@dataclass +class Packed: + payload: bytes + full_hash: bytes + data_hash: bytes + size: int + + +def pack(payload: Payload) -> Packed: + encoded = _encode_tables(payload.tables) + full_hash, data_hash = _hashes(encoded) + raw = json.dumps({"v": FORMAT, "form_id": payload.form_id, "tables": encoded}, + separators=(",", ":"), ensure_ascii=False).encode() + return Packed(zlib.compress(raw, 6), full_hash, data_hash, len(raw)) + + +def unpack(snapshot: FormSnapshot) -> Payload: + raw = json.loads(zlib.decompress(snapshot.payload)) + return Payload(int(raw["form_id"]), _decode_tables(raw["tables"])) + + +def _store(snapshot: FormSnapshot, payload: Payload) -> None: + packed = pack(payload) + snapshot.payload = packed.payload + snapshot.full_hash = packed.full_hash + snapshot.data_hash = packed.data_hash + snapshot.size = packed.size + snapshot.media_keys = _media_keys(payload) + snapshot.user_ids, snapshot.guest_ids = _people(payload) + + +# -------------------------------------------------------------------------- +# Stände anlegen +# -------------------------------------------------------------------------- + + +def latest(db: Session, form_id: int) -> FormSnapshot | None: + return db.scalar(select(FormSnapshot).where(FormSnapshot.form_id == form_id) + .order_by(FormSnapshot.created_at.desc(), FormSnapshot.id.desc()).limit(1)) + + +def capture( + db: Session, form_id: int, reason: str, actor_id: int | None = None, *, + force: bool = False, now: datetime | None = None, +) -> FormSnapshot | None: + """Stand anlegen, wenn sich seit dem letzten etwas geändert hat (siehe oben).""" + if reason not in REASONS: + raise ValueError(reason) + now = now or datetime.now(UTC) + payload = collect(db, form_id, full=reason == "deleted") + if not payload.rows("form"): + return None + packed = pack(payload) + last = latest(db, form_id) + if not force and last is not None: + if last.full_hash == packed.full_hash: + return None + if (reason in EDIT_REASONS and last.reason in EDIT_REASONS | {"before_restore"} + and last.data_hash == packed.data_hash and now - last.created_at < DEBOUNCE): + return None + snapshot = FormSnapshot(form_id=form_id, created_at=now, reason=reason, actor_id=actor_id) + snapshot.payload = packed.payload + snapshot.full_hash = packed.full_hash + snapshot.data_hash = packed.data_hash + snapshot.size = packed.size + snapshot.media_keys = _media_keys(payload) + snapshot.user_ids, snapshot.guest_ids = _people(payload) + db.add(snapshot) + db.flush() + return snapshot + + +def before_change(db: Session, form: Form, user: UserAccount | None, + reason: str = "edit") -> None: + """Vor einer Änderung durch Verwalter aufrufen (in derselben Transaktion).""" + capture(db, form.id, reason, user.id if user is not None else None) + + +def snapshots(db: Session, form_id: int) -> list[FormSnapshot]: + return list(db.scalars( + select(FormSnapshot).where(FormSnapshot.form_id == form_id) + .order_by(FormSnapshot.created_at.desc(), FormSnapshot.id.desc()) + )) + + +def find_snapshot(db: Session, form_id: int, snapshot_id: int) -> FormSnapshot | None: + snapshot = db.get(FormSnapshot, snapshot_id) + return snapshot if snapshot is not None and snapshot.form_id == form_id else None + + +# -------------------------------------------------------------------------- +# Vergleich +# -------------------------------------------------------------------------- + + +@dataclass +class Item: + """Ein Unterschied zwischen Stand und jetzt, der sich wiederherstellen lässt.""" + + key: str + # setting, access, question_deleted, question_changed, option, + # response_deleted, response_changed + kind: str + title: str = "" + setting: str = "" + old: Any = None + new: Any = None + answers: int = 0 + bookings: int = 0 + question: str = "" + when: datetime | None = None + + +@dataclass +class Comparison: + snapshot: FormSnapshot + settings: list[Item] = field(default_factory=list) + questions: list[Item] = field(default_factory=list) + responses: list[Item] = field(default_factory=list) + + @property + def empty(self) -> bool: + return not (self.settings or self.questions or self.responses) + + def items(self) -> list[Item]: + return [*self.settings, *self.questions, *self.responses] + + +def _options(config: dict[str, Any] | None) -> list[dict[str, Any]]: + return [dict(o) for o in (config or {}).get("options") or []] + + +def _without_options(config: dict[str, Any] | None) -> dict[str, Any]: + return {k: v for k, v in (config or {}).items() if k not in ("options", "confirmed")} + + +def _answer_map(payload: Payload, response_id: int) -> dict[int, tuple[Any, ...]]: + return {a["question_id"]: tuple(a.get(c) for c in VALUE_COLUMNS) + for a in payload.rows("answer") if a["response_id"] == response_id} + + +def _response_title(db: Session, payload: Payload, response: dict[str, Any], + anonymous: bool) -> str: + """Wer geantwortet hat (wie in der Auswertung); bei anonymen Formularen nichts.""" + if anonymous: + return "" + if response.get("user_id"): + user = db.get(UserAccount, response["user_id"]) + if user is not None: + return user.display_name + names = {q["id"] for q in payload.rows("question") if q["type"] == "participant_name"} + for answer in payload.rows("answer"): + if answer["response_id"] == response["id"] and answer["question_id"] in names: + parts = answer.get("value_json") or {} + if isinstance(parts, dict): + text = " ".join(str(v) for v in parts.values() if v) + if text: + return text + return "" + + +def compare(db: Session, form: Form, snapshot: FormSnapshot) -> Comparison: + old = unpack(snapshot) + now = collect(db, form.id) + result = Comparison(snapshot) + _compare_settings(old, now, result) + _compare_questions(old, now, result) + _compare_responses(db, old, now, result, snapshot.created_at, bool(form.anonymous)) + return result + + +def _access_entries(payload: Payload) -> set[tuple[Any, Any]]: + return {(r.get("user_id"), r.get("group_id")) for r in payload.rows("form_access")} + + +def _compare_settings(old: Payload, now: Payload, result: Comparison) -> None: + before, current = old.form(), now.form() + for name in SETTINGS: + if name in before and before.get(name) != current.get(name): + result.settings.append(Item(f"setting:{name}", "setting", setting=name, + old=before.get(name), new=current.get(name))) + if _access_entries(old) != _access_entries(now): + result.settings.append(Item("access", "access", old=len(_access_entries(old)), + new=len(_access_entries(now)))) + + +def _definition_differs(old: dict[str, Any], new: dict[str, Any]) -> bool: + """Frage geändert (ohne gestrichene oder neue Optionen; die zählen einzeln).""" + if any(old.get(f) != new.get(f) for f in QUESTION_FIELDS): + return True + if _without_options(old["config"]) != _without_options(new["config"]): + return True + new_ids = {o.get("id") for o in _options(new["config"])} + old_ids = {o.get("id") for o in _options(old["config"])} + common_old = [o for o in _options(old["config"]) if o.get("id") in new_ids] + common_new = [o for o in _options(new["config"]) if o.get("id") in old_ids] + return common_old != common_new + + +def _compare_questions(old: Payload, now: Payload, result: Comparison) -> None: + current = now.by_id("question") + for question in old.questions(): + qid = question["id"] + if qid not in current: + result.questions.append(Item( + f"q_del:{qid}", "question_deleted", title=question["label"], + answers=sum(1 for a in old.rows("answer") if a["question_id"] == qid), + bookings=sum(1 for b in old.rows("booking") if b["question_id"] == qid))) + continue + here = current[qid] + if _definition_differs(question, here): + result.questions.append(Item(f"q_chg:{qid}", "question_changed", + title=question["label"])) + kept = {o.get("id") for o in _options(here["config"])} + for option in _options(question["config"]): + oid = option.get("id") + if not oid or oid in kept: + continue + result.questions.append(Item( + f"opt:{qid}:{oid}", "option", title=str(option.get("label") or ""), + question=question["label"], + bookings=sum(1 for b in old.rows("booking") + if b["question_id"] == qid and b["option_id"] == oid))) + + +def _compare_responses(db: Session, old: Payload, now: Payload, result: Comparison, + since: datetime, anonymous: bool) -> None: + current = now.by_id("response") + common = set(old.by_id("question")) & set(now.by_id("question")) + for response in sorted(old.rows("response"), key=lambda r: (r["submitted_at"], r["id"])): + rid = response["id"] + if rid not in current: + result.responses.append(Item( + f"r_del:{rid}", "response_deleted", + title=_response_title(db, old, response, anonymous), + when=response["submitted_at"], + answers=sum(1 for a in old.rows("answer") if a["response_id"] == rid), + bookings=sum(1 for b in old.rows("booking") if b["response_id"] == rid))) + continue + here = current[rid] + if here.get("edited_by") != "manager": + continue # zuletzt von der Person selbst geändert: ihr Wille gilt + if here.get("updated_at") is None or here["updated_at"] <= since: + continue + before = {q: v for q, v in _answer_map(old, rid).items() if q in common} + after = {q: v for q, v in _answer_map(now, rid).items() if q in common} + changed = {q for q in set(before) | set(after) if before.get(q) != after.get(q)} + if changed: + result.responses.append(Item( + f"r_chg:{rid}", "response_changed", + title=_response_title(db, now, here, anonymous), + when=here["updated_at"], answers=len(changed))) + + +# -------------------------------------------------------------------------- +# Einfügen +# -------------------------------------------------------------------------- + +def _existing(db: Session, table: str, ids: Iterable[Any], column: str = "id") -> set[Any]: + wanted = {i for i in ids if i is not None} + if not wanted: + return set() + target = _table(table) + return set(db.scalars(select(target.c[column]).where(target.c[column].in_(wanted)))) + + +def _insert(db: Session, name: str, rows: Rows, *, new_ids: bool = False) -> int: + """Zeilen mit ihren alten Kennungen einfügen (new_ids: neue vergeben). + + Fehlt das Ziel eines Verweises inzwischen (ein Konto, eine Gruppe, eine + Gast-Adresse, eine Frage), gilt dasselbe wie beim Löschen in der Datenbank: + ON DELETE SET NULL leert den Verweis, sonst entfällt die Zeile.""" + if not rows: + return 0 + table = _table(name) + rows = [dict(r) for r in rows] + for fk in table.foreign_keys: + column = fk.parent.name + present = _existing(db, fk.column.table.name, (r.get(column) for r in rows), + fk.column.name) + kept = [] + for row in rows: + value = row.get(column) + if value is None or value in present: + kept.append(row) + elif (fk.ondelete or "").upper() == "SET NULL" and fk.parent.nullable: + row[column] = None + if name == "comment" and column == "user_id": + row["author_deleted"] = True + kept.append(row) + rows = kept + if new_ids and "id" in table.c: + for row in rows: + row.pop("id", None) + if rows: + db.execute(insert(table), rows) + return len(rows) + + +def _still_chosen(db: Session, qid: int, option_id: str) -> set[int]: + """Antworten, die eine (gestrichene) Option noch gewählt haben. Wer seither + selbst umgewählt hat, bekommt den alten Platz nicht zurück.""" + table = _table("answer") + found = set() + for response_id, value in db.execute( + select(table.c.response_id, table.c.value_json).where(table.c.question_id == qid)): + selected = (value or {}).get("selected") if isinstance(value, dict) else None + if isinstance(selected, list) and option_id in selected: + found.add(int(response_id)) + return found + + +def _question_ids(db: Session, form_id: int) -> list[int]: + table = _table("question") + return list(db.scalars(select(table.c.id).where(table.c.form_id == form_id) + .order_by(table.c.position, table.c.id))) + + +def _question_row(db: Session, form_id: int, qid: int) -> dict[str, Any] | None: + table = _table("question") + row = db.execute(select(table).where(table.c.id == qid, table.c.form_id == form_id)).first() + return dict(row._mapping) if row is not None else None + + +def _questions(db: Session, form_id: int) -> dict[int, dict[str, Any]]: + return {r["id"]: r for r in _select(db, "question", "form_id", [form_id])} + + +def _response_ids(db: Session, form_id: int) -> set[int]: + table = _table("response") + return set(db.scalars(select(table.c.id).where(table.c.form_id == form_id))) + + +def _set_question(db: Session, qid: int, **values: Any) -> None: + table = _table("question") + db.execute(update(table).where(table.c.id == qid).values(**values)) + + +def _touch(db: Session, form_id: int) -> None: + table = _table("form") + db.execute(update(table).where(table.c.id == form_id).values(updated_at=datetime.now(UTC))) + + +def _restore_bookings(db: Session, form_id: int, old: Payload, question_id: int, + option_ids: set[str] | None, response_ids: set[int]) -> int: + """Buchungen aus dem Stand zurück, ohne Rücksicht auf die Platzzahl.""" + table = _table("booking") + present = {(r.response_id, r.option_id) for r in db.execute( + select(table.c.response_id, table.c.option_id).where(table.c.question_id == question_id))} + rows = [b for b in old.rows("booking") + if b["question_id"] == question_id and b["response_id"] in response_ids + and (option_ids is None or b["option_id"] in option_ids) + and (b["response_id"], b["option_id"]) not in present] + taken = _existing(db, "booking", (b["id"] for b in rows)) + fresh = [] + for row in rows: + row = {**row, "form_id": form_id} + if row["id"] in taken: + row.pop("id") + fresh.append(row) + if fresh: + db.execute(insert(table), fresh) + return len(fresh) + + +def _restore_media(db: Session, old: Payload, wanted: Callable[[dict[str, Any]], bool]) -> None: + rows = [m for m in old.rows("media_file") if wanted(m)] + present = _existing(db, "media_file", (m["id"] for m in rows)) + _insert(db, "media_file", [m for m in rows if m["id"] not in present]) + + +def _question_media(db: Session, old: Payload, qid: int, config: dict[str, Any]) -> None: + """Bilder und Videos einer Frage und ihrer Optionen, die inzwischen fehlen.""" + from surveybox.media.service import question_media_ids + + referenced = set(question_media_ids(config)) + _restore_media(db, old, lambda m: m["response_id"] is None and ( + m["question_id"] == qid or str(m["public_id"]) in referenced)) + + +def _clean_conditions(config: dict[str, Any], allowed: set[int]) -> dict[str, Any]: + """Regeln auf Fragen weglassen, die es nicht (mehr) davor gibt.""" + from surveybox.forms import conditions + + rules = (config.get("condition") or {}).get("rules") or [] + for ref in {int(r["q"]) for r in rules if "q" in r} - allowed: + cleaned = conditions.without_reference(config, ref) + if cleaned is not None: # leeres dict ist ein gültiges Ergebnis + config = cleaned + return config + + +# -------------------------------------------------------------------------- +# Punktuell wiederherstellen +# -------------------------------------------------------------------------- + + +@dataclass +class Outcome: + restored: int = 0 + overbooked: list[str] = field(default_factory=list) + + +# Erst Einstellungen, dann Fragen, dann Optionen (vor den Fragen-Definitionen, +# die gestrichene Optionen nicht von sich aus zurückholen), dann Antworten +ORDER = {"setting": 0, "access": 0, "q_del": 1, "opt": 2, "q_chg": 3, "r_del": 4, "r_chg": 5} + + +def restore(db: Session, form: Form, snapshot: FormSnapshot, keys: Sequence[str], + actor: UserAccount, note: str = "") -> Outcome: + """Ausgewählte Unterschiede (Item.key) aus dem Stand zurückholen. `note` ist der + Vermerk an zurückgesetzten Antworten (in der Sprache der Person, die es tut).""" + available = {item.key for item in compare(db, form, snapshot).items()} + chosen = [k for k in dict.fromkeys(keys) if k in available] + if not chosen: + raise HistoryError("nothing_selected") + capture(db, form.id, "before_restore", actor.id, force=True) + old = unpack(snapshot) + form_id = form.id + outcome = Outcome() + for key in sorted(chosen, key=lambda k: ORDER[k.split(":", 1)[0]]): + kind, _, rest = key.partition(":") + if kind == "setting": + _restore_setting(db, form_id, old, rest) + elif kind == "access": + _restore_access(db, form_id, old) + elif kind == "q_del": + _restore_question(db, form_id, old, int(rest)) + elif kind == "opt": + qid, _, oid = rest.partition(":") + _restore_option(db, form_id, old, int(qid), oid) + elif kind == "q_chg": + _restore_definition(db, form_id, old, int(rest)) + elif kind == "r_del": + _restore_response(db, form_id, old, int(rest)) + elif kind == "r_chg": + _restore_answers(db, form_id, old, int(rest), actor, snapshot, note) + outcome.restored += 1 + _touch(db, form_id) + db.flush() + db.expire_all() + outcome.overbooked = overbooked(db, form) + return outcome + + +def _restore_setting(db: Session, form_id: int, old: Payload, name: str) -> None: + if name not in SETTINGS or name not in old.form(): + return + value = old.form()[name] + if name == "group_id" and value is not None and not _existing(db, "user_group", [value]): + value = None + table = _table("form") + db.execute(update(table).where(table.c.id == form_id).values({name: value})) + + +def _restore_access(db: Session, form_id: int, old: Payload) -> None: + table = _table("form_access") + db.execute(delete(table).where(table.c.form_id == form_id)) + _insert(db, "form_access", old.rows("form_access"), new_ids=True) + + +def _restore_question(db: Session, form_id: int, old: Payload, qid: int) -> None: + """Gelöschte Frage mit ihren Antworten, Buchungen und Dateien zurück, an ihren + alten Platz (vor die nächste Frage aus dem Stand, die es noch gibt).""" + source = old.by_id("question").get(qid) + if source is None or _existing(db, "question", [qid]): + return + order = [q["id"] for q in old.questions()] + current = _question_ids(db, form_id) + successors = [i for i in order[order.index(qid) + 1:] if i in current] + slot = current.index(successors[0]) if successors else len(current) + row = dict(source) + row["config"] = _clean_conditions(dict(row["config"] or {}), set(current[:slot])) + row["position"] = len(current) + 1000 # vorläufig, siehe unten + _insert(db, "question", [row]) + responses = _response_ids(db, form_id) + _insert(db, "answer", [a for a in old.rows("answer") + if a["question_id"] == qid and a["response_id"] in responses]) + _restore_bookings(db, form_id, old, qid, None, responses) + _question_media(db, old, qid, row["config"]) + _restore_media(db, old, lambda m: m["question_id"] == qid + and m["response_id"] is not None and m["response_id"] in responses) + for position, question_id in enumerate([*current[:slot], qid, *current[slot:]]): + _set_question(db, question_id, position=position) + + +def _restore_option(db: Session, form_id: int, old: Payload, qid: int, oid: str) -> None: + """Gestrichene Option zurück, hinter ihren alten Vorgänger, mit ihren Buchungen.""" + source = old.by_id("question").get(qid) + here = _question_row(db, form_id, qid) + if source is None or here is None: + return + old_options = _options(source["config"]) + option = next((o for o in old_options if o.get("id") == oid), None) + config = dict(here["config"] or {}) + current = _options(config) + if option is None or any(o.get("id") == oid for o in current): + return + ids = [o.get("id") for o in current] + old_ids = [o.get("id") for o in old_options] + before = [i for i in old_ids[:old_ids.index(oid)] if i in ids] + slot = ids.index(before[-1]) + 1 if before else 0 + config["options"] = [*current[:slot], option, *current[slot:]] + if oid in ((source["config"] or {}).get("confirmed") or []): + config["confirmed"] = [*(config.get("confirmed") or []), oid] + _set_question(db, qid, config=config) + if option.get("image"): + image = str(option["image"]) + _restore_media(db, old, lambda m: str(m["public_id"]) == image) + if here["type"] == "slots": + _restore_bookings(db, form_id, old, qid, {oid}, _still_chosen(db, qid, oid)) + + +def _restore_definition(db: Session, form_id: int, old: Payload, qid: int) -> None: + """Frage wie im Stand (Text, Pflicht, Einstellungen, Optionen). Optionen, die es + heute gibt, bleiben: geänderte bekommen ihre alte Fassung, neue bleiben dahinter; + gestrichene kommen nur über ihren eigenen Eintrag zurück.""" + source = old.by_id("question").get(qid) + here = _question_row(db, form_id, qid) + if source is None or here is None: + return + config = {k: v for k, v in (source["config"] or {}).items() if k != "confirmed"} + current = _options(here["config"]) + current_ids = {o.get("id") for o in current} + old_options = _options(source["config"]) + old_ids = {o.get("id") for o in old_options} + if old_options or current: + config["options"] = ([o for o in old_options if o.get("id") in current_ids] + + [o for o in current if o.get("id") not in old_ids]) + confirmed = (here["config"] or {}).get("confirmed") + if confirmed is not None: + config["confirmed"] = confirmed # bestätigte Termine gehören zu den Antworten + ordered = _question_ids(db, form_id) + config = _clean_conditions(config, set(ordered[:ordered.index(qid)])) + _set_question(db, qid, config=config, **{f: source.get(f) for f in QUESTION_FIELDS}) + _question_media(db, old, qid, config) + + +def _restore_response(db: Session, form_id: int, old: Payload, rid: int) -> None: + """Von Verwaltern gelöschte Antwort zurück; Antworten auf Fragen, die es nicht + mehr gibt, und Buchungen gestrichener Optionen bleiben weg.""" + source = old.by_id("response").get(rid) + if source is None or _existing(db, "response", [rid]): + return + if source.get("access_hash") is not None: + table = _table("response") + if db.scalar(select(table.c.id).where(table.c.access_hash == source["access_hash"])): + source = {**source, "access_hash": None} + _insert(db, "response", [source]) + questions = _questions(db, form_id) + _insert(db, "answer", [a for a in old.rows("answer") + if a["response_id"] == rid and a["question_id"] in questions]) + for qid, question in questions.items(): + if question["type"] == "slots": + _restore_bookings(db, form_id, old, qid, + {str(o.get("id")) for o in _options(question["config"])}, {rid}) + _insert(db, "response_note", [n for n in old.rows("response_note") + if n["response_id"] == rid], new_ids=True) + _restore_media(db, old, lambda m: m["response_id"] == rid + and (m["question_id"] is None or m["question_id"] in questions)) + + +def _restore_answers(db: Session, form_id: int, old: Payload, rid: int, actor: UserAccount, + snapshot: FormSnapshot, note: str) -> None: + """Von Verwaltern geänderte Antwort auf den Stand zurück; mit Vermerk.""" + responses = _table("response") + if db.scalar(select(responses.c.form_id).where(responses.c.id == rid)) != form_id: + return + questions = _questions(db, form_id) + common = sorted(set(questions) & set(old.by_id("question")), + key=lambda q: (questions[q]["position"], q)) + before = {a["question_id"]: a for a in _select(db, "answer", "response_id", [rid])} + after = {a["question_id"]: a for a in old.rows("answer") if a["response_id"] == rid} + changed = [q for q in common if tuple((before.get(q) or {}).get(c) for c in VALUE_COLUMNS) + != tuple((after.get(q) or {}).get(c) for c in VALUE_COLUMNS)] + answers = _table("answer") + db.execute(delete(answers).where(answers.c.response_id == rid, + answers.c.question_id.in_(common))) + _insert(db, "answer", [after[q] for q in common if q in after], new_ids=True) + wanted = set(common) + _restore_media(db, old, lambda m: m["response_id"] == rid and m["question_id"] in wanted) + bookings = _table("booking") + for qid in common: + if questions[qid]["type"] != "slots": + continue + db.execute(delete(bookings).where(bookings.c.response_id == rid, + bookings.c.question_id == qid)) + _restore_bookings(db, form_id, old, qid, + {str(o.get("id")) for o in _options(questions[qid]["config"])}, {rid}) + db.execute(update(responses).where(responses.c.id == rid) + .values(updated_at=datetime.now(UTC), edited_by="manager")) + body = note or snapshot.created_at.astimezone(UTC).strftime("↺ %Y-%m-%d %H:%M UTC") + db.execute(insert(_table("response_note")).values( + response_id=rid, author_id=actor.id, body=body[:1000], + changed=[questions[q]["label"] for q in changed])) + + +def overbooked(db: Session, form: Form) -> list[str]: + """Optionen, auf denen mehr Plätze belegt sind als vorhanden.""" + from surveybox.forms import booking, types + + found = [] + for question in form.questions: + if question.type != "slots": + continue + labels = {o["id"]: o.get("label") or "" for o in types.options_of(question)} + for oid, avail in booking.availability(db, question).items(): + if avail.overbooked: + found.append(f"{question.label}: {labels.get(oid, oid)}") + return found + + +# -------------------------------------------------------------------------- +# Papierkorb +# -------------------------------------------------------------------------- + + +def trash_form(db: Session, form: Form, actor: UserAccount | None) -> FormTrash: + """Formular in den Papierkorb: vollständiger Stand, dann löschen.""" + from surveybox.forms import service + + snapshot = capture(db, form.id, "deleted", actor.id if actor else None, force=True) + if snapshot is None: # pragma: no cover - das Formular existiert ja + raise HistoryError("trash_failed") + entry = FormTrash( + form_id=form.id, public_id=form.public_id, title=form.title, owner_id=form.owner_id, + deleted_by=actor.id if actor else None, snapshot_id=snapshot.id, + responses=service.response_count(db, form), + extra={"is_template": bool(form.is_template), "group_id": form.group_id}, + ) + db.add(entry) + service.delete_form(db, form) + db.flush() + return entry + + +def may_restore(user: UserAccount, entry: FormTrash, managed: frozenset[int]) -> bool: + """Admins, Eigentümer, wer gelöscht hat, Gruppenadmins der Gruppe des Formulars.""" + group_id = (entry.extra or {}).get("group_id") + return (user.is_admin or entry.owner_id == user.id or entry.deleted_by == user.id + or (group_id is not None and group_id in managed)) + + +def visible_trash(db: Session, user: UserAccount, + managed: frozenset[int] = frozenset()) -> list[FormTrash]: + """Gelöschte Formulare, die jemand wiederherstellen darf, neueste zuerst.""" + entries = db.scalars(select(FormTrash).order_by(FormTrash.deleted_at.desc())) + return [e for e in entries if may_restore(user, e, managed)] + + +def find_trash(db: Session, user: UserAccount, managed: frozenset[int], + public_id: str) -> FormTrash | None: + try: + pid = uuid.UUID(public_id) + except ValueError: + return None + entry = db.scalar(select(FormTrash).where(FormTrash.public_id == pid)) + if entry is None or not may_restore(user, entry, managed): + return None + return entry + + +def expires_at(db: Session, entry: FormTrash) -> datetime: + return entry.deleted_at + timedelta(days=trash_days(db)) + + +def restore_trashed(db: Session, entry: FormTrash, actor: UserAccount) -> Form: + """Gelöschtes Formular vollständig zurück. Fehlt der Eigentümer inzwischen, + übernimmt es, wer es wiederherstellt.""" + snapshot = db.get(FormSnapshot, entry.snapshot_id) + if snapshot is None or _existing(db, "form", [entry.form_id]): + raise HistoryError("trash_gone") + payload = unpack(snapshot) + form_row = dict(payload.form()) + if not _existing(db, "user_account", [form_row.get("owner_id")]): + form_row["owner_id"] = actor.id + payload.tables["form"] = [form_row] + for name in INSERT_ORDER: + _insert(db, name, payload.rows(name)) + db.delete(entry) + db.flush() + form = db.get(Form, payload.form_id) + if form is None: # pragma: no cover + raise HistoryError("trash_gone") + return form + + +# -------------------------------------------------------------------------- +# Löschen und Datenschutz +# -------------------------------------------------------------------------- + + +def purge_form(db: Session, form_id: int) -> None: + """Alle Stände eines Formulars und seinen Papierkorb-Eintrag entfernen.""" + db.execute(delete(FormTrash).where(FormTrash.form_id == form_id)) + db.execute(delete(FormSnapshot).where(FormSnapshot.form_id == form_id)) + + +def _rewrite(snapshot: FormSnapshot, change: Callable[[Payload], bool]) -> None: + payload = unpack(snapshot) + if change(payload): + _store(snapshot, payload) + + +def _drop_responses(payload: Payload, response_ids: set[int]) -> bool: + if not response_ids & {r["id"] for r in payload.rows("response")}: + return False + payload.tables["response"] = [r for r in payload.rows("response") + if r["id"] not in response_ids] + for name in ("answer", "booking", "response_note", "followup_delivery", "media_file"): + if name in payload.tables: + payload.tables[name] = [r for r in payload.rows(name) + if r.get("response_id") not in response_ids] + return True + + +def _drop_rows(payload: Payload, name: str, keep: Callable[[dict[str, Any]], bool]) -> bool: + if name not in payload.tables: + return False + before = len(payload.tables[name]) + payload.tables[name] = [r for r in payload.tables[name] if keep(r)] + return before != len(payload.tables[name]) + + +def scrub_responses(db: Session, form_id: int, response_ids: Iterable[int]) -> None: + """Antworten aus allen Ständen eines Formulars entfernen (Teilnehmende haben + sie selbst gelöscht).""" + wanted = set(response_ids) + if not wanted: + return + for snapshot in db.scalars(select(FormSnapshot).where(FormSnapshot.form_id == form_id)): + _rewrite(snapshot, lambda p: _drop_responses(p, wanted)) + db.flush() + + +def scrub_user(db: Session, user_id: int, recipient: str, + marker: Callable[[int], bytes] | None = None) -> None: + """Gelöschtes Konto aus allen Ständen entfernen, auch aus dem Papierkorb: + Antworten, Freigaben, Rollen, Stummschaltungen, Versandstand und Merker; + Kommentare und Vermerke bleiben ohne Bezug zur Person.""" + + def change(payload: Payload) -> bool: + ids = {r["id"] for r in payload.rows("response") if r.get("user_id") == user_id} + changed = _drop_responses(payload, ids) + for name in ("form_access", "form_member", "form_mute"): + changed |= _drop_rows(payload, name, lambda r: r.get("user_id") != user_id) + changed |= _drop_rows(payload, "followup_delivery", + lambda r: r.get("recipient") != recipient) + if marker is not None: + mine = marker(payload.form_id) + changed |= _drop_rows(payload, "form_participation", + lambda r: bytes(r.get("marker") or b"") != mine) + for row in payload.rows("comment"): + if row.get("user_id") == user_id: + row["user_id"], row["author_deleted"] = None, True + changed = True + for row in payload.rows("response_note"): + if row.get("author_id") == user_id: + row["author_id"] = None + changed = True + for row in payload.rows("form"): + if row.get("owner_id") == user_id: + row["owner_id"] = None + changed = True + return changed + + for snapshot in db.scalars(select(FormSnapshot).where( + FormSnapshot.user_ids.contains([user_id]))): + _rewrite(snapshot, change) + db.flush() + + +def scrub_guest(db: Session, guest_id: int, recipient: str) -> None: + """Gelöschte Gast-Adresse aus allen Ständen entfernen.""" + + def change(payload: Payload) -> bool: + ids = {r["id"] for r in payload.rows("response") if r.get("guest_contact_id") == guest_id} + changed = _drop_responses(payload, ids) + changed |= _drop_rows(payload, "followup_delivery", + lambda r: r.get("recipient") != recipient) + return changed + + for snapshot in db.scalars(select(FormSnapshot).where( + FormSnapshot.guest_ids.contains([guest_id]))): + _rewrite(snapshot, change) + db.flush() + + +def purge_owner_trash(db: Session, user_id: int) -> None: + """Gelöschte Person: ihre Formulare im Papierkorb entfallen wie ihre übrigen.""" + for form_id in list(db.scalars(select(FormTrash.form_id) + .where(FormTrash.owner_id == user_id))): + purge_form(db, form_id) + + +# -------------------------------------------------------------------------- +# Täglich (Worker) +# -------------------------------------------------------------------------- + + +def daily(db: Session, now: datetime) -> int: + """Stand für jedes Formular, das sich seit dem letzten Stand geändert hat.""" + created = 0 + for form_id in list(db.scalars(select(Form.id).order_by(Form.id))): + if capture(db, form_id, "daily", now=now) is not None: + created += 1 + return created + + +def prune(db: Session, now: datetime) -> int: + """Abgelaufene Stände und Papierkorb-Einträge entfernen.""" + removed = 0 + expired = list(db.scalars(select(FormTrash.form_id).where( + FormTrash.deleted_at < now - timedelta(days=trash_days(db))))) + for form_id in expired: + purge_form(db, form_id) + removed += len(expired) + deleted = db.execute(delete(FormSnapshot).where( + FormSnapshot.created_at < now - timedelta(days=history_days(db)), + FormSnapshot.id.not_in(select(FormTrash.snapshot_id)), + ).returning(FormSnapshot.id)) + removed += len(deleted.all()) + # Stände ohne Formular und ohne Papierkorb-Eintrag + orphans = db.execute(delete(FormSnapshot).where( + FormSnapshot.form_id.not_in(select(Form.id)), + FormSnapshot.form_id.not_in(select(FormTrash.form_id)), + ).returning(FormSnapshot.id)) + removed += len(orphans.all()) + return removed + + +def referenced_media_keys(db: Session) -> set[str]: + """Dateien, auf die ein Stand verweist, bleiben im Volume.""" + return set(db.scalars(select(func.jsonb_array_elements_text(FormSnapshot.media_keys)))) diff --git a/surveybox/forms/retention.py b/surveybox/forms/retention.py index d0b1938..5fffba0 100644 --- a/surveybox/forms/retention.py +++ b/surveybox/forms/retention.py @@ -30,7 +30,7 @@ from sqlalchemy import delete, exists, select, update from sqlalchemy.orm import Session from surveybox.accounts import audit -from surveybox.forms import notes +from surveybox.forms import history, notes from surveybox.models import ( Answer, AppSetting, @@ -204,6 +204,8 @@ def apply(db: Session, form: Form, now: datetime) -> int: else anonymize_responses(db, form, ids, now) ) _clear_form_traces(db, form, mode) + # Frist abgelaufen: auch die Stände im Verlauf enthalten die Antworten + history.purge_form(db, form.id) audit.record(db, "form.retention_applied", target_type="form", target_id=str(form.public_id), details={"mode": mode, "responses": count}) return count diff --git a/surveybox/forms/service.py b/surveybox/forms/service.py index 525eed9..285e238 100644 --- a/surveybox/forms/service.py +++ b/surveybox/forms/service.py @@ -795,6 +795,7 @@ def replace_answers(db: Session, response: Response, validation: Validation) -> db.flush() response.answers.extend(_answers(validation.stored)) response.updated_at = datetime.now(UTC) + response.edited_by = "participant" # Verwalter setzen danach "manager" (Verlauf) def stored_of(answer: Answer) -> Stored: diff --git a/surveybox/locale/de/LC_MESSAGES/messages.po b/surveybox/locale/de/LC_MESSAGES/messages.po index 460de90..66f50a6 100644 --- a/surveybox/locale/de/LC_MESSAGES/messages.po +++ b/surveybox/locale/de/LC_MESSAGES/messages.po @@ -4,7 +4,7 @@ msgid "" msgstr "" "Project-Id-Version: Surveybox VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2026-11-25 16:57+0100\n" +"POT-Creation-Date: 2026-11-26 08:43+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language: de\n" @@ -82,7 +82,7 @@ msgid "Guest" msgstr "Gast" #: surveybox/forms/comments.py surveybox/web/templates/admin_audit.html -#: surveybox/web/templates/response_view.html +#: surveybox/web/templates/form_history.html surveybox/web/templates/response_view.html msgid "Deleted user" msgstr "Gelöschter Benutzer" @@ -124,15 +124,16 @@ msgstr "Ungültige Regel (Frage fehlt oder steht nicht davor)" #: surveybox/forms/conditions.py surveybox/forms/evaluation.py surveybox/forms/export.py #: surveybox/forms/summary.py surveybox/forms/types.py surveybox/web/routes/forms.py -#: surveybox/web/templates/_fill_fields.html surveybox/web/templates/form_responses.html -#: surveybox/web/templates/results_public.html +#: surveybox/web/templates/_fill_fields.html surveybox/web/templates/form_history_compare.html +#: surveybox/web/templates/form_responses.html surveybox/web/templates/results_public.html msgid "Yes" msgstr "Ja" #: surveybox/forms/conditions.py surveybox/forms/evaluation.py surveybox/forms/export.py #: surveybox/forms/summary.py surveybox/forms/types.py surveybox/web/routes/forms.py -#: surveybox/web/templates/_fill_fields.html surveybox/web/templates/form_responses.html -#: surveybox/web/templates/form_settings.html surveybox/web/templates/results_public.html +#: surveybox/web/templates/_fill_fields.html surveybox/web/templates/form_history_compare.html +#: surveybox/web/templates/form_responses.html surveybox/web/templates/form_settings.html +#: surveybox/web/templates/results_public.html msgid "No" msgstr "Nein" @@ -236,7 +237,8 @@ msgid "Page %(page)s of %(pages)s" msgstr "Seite %(page)s von %(pages)s" #: surveybox/forms/export.py surveybox/forms/pdf_export.py surveybox/web/templates/form_designer.html -#: surveybox/web/templates/form_responses.html surveybox/web/templates/forms_list.html +#: surveybox/web/templates/form_history_compare.html surveybox/web/templates/form_responses.html +#: surveybox/web/templates/forms_list.html msgid "Answers" msgstr "Antworten" @@ -850,6 +852,18 @@ msgstr "Das Formular wurde gespeichert." msgid "The form has been deleted." msgstr "Das Formular wurde gelöscht." +#: surveybox/web/templating.py +msgid "The form has been moved to the trash. It can be restored there for a limited time." +msgstr "Das Formular liegt jetzt im Papierkorb. Dort lässt es sich eine Zeit lang wiederherstellen." + +#: surveybox/web/templating.py +msgid "The form has been restored from the trash." +msgstr "Das Formular wurde aus dem Papierkorb wiederhergestellt." + +#: surveybox/web/templating.py +msgid "The selected changes have been restored." +msgstr "Die ausgewählten Änderungen wurden wiederhergestellt." + #: surveybox/web/templating.py msgid "The copy has been created. It is a draft." msgstr "Die Kopie wurde angelegt. Sie ist ein Entwurf." @@ -1106,6 +1120,18 @@ msgstr "Standard-Löschfrist geändert" msgid "Retention period applied to a form" msgstr "Löschfrist auf ein Formular angewendet" +#: surveybox/web/routes/admin.py +msgid "Changes restored from the form history" +msgstr "Änderungen aus dem Verlauf wiederhergestellt" + +#: surveybox/web/routes/admin.py +msgid "Deleted form restored" +msgstr "Gelöschtes Formular wiederhergestellt" + +#: surveybox/web/routes/admin.py +msgid "Form history settings changed" +msgstr "Einstellungen zu Verlauf und Papierkorb geändert" + #: surveybox/web/routes/admin.py msgid "Account deleted" msgstr "Konto gelöscht" @@ -1447,6 +1473,145 @@ msgstr "an den Mailserver übergeben" msgid "sending failed" msgstr "Versand fehlgeschlagen" +#: surveybox/web/routes/form_history.py +msgid "Before a change to questions or settings" +msgstr "Vor einer Änderung an Fragen oder Einstellungen" + +#: surveybox/web/routes/form_history.py +msgid "Before an answer was changed by a manager" +msgstr "Bevor eine Antwort durch Verwaltende geändert wurde" + +#: surveybox/web/routes/form_history.py +msgid "Before an answer was deleted by a manager" +msgstr "Bevor eine Antwort durch Verwaltende gelöscht wurde" + +#: surveybox/web/routes/form_history.py +msgid "Daily" +msgstr "Täglich" + +#: surveybox/web/routes/form_history.py +msgid "Before a restore" +msgstr "Vor einer Wiederherstellung" + +#: surveybox/web/routes/form_history.py +msgid "When the form was deleted" +msgstr "Beim Löschen des Formulars" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +#: surveybox/web/templates/forms_list.html +msgid "Title" +msgstr "Titel" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Description (optional)" +msgstr "Beschreibung (optional)" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Opens at (optional)" +msgstr "Öffnet am (optional)" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Closes at (optional)" +msgstr "Schließt am (optional)" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_access.html +#: surveybox/web/templates/form_designer.html surveybox/web/templates/form_settings.html +msgid "Who may fill in" +msgstr "Wer darf ausfüllen" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Password for access via link" +msgstr "Passwort für den Zugang per Link" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "A person may fill in the form several times" +msgstr "Eine Person darf das Formular mehrfach ausfüllen" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Participants may change their answer" +msgstr "Teilnehmende dürfen ihre Antwort ändern" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Email address of guests" +msgstr "E-Mail-Adresse von Gästen" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Participants see the results" +msgstr "Teilnehmende sehen die Ergebnisse" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Retention period in days after the end of the form" +msgstr "Löschfrist in Tagen nach Ende des Formulars" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "When the retention period ends or a participant is deleted" +msgstr "Wenn die Löschfrist abläuft oder eine Person gelöscht wird" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Privacy notice shown with the form (optional)" +msgstr "Datenschutzhinweis zum Formular (optional)" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Participants must give their consent" +msgstr "Teilnehmende müssen einwilligen" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Consent text" +msgstr "Einwilligungstext" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Show who has signed up" +msgstr "Eingetragene Namen anzeigen" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Places per person across all participation fields (empty: no limit)" +msgstr "Plätze je Person über alle Teilnahme-Felder (leer: unbegrenzt)" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Remind invited people who have not taken part yet … days before the end (empty: no reminder)" +msgstr "Eingeladene ohne Teilnahme … Tage vor dem Ende erinnern (leer: keine Erinnerung)" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Confirmed dates as calendar" +msgstr "Bestätigte Termine als Kalender" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/_comments.html +#: surveybox/web/templates/form_comments.html surveybox/web/templates/form_designer.html +#: surveybox/web/templates/form_settings.html +msgid "Comments" +msgstr "Kommentare" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Publish comments without the author’s name (managers still see it)" +msgstr "Kommentare ohne Namen veröffentlichen (Verwalter sehen ihn weiterhin)" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Reply-to address for messages about this form (optional)" +msgstr "Antwort-an-Adresse für Nachrichten zu diesem Formular (optional)" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Notify managers about new comments by email" +msgstr "Verwalter per E-Mail über neue Kommentare benachrichtigen" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/admin_audit.html +#: surveybox/web/templates/form_settings.html surveybox/web/templates/form_team.html +#: surveybox/web/templates/forms_list.html +msgid "Group" +msgstr "Gruppe" + +#: surveybox/web/routes/form_history.py +msgid "Please choose at least one change to restore." +msgstr "Bitte wählen Sie mindestens eine Änderung zum Wiederherstellen." + +#: surveybox/web/routes/form_history.py surveybox/web/routes/forms.py +msgid "This form can no longer be restored." +msgstr "Dieses Formular lässt sich nicht mehr wiederherstellen." + +#: surveybox/web/routes/form_history.py +#, python-format +msgid "Restored from the form history (state of %(date)s)." +msgstr "Aus dem Verlauf wiederhergestellt (Stand vom %(date)s)." + #: surveybox/web/routes/form_results.py msgid "Please describe why you change this answer." msgstr "Bitte beschreiben Sie, warum Sie diese Antwort ändern." @@ -1744,11 +1909,6 @@ msgstr "Zu dieser Adresse gibt es schon ein Konto. Bitte melden Sie sich an." msgid "Registration is switched off." msgstr "Die Registrierung ist abgeschaltet." -#: surveybox/web/templates/_comments.html surveybox/web/templates/form_comments.html -#: surveybox/web/templates/form_designer.html surveybox/web/templates/form_settings.html -msgid "Comments" -msgstr "Kommentare" - #: surveybox/web/templates/_comments.html msgid "edited" msgstr "bearbeitet" @@ -2363,7 +2523,8 @@ msgstr "Gestaltung" #: surveybox/web/templates/admin_appearance.html surveybox/web/templates/admin_settings.html #: surveybox/web/templates/base.html surveybox/web/templates/form_designer.html -#: surveybox/web/templates/form_responses.html surveybox/web/templates/form_settings.html +#: surveybox/web/templates/form_history_compare.html surveybox/web/templates/form_responses.html +#: surveybox/web/templates/form_settings.html msgid "Settings" msgstr "Einstellungen" @@ -2632,7 +2793,7 @@ msgstr "" msgid "Action" msgstr "Aktion" -#: surveybox/web/templates/admin_audit.html +#: surveybox/web/templates/admin_audit.html surveybox/web/templates/form_history.html msgid "By" msgstr "Durch" @@ -2650,12 +2811,7 @@ msgstr "Gelöschtes Konto Nr. %(n)s" msgid "Guest address no. %(n)s" msgstr "Gast-Adresse Nr. %(n)s" -#: surveybox/web/templates/admin_audit.html surveybox/web/templates/form_settings.html -#: surveybox/web/templates/form_team.html surveybox/web/templates/forms_list.html -msgid "Group" -msgstr "Gruppe" - -#: surveybox/web/templates/admin_audit.html +#: surveybox/web/templates/admin_audit.html surveybox/web/templates/form_history_compare.html msgid "deleted" msgstr "gelöscht" @@ -3197,6 +3353,47 @@ msgstr "" "gelöscht, je nach Einstellung des Formulars. Der Eigentümer erhält 14 Tage vorher einen Hinweis; " "kommt der Hinweis später, vergehen bis zur Löschung mindestens 7 Tage." +#: surveybox/web/templates/admin_settings.html +msgid "Form history and trash" +msgstr "Verlauf und Papierkorb" + +#: surveybox/web/templates/admin_settings.html +#, python-format +msgid "The history can be kept for %(a)d to %(b)d days, the trash for %(c)d to %(d)d days." +msgstr "Der Verlauf lässt sich %(a)d bis %(b)d Tage aufbewahren, der Papierkorb %(c)d bis %(d)d Tage." + +#: surveybox/web/templates/admin_settings.html +msgid "Keep saved states of forms for … days" +msgstr "Gespeicherte Stände von Formularen … Tage aufbewahren" + +#: surveybox/web/templates/admin_settings.html +msgid "" +"States are saved before changes to questions, options, settings and access, before managers " +"change or delete answers, and once a day if a form changed. Managers use them to restore " +"individual questions, options, settings or answers. They contain the answers, so they never " +"outlast them: when a form is deleted or its retention period ends, its states are deleted too." +msgstr "" +"Stände entstehen vor Änderungen an Fragen, Optionen, Einstellungen und Freigaben, bevor " +"Verwaltende Antworten ändern oder löschen, und einmal täglich, wenn sich ein Formular geändert " +"hat. Damit lassen sich einzelne Fragen, Optionen, Einstellungen oder Antworten wiederherstellen. " +"Sie enthalten die Antworten und überdauern sie deshalb nie: Wird ein Formular gelöscht oder endet" +" seine Löschfrist, werden auch seine Stände gelöscht." + +#: surveybox/web/templates/admin_settings.html +msgid "Keep deleted forms in the trash for … days" +msgstr "Gelöschte Formulare … Tage im Papierkorb aufbewahren" + +#: surveybox/web/templates/admin_settings.html +msgid "" +"During this time the owner, the person who deleted it, group administrators and administrators " +"can restore a deleted form with all questions and answers. Afterwards it is deleted for good. If " +"a person is deleted, their answers are also removed from the trash and the history at once." +msgstr "" +"In dieser Zeit können Eigentümer, wer gelöscht hat, Gruppenadministratoren und Administratoren " +"ein gelöschtes Formular mit allen Fragen und Antworten wiederherstellen. Danach ist es endgültig " +"gelöscht. Wird eine Person gelöscht, verschwinden ihre Antworten sofort auch aus Papierkorb und " +"Verlauf." + #: surveybox/web/templates/admin_user_delete.html surveybox/web/templates/admin_user_edit.html msgid "Delete user" msgstr "Benutzer löschen" @@ -4003,11 +4200,6 @@ msgstr "" msgid "Access" msgstr "Zugang" -#: surveybox/web/templates/form_access.html surveybox/web/templates/form_designer.html -#: surveybox/web/templates/form_settings.html -msgid "Who may fill in" -msgstr "Wer darf ausfüllen" - #: surveybox/web/templates/form_access.html msgid "" "Choose groups and individual users. Members of a chosen group always have access, also if they " @@ -4028,10 +4220,14 @@ msgstr "Freigeben" msgid "All forms" msgstr "Alle Formulare" -#: surveybox/web/templates/form_designer.html +#: surveybox/web/templates/form_designer.html surveybox/web/templates/forms_list.html msgid "Template" msgstr "Vorlage" +#: surveybox/web/templates/form_designer.html surveybox/web/templates/form_history.html +msgid "More places are booked than available:" +msgstr "Es sind mehr Plätze belegt als vorhanden:" + #: surveybox/web/templates/form_designer.html surveybox/web/templates/form_preview.html msgid "Live preview" msgstr "Live-Vorschau" @@ -4040,6 +4236,11 @@ msgstr "Live-Vorschau" msgid "Team" msgstr "Team" +#: surveybox/web/templates/form_designer.html surveybox/web/templates/form_history.html +#: surveybox/web/templates/form_history_compare.html +msgid "History" +msgstr "Verlauf" + #: surveybox/web/templates/form_designer.html #, python-format msgid "%(num)d new" @@ -4259,6 +4460,183 @@ msgstr[1] "%(num)d Personen" msgid "No follow-up emails yet." msgstr "Noch keine Folge-Mails." +#: surveybox/web/templates/form_history.html +msgid "Nobody was moved to the waiting list. Raise the number of places or contact the people concerned." +msgstr "" +"Niemand wurde auf die Warteliste verschoben. Erhöhen Sie die Zahl der Plätze oder wenden Sie sich" +" an die Betroffenen." + +#: surveybox/web/templates/form_history.html +msgid "" +"Surveybox saves the state of this form before questions, options, settings or access are changed," +" before a manager changes or deletes an answer, and once a day if anything changed. Choose a " +"state to see what differs from now and to restore individual questions, options, settings or " +"answers. Everything else stays as it is." +msgstr "" +"Surveybox speichert den Stand dieses Formulars, bevor Fragen, Optionen, Einstellungen oder " +"Freigaben geändert werden, bevor Verwaltende eine Antwort ändern oder löschen, und einmal " +"täglich, wenn sich etwas geändert hat. Wählen Sie einen Stand, um zu sehen, was sich seither " +"unterscheidet, und um einzelne Fragen, Optionen, Einstellungen oder Antworten wiederherzustellen." +" Alles andere bleibt, wie es ist." + +#: surveybox/web/templates/form_history.html +#, python-format +msgid "States are kept for %(num)d day, at most as long as the answers themselves." +msgid_plural "States are kept for %(num)d days, at most as long as the answers themselves." +msgstr[0] "Stände werden %(num)d Tag aufbewahrt, höchstens so lange wie die Antworten selbst." +msgstr[1] "Stände werden %(num)d Tage aufbewahrt, höchstens so lange wie die Antworten selbst." + +#: surveybox/web/templates/form_history.html +msgid "" +"Changes and deletions by participants themselves are not restored; what participants delete also " +"disappears from the history." +msgstr "" +"Änderungen und Löschungen durch Teilnehmende selbst werden nicht zurückgenommen; was Teilnehmende" +" löschen, verschwindet auch aus dem Verlauf." + +#: surveybox/web/templates/form_history.html +msgid "Saved" +msgstr "Gespeichert" + +#: surveybox/web/templates/form_history.html +msgid "Occasion" +msgstr "Anlass" + +#: surveybox/web/templates/form_history.html +msgid "Compare" +msgstr "Vergleichen" + +#: surveybox/web/templates/form_history.html +msgid "No states yet. The first one is saved with the next change." +msgstr "Noch keine Stände. Der erste entsteht mit der nächsten Änderung." + +#: surveybox/web/templates/form_history_compare.html +msgid "empty" +msgstr "leer" + +#: surveybox/web/templates/form_history_compare.html +#, python-format +msgid "State of %(date)s" +msgstr "Stand vom %(date)s" + +#: surveybox/web/templates/form_history_compare.html +msgid "Nothing in this state differs from the form as it is now in a way that can be restored." +msgstr "In diesem Stand unterscheidet sich nichts vom heutigen Formular, das sich wiederherstellen ließe." + +#: surveybox/web/templates/form_history_compare.html +msgid "" +"Choose what to restore. Only the chosen items change; questions, answers and settings that are " +"not chosen stay as they are now." +msgstr "" +"Wählen Sie, was wiederhergestellt werden soll. Nur das Ausgewählte ändert sich; nicht ausgewählte" +" Fragen, Antworten und Einstellungen bleiben, wie sie jetzt sind." + +#: surveybox/web/templates/form_history_compare.html +msgid "Access for people and groups" +msgstr "Freigabe für Personen und Gruppen" + +#: surveybox/web/templates/form_history_compare.html +#, python-format +msgid "Then: %(old)d entries, now: %(new)d entries" +msgstr "Damals: %(old)d Einträge, jetzt: %(new)d Einträge" + +#: surveybox/web/templates/form_history_compare.html +msgid "Then" +msgstr "Damals" + +#: surveybox/web/templates/form_history_compare.html +msgid "Now" +msgstr "Jetzt" + +#: surveybox/web/templates/form_history_compare.html +msgid "changed" +msgstr "geändert" + +#: surveybox/web/templates/form_history_compare.html +msgid "Questions and options" +msgstr "Fragen und Optionen" + +#: surveybox/web/templates/form_history_compare.html +#, python-format +msgid "With %(num)d answer" +msgid_plural "With %(num)d answers" +msgstr[0] "Mit %(num)d Antwort" +msgstr[1] "Mit %(num)d Antworten" + +#: surveybox/web/templates/form_history_compare.html +#, python-format +msgid "%(num)d booked place" +msgid_plural "%(num)d booked places" +msgstr[0] "%(num)d gebuchter Platz" +msgstr[1] "%(num)d gebuchte Plätze" + +#: surveybox/web/templates/form_history_compare.html +msgid "" +"Text, settings and options as they were then. Options added since are kept; removed options are " +"listed separately." +msgstr "" +"Text, Einstellungen und Optionen wie damals. Seither hinzugekommene Optionen bleiben; gestrichene" +" Optionen stehen einzeln in der Liste." + +#: surveybox/web/templates/form_history_compare.html +msgid "option removed" +msgstr "Option gestrichen" + +#: surveybox/web/templates/form_history_compare.html +#, python-format +msgid "Question: %(question)s" +msgstr "Frage: %(question)s" + +#: surveybox/web/templates/form_history_compare.html +msgid "Answer without name" +msgstr "Antwort ohne Namen" + +#: surveybox/web/templates/form_history_compare.html +msgid "deleted by a manager" +msgstr "von Verwaltenden gelöscht" + +#: surveybox/web/templates/form_history_compare.html +#, python-format +msgid "Submitted %(date)s" +msgstr "Abgegeben %(date)s" + +#: surveybox/web/templates/form_history_compare.html +#, python-format +msgid "%(num)d answered question" +msgid_plural "%(num)d answered questions" +msgstr[0] "%(num)d beantwortete Frage" +msgstr[1] "%(num)d beantwortete Fragen" + +#: surveybox/web/templates/form_history_compare.html +msgid "changed by a manager" +msgstr "von Verwaltenden geändert" + +#: surveybox/web/templates/form_history_compare.html +#, python-format +msgid "Changed %(date)s" +msgstr "Geändert %(date)s" + +#: surveybox/web/templates/form_history_compare.html +#, python-format +msgid "%(num)d question differs" +msgid_plural "%(num)d questions differ" +msgstr[0] "%(num)d Frage weicht ab" +msgstr[1] "%(num)d Fragen weichen ab" + +#: surveybox/web/templates/form_history_compare.html +msgid "" +"Before restoring, the current state is saved too, so this step can be undone in the history. " +"Booked places are restored even if there are not enough places any more; the option is then shown" +" as overbooked." +msgstr "" +"Vor dem Wiederherstellen wird auch der jetzige Stand gespeichert; so lässt sich dieser Schritt im" +" Verlauf zurücknehmen. Gebuchte Plätze kommen auch dann zurück, wenn die Plätze nicht mehr " +"reichen; die Option wird dann als überbucht angezeigt." + +#: surveybox/web/templates/form_history_compare.html +msgid "Restore selected" +msgstr "Ausgewähltes wiederherstellen" + #: surveybox/web/templates/form_preview.html msgid "Phone" msgstr "Handy" @@ -4417,6 +4795,10 @@ msgstr "Eintrag" msgid "Signed up" msgstr "Eingetragen" +#: surveybox/web/templates/form_responses.html +msgid "overbooked" +msgstr "überbucht" + #: surveybox/web/templates/form_responses.html surveybox/web/templates/results_public.html #, python-format msgid "%(num)d waiting" @@ -4507,22 +4889,6 @@ msgstr "" msgid "General" msgstr "Allgemein" -#: surveybox/web/templates/form_settings.html surveybox/web/templates/forms_list.html -msgid "Title" -msgstr "Titel" - -#: surveybox/web/templates/form_settings.html -msgid "Description (optional)" -msgstr "Beschreibung (optional)" - -#: surveybox/web/templates/form_settings.html -msgid "Opens at (optional)" -msgstr "Öffnet am (optional)" - -#: surveybox/web/templates/form_settings.html -msgid "Closes at (optional)" -msgstr "Schließt am (optional)" - #: surveybox/web/templates/form_settings.html surveybox/web/templates/forms_list.html msgid "no group (instance-wide)" msgstr "keine Gruppe (instanzweit)" @@ -4531,10 +4897,6 @@ msgstr "keine Gruppe (instanzweit)" msgid "Group administrators of this group and the groups above manage the form too." msgstr "Gruppenadministratoren dieser und der darüberliegenden Gruppen verwalten die Umfrage mit." -#: surveybox/web/templates/form_settings.html -msgid "Password for access via link" -msgstr "Passwort für den Zugang per Link" - #: surveybox/web/templates/form_settings.html msgid "A password is set. Leave empty to keep it." msgstr "Ein Passwort ist gesetzt. Leer lassen, um es zu behalten." @@ -4551,18 +4913,10 @@ msgstr "Bei „ausgewählte Benutzer und Gruppen“ wählen Sie diese auf der n msgid "Participation" msgstr "Teilnahme" -#: surveybox/web/templates/form_settings.html -msgid "A person may fill in the form several times" -msgstr "Eine Person darf das Formular mehrfach ausfüllen" - #: surveybox/web/templates/form_settings.html msgid "Anonymous: answers are stored without reference to the person" msgstr "Anonym: Antworten werden ohne Personenbezug gespeichert" -#: surveybox/web/templates/form_settings.html -msgid "Participants may change their answer" -msgstr "Teilnehmende dürfen ihre Antwort ändern" - #: surveybox/web/templates/form_settings.html msgid "Yes, until the form closes" msgstr "Ja, bis das Formular schließt" @@ -4573,10 +4927,6 @@ msgstr "" "Für angemeldete Teilnehmende und für Gäste mit ihrem persönlichen Link; nicht bei anonymen " "Formularen." -#: surveybox/web/templates/form_settings.html -msgid "Remind invited people who have not taken part yet … days before the end (empty: no reminder)" -msgstr "Eingeladene ohne Teilnahme … Tage vor dem Ende erinnern (leer: keine Erinnerung)" - #: surveybox/web/templates/form_settings.html msgid "" "Only for access “Selected users and groups” and with an end date. Each person gets the reminder " @@ -4585,10 +4935,6 @@ msgstr "" "Nur bei Zugriff „Ausgewählte Benutzer und Gruppen“ und mit Enddatum. Jede Person erhält die " "Erinnerung einmal per E-Mail; abschalten kann sie das in ihrem Konto." -#: surveybox/web/templates/form_settings.html -msgid "Participants see the results" -msgstr "Teilnehmende sehen die Ergebnisse" - #: surveybox/web/templates/form_settings.html msgid "Never" msgstr "Nie" @@ -4618,14 +4964,6 @@ msgstr "" msgid "Places, calendar and comments" msgstr "Plätze, Kalender und Kommentare" -#: surveybox/web/templates/form_settings.html -msgid "Places per person across all participation fields (empty: no limit)" -msgstr "Plätze je Person über alle Teilnahme-Felder (leer: unbegrenzt)" - -#: surveybox/web/templates/form_settings.html -msgid "Show who has signed up" -msgstr "Eingetragene Namen anzeigen" - #: surveybox/web/templates/form_settings.html msgid "Yes, first name and initial of the last name" msgstr "Ja, Vorname und Anfangsbuchstabe des Nachnamens" @@ -4645,10 +4983,6 @@ msgstr "" "Adressen werden nie angezeigt. Das Formular weist die Teilnehmenden darauf hin. Nicht bei " "anonymen Formularen." -#: surveybox/web/templates/form_settings.html -msgid "Confirmed dates as calendar" -msgstr "Bestätigte Termine als Kalender" - #: surveybox/web/templates/form_settings.html msgid "Off" msgstr "Aus" @@ -4677,18 +5011,6 @@ msgstr "Moderiert: neue Kommentare sind nach Freigabe sichtbar" msgid "Public: new comments are visible at once" msgstr "Öffentlich: neue Kommentare sind sofort sichtbar" -#: surveybox/web/templates/form_settings.html -msgid "Publish comments without the author’s name (managers still see it)" -msgstr "Kommentare ohne Namen veröffentlichen (Verwalter sehen ihn weiterhin)" - -#: surveybox/web/templates/form_settings.html -msgid "Notify managers about new comments by email" -msgstr "Verwalter per E-Mail über neue Kommentare benachrichtigen" - -#: surveybox/web/templates/form_settings.html -msgid "Reply-to address for messages about this form (optional)" -msgstr "Antwort-an-Adresse für Nachrichten zu diesem Formular (optional)" - #: surveybox/web/templates/form_settings.html msgid "" "Replies to messages about this form go to this address. Empty: the address from the email " @@ -4701,22 +5023,6 @@ msgstr "" msgid "Data protection" msgstr "Datenschutz" -#: surveybox/web/templates/form_settings.html -msgid "Privacy notice shown with the form (optional)" -msgstr "Datenschutzhinweis zum Formular (optional)" - -#: surveybox/web/templates/form_settings.html -msgid "Participants must give their consent" -msgstr "Teilnehmende müssen einwilligen" - -#: surveybox/web/templates/form_settings.html -msgid "Consent text" -msgstr "Einwilligungstext" - -#: surveybox/web/templates/form_settings.html -msgid "Retention period in days after the end of the form" -msgstr "Löschfrist in Tagen nach Ende des Formulars" - #: surveybox/web/templates/form_settings.html #, python-format msgid "" @@ -4736,10 +5042,6 @@ msgstr "Die Antworten werden am %(date)s gelöscht." msgid "The answers will be anonymized on %(date)s." msgstr "Die Antworten werden am %(date)s anonymisiert." -#: surveybox/web/templates/form_settings.html -msgid "When the retention period ends or a participant is deleted" -msgstr "Wenn die Löschfrist abläuft oder eine Person gelöscht wird" - #: surveybox/web/templates/form_settings.html msgid "Keep the answer anonymized" msgstr "Antwort anonymisiert behalten" @@ -4748,10 +5050,6 @@ msgstr "Antwort anonymisiert behalten" msgid "Delete the answer completely" msgstr "Antwort vollständig löschen" -#: surveybox/web/templates/form_settings.html -msgid "Email address of guests" -msgstr "E-Mail-Adresse von Gästen" - #: surveybox/web/templates/form_settings.html surveybox/web/templates/question_edit.html msgid "Do not ask" msgstr "Nicht abfragen" @@ -4813,6 +5111,21 @@ msgstr "Link erneuern" msgid "Delete form" msgstr "Formular löschen" +#: surveybox/web/templates/form_settings.html +#, python-format +msgid "" +"The form goes to the trash in the form list. There you can restore it for %(num)d day; after that" +" it is deleted for good." +msgid_plural "" +"The form goes to the trash in the form list. There you can restore it for %(num)d days; after " +"that it is deleted for good." +msgstr[0] "" +"Das Formular kommt in den Papierkorb in der Formularliste. Dort lässt es sich %(num)d Tag lang " +"wiederherstellen; danach ist es endgültig gelöscht." +msgstr[1] "" +"Das Formular kommt in den Papierkorb in der Formularliste. Dort lässt es sich %(num)d Tage lang " +"wiederherstellen; danach ist es endgültig gelöscht." + #: surveybox/web/templates/form_settings.html msgid "Yes, delete this form with all questions and answers." msgstr "Ja, dieses Formular mit allen Fragen und Antworten löschen." @@ -4853,6 +5166,30 @@ msgstr "Mitbearbeitung" msgid "No forms yet." msgstr "Noch keine Formulare." +#: surveybox/web/templates/forms_list.html +msgid "Trash" +msgstr "Papierkorb" + +#: surveybox/web/templates/forms_list.html +msgid "" +"Deleted forms can be restored with all questions and answers until the date shown. After that " +"they are deleted for good." +msgstr "" +"Gelöschte Formulare lassen sich bis zum angegebenen Datum mit allen Fragen und Antworten " +"wiederherstellen. Danach sind sie endgültig gelöscht." + +#: surveybox/web/templates/forms_list.html +msgid "Deleted" +msgstr "Gelöscht" + +#: surveybox/web/templates/forms_list.html +msgid "Restorable until" +msgstr "Wiederherstellbar bis" + +#: surveybox/web/templates/forms_list.html +msgid "Restore" +msgstr "Wiederherstellen" + #: surveybox/web/templates/forms_list.html msgid "Templates" msgstr "Vorlagen" diff --git a/surveybox/locale/en/LC_MESSAGES/messages.po b/surveybox/locale/en/LC_MESSAGES/messages.po index efee56e..4735927 100644 --- a/surveybox/locale/en/LC_MESSAGES/messages.po +++ b/surveybox/locale/en/LC_MESSAGES/messages.po @@ -4,7 +4,7 @@ msgid "" msgstr "" "Project-Id-Version: Surveybox VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2026-11-25 16:57+0100\n" +"POT-Creation-Date: 2026-11-26 08:43+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language: en\n" @@ -82,7 +82,7 @@ msgid "Guest" msgstr "Guest" #: surveybox/forms/comments.py surveybox/web/templates/admin_audit.html -#: surveybox/web/templates/response_view.html +#: surveybox/web/templates/form_history.html surveybox/web/templates/response_view.html msgid "Deleted user" msgstr "Deleted user" @@ -124,15 +124,16 @@ msgstr "Invalid rule (question missing or not earlier)" #: surveybox/forms/conditions.py surveybox/forms/evaluation.py surveybox/forms/export.py #: surveybox/forms/summary.py surveybox/forms/types.py surveybox/web/routes/forms.py -#: surveybox/web/templates/_fill_fields.html surveybox/web/templates/form_responses.html -#: surveybox/web/templates/results_public.html +#: surveybox/web/templates/_fill_fields.html surveybox/web/templates/form_history_compare.html +#: surveybox/web/templates/form_responses.html surveybox/web/templates/results_public.html msgid "Yes" msgstr "Yes" #: surveybox/forms/conditions.py surveybox/forms/evaluation.py surveybox/forms/export.py #: surveybox/forms/summary.py surveybox/forms/types.py surveybox/web/routes/forms.py -#: surveybox/web/templates/_fill_fields.html surveybox/web/templates/form_responses.html -#: surveybox/web/templates/form_settings.html surveybox/web/templates/results_public.html +#: surveybox/web/templates/_fill_fields.html surveybox/web/templates/form_history_compare.html +#: surveybox/web/templates/form_responses.html surveybox/web/templates/form_settings.html +#: surveybox/web/templates/results_public.html msgid "No" msgstr "No" @@ -236,7 +237,8 @@ msgid "Page %(page)s of %(pages)s" msgstr "Page %(page)s of %(pages)s" #: surveybox/forms/export.py surveybox/forms/pdf_export.py surveybox/web/templates/form_designer.html -#: surveybox/web/templates/form_responses.html surveybox/web/templates/forms_list.html +#: surveybox/web/templates/form_history_compare.html surveybox/web/templates/form_responses.html +#: surveybox/web/templates/forms_list.html msgid "Answers" msgstr "Answers" @@ -850,6 +852,18 @@ msgstr "The form has been saved." msgid "The form has been deleted." msgstr "The form has been deleted." +#: surveybox/web/templating.py +msgid "The form has been moved to the trash. It can be restored there for a limited time." +msgstr "The form has been moved to the trash. It can be restored there for a limited time." + +#: surveybox/web/templating.py +msgid "The form has been restored from the trash." +msgstr "The form has been restored from the trash." + +#: surveybox/web/templating.py +msgid "The selected changes have been restored." +msgstr "The selected changes have been restored." + #: surveybox/web/templating.py msgid "The copy has been created. It is a draft." msgstr "The copy has been created. It is a draft." @@ -1104,6 +1118,18 @@ msgstr "Default retention period changed" msgid "Retention period applied to a form" msgstr "Retention period applied to a form" +#: surveybox/web/routes/admin.py +msgid "Changes restored from the form history" +msgstr "Changes restored from the form history" + +#: surveybox/web/routes/admin.py +msgid "Deleted form restored" +msgstr "Deleted form restored" + +#: surveybox/web/routes/admin.py +msgid "Form history settings changed" +msgstr "Form history settings changed" + #: surveybox/web/routes/admin.py msgid "Account deleted" msgstr "Account deleted" @@ -1445,6 +1471,145 @@ msgstr "handed to the mail server" msgid "sending failed" msgstr "sending failed" +#: surveybox/web/routes/form_history.py +msgid "Before a change to questions or settings" +msgstr "Before a change to questions or settings" + +#: surveybox/web/routes/form_history.py +msgid "Before an answer was changed by a manager" +msgstr "Before an answer was changed by a manager" + +#: surveybox/web/routes/form_history.py +msgid "Before an answer was deleted by a manager" +msgstr "Before an answer was deleted by a manager" + +#: surveybox/web/routes/form_history.py +msgid "Daily" +msgstr "Daily" + +#: surveybox/web/routes/form_history.py +msgid "Before a restore" +msgstr "Before a restore" + +#: surveybox/web/routes/form_history.py +msgid "When the form was deleted" +msgstr "When the form was deleted" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +#: surveybox/web/templates/forms_list.html +msgid "Title" +msgstr "Title" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Description (optional)" +msgstr "Description (optional)" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Opens at (optional)" +msgstr "Opens at (optional)" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Closes at (optional)" +msgstr "Closes at (optional)" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_access.html +#: surveybox/web/templates/form_designer.html surveybox/web/templates/form_settings.html +msgid "Who may fill in" +msgstr "Who may fill in" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Password for access via link" +msgstr "Password for access via link" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "A person may fill in the form several times" +msgstr "A person may fill in the form several times" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Participants may change their answer" +msgstr "Participants may change their answer" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Email address of guests" +msgstr "Email address of guests" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Participants see the results" +msgstr "Participants see the results" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Retention period in days after the end of the form" +msgstr "Retention period in days after the end of the form" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "When the retention period ends or a participant is deleted" +msgstr "When the retention period ends or a participant is deleted" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Privacy notice shown with the form (optional)" +msgstr "Privacy notice shown with the form (optional)" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Participants must give their consent" +msgstr "Participants must give their consent" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Consent text" +msgstr "Consent text" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Show who has signed up" +msgstr "Show who has signed up" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Places per person across all participation fields (empty: no limit)" +msgstr "Places per person across all participation fields (empty: no limit)" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Remind invited people who have not taken part yet … days before the end (empty: no reminder)" +msgstr "Remind invited people who have not taken part yet … days before the end (empty: no reminder)" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Confirmed dates as calendar" +msgstr "Confirmed dates as calendar" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/_comments.html +#: surveybox/web/templates/form_comments.html surveybox/web/templates/form_designer.html +#: surveybox/web/templates/form_settings.html +msgid "Comments" +msgstr "Comments" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Publish comments without the author’s name (managers still see it)" +msgstr "Publish comments without the author’s name (managers still see it)" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Reply-to address for messages about this form (optional)" +msgstr "Reply-to address for messages about this form (optional)" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Notify managers about new comments by email" +msgstr "Notify managers about new comments by email" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/admin_audit.html +#: surveybox/web/templates/form_settings.html surveybox/web/templates/form_team.html +#: surveybox/web/templates/forms_list.html +msgid "Group" +msgstr "Group" + +#: surveybox/web/routes/form_history.py +msgid "Please choose at least one change to restore." +msgstr "Please choose at least one change to restore." + +#: surveybox/web/routes/form_history.py surveybox/web/routes/forms.py +msgid "This form can no longer be restored." +msgstr "This form can no longer be restored." + +#: surveybox/web/routes/form_history.py +#, python-format +msgid "Restored from the form history (state of %(date)s)." +msgstr "Restored from the form history (state of %(date)s)." + #: surveybox/web/routes/form_results.py msgid "Please describe why you change this answer." msgstr "Please describe why you change this answer." @@ -1738,11 +1903,6 @@ msgstr "There already is an account with this address. Please sign in." msgid "Registration is switched off." msgstr "Registration is switched off." -#: surveybox/web/templates/_comments.html surveybox/web/templates/form_comments.html -#: surveybox/web/templates/form_designer.html surveybox/web/templates/form_settings.html -msgid "Comments" -msgstr "Comments" - #: surveybox/web/templates/_comments.html msgid "edited" msgstr "edited" @@ -2354,7 +2514,8 @@ msgstr "Design" #: surveybox/web/templates/admin_appearance.html surveybox/web/templates/admin_settings.html #: surveybox/web/templates/base.html surveybox/web/templates/form_designer.html -#: surveybox/web/templates/form_responses.html surveybox/web/templates/form_settings.html +#: surveybox/web/templates/form_history_compare.html surveybox/web/templates/form_responses.html +#: surveybox/web/templates/form_settings.html msgid "Settings" msgstr "Settings" @@ -2616,7 +2777,7 @@ msgstr "Sign-ins and administrative actions. Contains no form content, email add msgid "Action" msgstr "Action" -#: surveybox/web/templates/admin_audit.html +#: surveybox/web/templates/admin_audit.html surveybox/web/templates/form_history.html msgid "By" msgstr "By" @@ -2634,12 +2795,7 @@ msgstr "Deleted account no. %(n)s" msgid "Guest address no. %(n)s" msgstr "Guest address no. %(n)s" -#: surveybox/web/templates/admin_audit.html surveybox/web/templates/form_settings.html -#: surveybox/web/templates/form_team.html surveybox/web/templates/forms_list.html -msgid "Group" -msgstr "Group" - -#: surveybox/web/templates/admin_audit.html +#: surveybox/web/templates/admin_audit.html surveybox/web/templates/form_history_compare.html msgid "deleted" msgstr "deleted" @@ -3177,6 +3333,45 @@ msgstr "" "as set in the form. The owner is notified 14 days before; if the notice comes later, at least 7 " "days pass before anything is deleted." +#: surveybox/web/templates/admin_settings.html +msgid "Form history and trash" +msgstr "Form history and trash" + +#: surveybox/web/templates/admin_settings.html +#, python-format +msgid "The history can be kept for %(a)d to %(b)d days, the trash for %(c)d to %(d)d days." +msgstr "The history can be kept for %(a)d to %(b)d days, the trash for %(c)d to %(d)d days." + +#: surveybox/web/templates/admin_settings.html +msgid "Keep saved states of forms for … days" +msgstr "Keep saved states of forms for … days" + +#: surveybox/web/templates/admin_settings.html +msgid "" +"States are saved before changes to questions, options, settings and access, before managers " +"change or delete answers, and once a day if a form changed. Managers use them to restore " +"individual questions, options, settings or answers. They contain the answers, so they never " +"outlast them: when a form is deleted or its retention period ends, its states are deleted too." +msgstr "" +"States are saved before changes to questions, options, settings and access, before managers " +"change or delete answers, and once a day if a form changed. Managers use them to restore " +"individual questions, options, settings or answers. They contain the answers, so they never " +"outlast them: when a form is deleted or its retention period ends, its states are deleted too." + +#: surveybox/web/templates/admin_settings.html +msgid "Keep deleted forms in the trash for … days" +msgstr "Keep deleted forms in the trash for … days" + +#: surveybox/web/templates/admin_settings.html +msgid "" +"During this time the owner, the person who deleted it, group administrators and administrators " +"can restore a deleted form with all questions and answers. Afterwards it is deleted for good. If " +"a person is deleted, their answers are also removed from the trash and the history at once." +msgstr "" +"During this time the owner, the person who deleted it, group administrators and administrators " +"can restore a deleted form with all questions and answers. Afterwards it is deleted for good. If " +"a person is deleted, their answers are also removed from the trash and the history at once." + #: surveybox/web/templates/admin_user_delete.html surveybox/web/templates/admin_user_edit.html msgid "Delete user" msgstr "Delete user" @@ -3973,11 +4168,6 @@ msgstr "" msgid "Access" msgstr "Access" -#: surveybox/web/templates/form_access.html surveybox/web/templates/form_designer.html -#: surveybox/web/templates/form_settings.html -msgid "Who may fill in" -msgstr "Who may fill in" - #: surveybox/web/templates/form_access.html msgid "" "Choose groups and individual users. Members of a chosen group always have access, also if they " @@ -3998,10 +4188,14 @@ msgstr "Approve" msgid "All forms" msgstr "All forms" -#: surveybox/web/templates/form_designer.html +#: surveybox/web/templates/form_designer.html surveybox/web/templates/forms_list.html msgid "Template" msgstr "Template" +#: surveybox/web/templates/form_designer.html surveybox/web/templates/form_history.html +msgid "More places are booked than available:" +msgstr "More places are booked than available:" + #: surveybox/web/templates/form_designer.html surveybox/web/templates/form_preview.html msgid "Live preview" msgstr "Live preview" @@ -4010,6 +4204,11 @@ msgstr "Live preview" msgid "Team" msgstr "Team" +#: surveybox/web/templates/form_designer.html surveybox/web/templates/form_history.html +#: surveybox/web/templates/form_history_compare.html +msgid "History" +msgstr "History" + #: surveybox/web/templates/form_designer.html #, python-format msgid "%(num)d new" @@ -4229,6 +4428,180 @@ msgstr[1] "%(num)d people" msgid "No follow-up emails yet." msgstr "No follow-up emails yet." +#: surveybox/web/templates/form_history.html +msgid "Nobody was moved to the waiting list. Raise the number of places or contact the people concerned." +msgstr "Nobody was moved to the waiting list. Raise the number of places or contact the people concerned." + +#: surveybox/web/templates/form_history.html +msgid "" +"Surveybox saves the state of this form before questions, options, settings or access are changed," +" before a manager changes or deletes an answer, and once a day if anything changed. Choose a " +"state to see what differs from now and to restore individual questions, options, settings or " +"answers. Everything else stays as it is." +msgstr "" +"Surveybox saves the state of this form before questions, options, settings or access are changed," +" before a manager changes or deletes an answer, and once a day if anything changed. Choose a " +"state to see what differs from now and to restore individual questions, options, settings or " +"answers. Everything else stays as it is." + +#: surveybox/web/templates/form_history.html +#, python-format +msgid "States are kept for %(num)d day, at most as long as the answers themselves." +msgid_plural "States are kept for %(num)d days, at most as long as the answers themselves." +msgstr[0] "States are kept for %(num)d day, at most as long as the answers themselves." +msgstr[1] "States are kept for %(num)d days, at most as long as the answers themselves." + +#: surveybox/web/templates/form_history.html +msgid "" +"Changes and deletions by participants themselves are not restored; what participants delete also " +"disappears from the history." +msgstr "" +"Changes and deletions by participants themselves are not restored; what participants delete also " +"disappears from the history." + +#: surveybox/web/templates/form_history.html +msgid "Saved" +msgstr "Saved" + +#: surveybox/web/templates/form_history.html +msgid "Occasion" +msgstr "Occasion" + +#: surveybox/web/templates/form_history.html +msgid "Compare" +msgstr "Compare" + +#: surveybox/web/templates/form_history.html +msgid "No states yet. The first one is saved with the next change." +msgstr "No states yet. The first one is saved with the next change." + +#: surveybox/web/templates/form_history_compare.html +msgid "empty" +msgstr "empty" + +#: surveybox/web/templates/form_history_compare.html +#, python-format +msgid "State of %(date)s" +msgstr "State of %(date)s" + +#: surveybox/web/templates/form_history_compare.html +msgid "Nothing in this state differs from the form as it is now in a way that can be restored." +msgstr "Nothing in this state differs from the form as it is now in a way that can be restored." + +#: surveybox/web/templates/form_history_compare.html +msgid "" +"Choose what to restore. Only the chosen items change; questions, answers and settings that are " +"not chosen stay as they are now." +msgstr "" +"Choose what to restore. Only the chosen items change; questions, answers and settings that are " +"not chosen stay as they are now." + +#: surveybox/web/templates/form_history_compare.html +msgid "Access for people and groups" +msgstr "Access for people and groups" + +#: surveybox/web/templates/form_history_compare.html +#, python-format +msgid "Then: %(old)d entries, now: %(new)d entries" +msgstr "Then: %(old)d entries, now: %(new)d entries" + +#: surveybox/web/templates/form_history_compare.html +msgid "Then" +msgstr "Then" + +#: surveybox/web/templates/form_history_compare.html +msgid "Now" +msgstr "Now" + +#: surveybox/web/templates/form_history_compare.html +msgid "changed" +msgstr "changed" + +#: surveybox/web/templates/form_history_compare.html +msgid "Questions and options" +msgstr "Questions and options" + +#: surveybox/web/templates/form_history_compare.html +#, python-format +msgid "With %(num)d answer" +msgid_plural "With %(num)d answers" +msgstr[0] "With %(num)d answer" +msgstr[1] "With %(num)d answers" + +#: surveybox/web/templates/form_history_compare.html +#, python-format +msgid "%(num)d booked place" +msgid_plural "%(num)d booked places" +msgstr[0] "%(num)d booked place" +msgstr[1] "%(num)d booked places" + +#: surveybox/web/templates/form_history_compare.html +msgid "" +"Text, settings and options as they were then. Options added since are kept; removed options are " +"listed separately." +msgstr "" +"Text, settings and options as they were then. Options added since are kept; removed options are " +"listed separately." + +#: surveybox/web/templates/form_history_compare.html +msgid "option removed" +msgstr "option removed" + +#: surveybox/web/templates/form_history_compare.html +#, python-format +msgid "Question: %(question)s" +msgstr "Question: %(question)s" + +#: surveybox/web/templates/form_history_compare.html +msgid "Answer without name" +msgstr "Answer without name" + +#: surveybox/web/templates/form_history_compare.html +msgid "deleted by a manager" +msgstr "deleted by a manager" + +#: surveybox/web/templates/form_history_compare.html +#, python-format +msgid "Submitted %(date)s" +msgstr "Submitted %(date)s" + +#: surveybox/web/templates/form_history_compare.html +#, python-format +msgid "%(num)d answered question" +msgid_plural "%(num)d answered questions" +msgstr[0] "%(num)d answered question" +msgstr[1] "%(num)d answered questions" + +#: surveybox/web/templates/form_history_compare.html +msgid "changed by a manager" +msgstr "changed by a manager" + +#: surveybox/web/templates/form_history_compare.html +#, python-format +msgid "Changed %(date)s" +msgstr "Changed %(date)s" + +#: surveybox/web/templates/form_history_compare.html +#, python-format +msgid "%(num)d question differs" +msgid_plural "%(num)d questions differ" +msgstr[0] "%(num)d question differs" +msgstr[1] "%(num)d questions differ" + +#: surveybox/web/templates/form_history_compare.html +msgid "" +"Before restoring, the current state is saved too, so this step can be undone in the history. " +"Booked places are restored even if there are not enough places any more; the option is then shown" +" as overbooked." +msgstr "" +"Before restoring, the current state is saved too, so this step can be undone in the history. " +"Booked places are restored even if there are not enough places any more; the option is then shown" +" as overbooked." + +#: surveybox/web/templates/form_history_compare.html +msgid "Restore selected" +msgstr "Restore selected" + #: surveybox/web/templates/form_preview.html msgid "Phone" msgstr "Phone" @@ -4384,6 +4757,10 @@ msgstr "Entry" msgid "Signed up" msgstr "Signed up" +#: surveybox/web/templates/form_responses.html +msgid "overbooked" +msgstr "overbooked" + #: surveybox/web/templates/form_responses.html surveybox/web/templates/results_public.html #, python-format msgid "%(num)d waiting" @@ -4474,22 +4851,6 @@ msgstr "" msgid "General" msgstr "General" -#: surveybox/web/templates/form_settings.html surveybox/web/templates/forms_list.html -msgid "Title" -msgstr "Title" - -#: surveybox/web/templates/form_settings.html -msgid "Description (optional)" -msgstr "Description (optional)" - -#: surveybox/web/templates/form_settings.html -msgid "Opens at (optional)" -msgstr "Opens at (optional)" - -#: surveybox/web/templates/form_settings.html -msgid "Closes at (optional)" -msgstr "Closes at (optional)" - #: surveybox/web/templates/form_settings.html surveybox/web/templates/forms_list.html msgid "no group (instance-wide)" msgstr "no group (instance-wide)" @@ -4498,10 +4859,6 @@ msgstr "no group (instance-wide)" msgid "Group administrators of this group and the groups above manage the form too." msgstr "Group administrators of this group and the groups above manage the form too." -#: surveybox/web/templates/form_settings.html -msgid "Password for access via link" -msgstr "Password for access via link" - #: surveybox/web/templates/form_settings.html msgid "A password is set. Leave empty to keep it." msgstr "A password is set. Leave empty to keep it." @@ -4518,18 +4875,10 @@ msgstr "For “selected users and groups” you choose them on the next page." msgid "Participation" msgstr "Participation" -#: surveybox/web/templates/form_settings.html -msgid "A person may fill in the form several times" -msgstr "A person may fill in the form several times" - #: surveybox/web/templates/form_settings.html msgid "Anonymous: answers are stored without reference to the person" msgstr "Anonymous: answers are stored without reference to the person" -#: surveybox/web/templates/form_settings.html -msgid "Participants may change their answer" -msgstr "Participants may change their answer" - #: surveybox/web/templates/form_settings.html msgid "Yes, until the form closes" msgstr "Yes, until the form closes" @@ -4538,10 +4887,6 @@ msgstr "Yes, until the form closes" msgid "For signed-in participants and for guests with their personal link; not for anonymous forms." msgstr "For signed-in participants and for guests with their personal link; not for anonymous forms." -#: surveybox/web/templates/form_settings.html -msgid "Remind invited people who have not taken part yet … days before the end (empty: no reminder)" -msgstr "Remind invited people who have not taken part yet … days before the end (empty: no reminder)" - #: surveybox/web/templates/form_settings.html msgid "" "Only for access “Selected users and groups” and with an end date. Each person gets the reminder " @@ -4550,10 +4895,6 @@ msgstr "" "Only for access “Selected users and groups” and with an end date. Each person gets the reminder " "once, by email; they can switch reminders off in their account." -#: surveybox/web/templates/form_settings.html -msgid "Participants see the results" -msgstr "Participants see the results" - #: surveybox/web/templates/form_settings.html msgid "Never" msgstr "Never" @@ -4582,14 +4923,6 @@ msgstr "" msgid "Places, calendar and comments" msgstr "Places, calendar and comments" -#: surveybox/web/templates/form_settings.html -msgid "Places per person across all participation fields (empty: no limit)" -msgstr "Places per person across all participation fields (empty: no limit)" - -#: surveybox/web/templates/form_settings.html -msgid "Show who has signed up" -msgstr "Show who has signed up" - #: surveybox/web/templates/form_settings.html msgid "Yes, first name and initial of the last name" msgstr "Yes, first name and initial of the last name" @@ -4608,10 +4941,6 @@ msgstr "" "name comes from the question “Participant name”, otherwise from the account; email addresses are " "never shown. The form tells participants about it. Not for anonymous forms." -#: surveybox/web/templates/form_settings.html -msgid "Confirmed dates as calendar" -msgstr "Confirmed dates as calendar" - #: surveybox/web/templates/form_settings.html msgid "Off" msgstr "Off" @@ -4640,18 +4969,6 @@ msgstr "Moderated: new comments are visible after approval" msgid "Public: new comments are visible at once" msgstr "Public: new comments are visible at once" -#: surveybox/web/templates/form_settings.html -msgid "Publish comments without the author’s name (managers still see it)" -msgstr "Publish comments without the author’s name (managers still see it)" - -#: surveybox/web/templates/form_settings.html -msgid "Notify managers about new comments by email" -msgstr "Notify managers about new comments by email" - -#: surveybox/web/templates/form_settings.html -msgid "Reply-to address for messages about this form (optional)" -msgstr "Reply-to address for messages about this form (optional)" - #: surveybox/web/templates/form_settings.html msgid "" "Replies to messages about this form go to this address. Empty: the address from the email " @@ -4664,22 +4981,6 @@ msgstr "" msgid "Data protection" msgstr "Data protection" -#: surveybox/web/templates/form_settings.html -msgid "Privacy notice shown with the form (optional)" -msgstr "Privacy notice shown with the form (optional)" - -#: surveybox/web/templates/form_settings.html -msgid "Participants must give their consent" -msgstr "Participants must give their consent" - -#: surveybox/web/templates/form_settings.html -msgid "Consent text" -msgstr "Consent text" - -#: surveybox/web/templates/form_settings.html -msgid "Retention period in days after the end of the form" -msgstr "Retention period in days after the end of the form" - #: surveybox/web/templates/form_settings.html #, python-format msgid "" @@ -4699,10 +5000,6 @@ msgstr "The answers will be deleted on %(date)s." msgid "The answers will be anonymized on %(date)s." msgstr "The answers will be anonymized on %(date)s." -#: surveybox/web/templates/form_settings.html -msgid "When the retention period ends or a participant is deleted" -msgstr "When the retention period ends or a participant is deleted" - #: surveybox/web/templates/form_settings.html msgid "Keep the answer anonymized" msgstr "Keep the answer anonymized" @@ -4711,10 +5008,6 @@ msgstr "Keep the answer anonymized" msgid "Delete the answer completely" msgstr "Delete the answer completely" -#: surveybox/web/templates/form_settings.html -msgid "Email address of guests" -msgstr "Email address of guests" - #: surveybox/web/templates/form_settings.html surveybox/web/templates/question_edit.html msgid "Do not ask" msgstr "Do not ask" @@ -4771,6 +5064,21 @@ msgstr "Renew link" msgid "Delete form" msgstr "Delete form" +#: surveybox/web/templates/form_settings.html +#, python-format +msgid "" +"The form goes to the trash in the form list. There you can restore it for %(num)d day; after that" +" it is deleted for good." +msgid_plural "" +"The form goes to the trash in the form list. There you can restore it for %(num)d days; after " +"that it is deleted for good." +msgstr[0] "" +"The form goes to the trash in the form list. There you can restore it for %(num)d day; after that" +" it is deleted for good." +msgstr[1] "" +"The form goes to the trash in the form list. There you can restore it for %(num)d days; after " +"that it is deleted for good." + #: surveybox/web/templates/form_settings.html msgid "Yes, delete this form with all questions and answers." msgstr "Yes, delete this form with all questions and answers." @@ -4811,6 +5119,30 @@ msgstr "Co-editor" msgid "No forms yet." msgstr "No forms yet." +#: surveybox/web/templates/forms_list.html +msgid "Trash" +msgstr "Trash" + +#: surveybox/web/templates/forms_list.html +msgid "" +"Deleted forms can be restored with all questions and answers until the date shown. After that " +"they are deleted for good." +msgstr "" +"Deleted forms can be restored with all questions and answers until the date shown. After that " +"they are deleted for good." + +#: surveybox/web/templates/forms_list.html +msgid "Deleted" +msgstr "Deleted" + +#: surveybox/web/templates/forms_list.html +msgid "Restorable until" +msgstr "Restorable until" + +#: surveybox/web/templates/forms_list.html +msgid "Restore" +msgstr "Restore" + #: surveybox/web/templates/forms_list.html msgid "Templates" msgstr "Templates" diff --git a/surveybox/locale/fr/LC_MESSAGES/messages.po b/surveybox/locale/fr/LC_MESSAGES/messages.po index ca9a467..babd919 100644 --- a/surveybox/locale/fr/LC_MESSAGES/messages.po +++ b/surveybox/locale/fr/LC_MESSAGES/messages.po @@ -4,7 +4,7 @@ msgid "" msgstr "" "Project-Id-Version: Surveybox VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2026-11-25 16:57+0100\n" +"POT-Creation-Date: 2026-11-26 08:43+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language: fr\n" @@ -82,7 +82,7 @@ msgid "Guest" msgstr "Invité" #: surveybox/forms/comments.py surveybox/web/templates/admin_audit.html -#: surveybox/web/templates/response_view.html +#: surveybox/web/templates/form_history.html surveybox/web/templates/response_view.html msgid "Deleted user" msgstr "Utilisateur supprimé" @@ -124,15 +124,16 @@ msgstr "Règle invalide (question absente ou pas avant)" #: surveybox/forms/conditions.py surveybox/forms/evaluation.py surveybox/forms/export.py #: surveybox/forms/summary.py surveybox/forms/types.py surveybox/web/routes/forms.py -#: surveybox/web/templates/_fill_fields.html surveybox/web/templates/form_responses.html -#: surveybox/web/templates/results_public.html +#: surveybox/web/templates/_fill_fields.html surveybox/web/templates/form_history_compare.html +#: surveybox/web/templates/form_responses.html surveybox/web/templates/results_public.html msgid "Yes" msgstr "Oui" #: surveybox/forms/conditions.py surveybox/forms/evaluation.py surveybox/forms/export.py #: surveybox/forms/summary.py surveybox/forms/types.py surveybox/web/routes/forms.py -#: surveybox/web/templates/_fill_fields.html surveybox/web/templates/form_responses.html -#: surveybox/web/templates/form_settings.html surveybox/web/templates/results_public.html +#: surveybox/web/templates/_fill_fields.html surveybox/web/templates/form_history_compare.html +#: surveybox/web/templates/form_responses.html surveybox/web/templates/form_settings.html +#: surveybox/web/templates/results_public.html msgid "No" msgstr "Non" @@ -236,7 +237,8 @@ msgid "Page %(page)s of %(pages)s" msgstr "Page %(page)s sur %(pages)s" #: surveybox/forms/export.py surveybox/forms/pdf_export.py surveybox/web/templates/form_designer.html -#: surveybox/web/templates/form_responses.html surveybox/web/templates/forms_list.html +#: surveybox/web/templates/form_history_compare.html surveybox/web/templates/form_responses.html +#: surveybox/web/templates/forms_list.html msgid "Answers" msgstr "Réponses" @@ -850,6 +852,18 @@ msgstr "Le formulaire a été enregistré." msgid "The form has been deleted." msgstr "Le formulaire a été supprimé." +#: surveybox/web/templating.py +msgid "The form has been moved to the trash. It can be restored there for a limited time." +msgstr "Le formulaire a été placé dans la corbeille. Il peut y être restauré pendant un temps limité." + +#: surveybox/web/templating.py +msgid "The form has been restored from the trash." +msgstr "Le formulaire a été restauré depuis la corbeille." + +#: surveybox/web/templating.py +msgid "The selected changes have been restored." +msgstr "Les modifications sélectionnées ont été restaurées." + #: surveybox/web/templating.py msgid "The copy has been created. It is a draft." msgstr "La copie a été créée. C’est un brouillon." @@ -1104,6 +1118,18 @@ msgstr "Durée de conservation par défaut modifiée" msgid "Retention period applied to a form" msgstr "Durée de conservation appliquée à un formulaire" +#: surveybox/web/routes/admin.py +msgid "Changes restored from the form history" +msgstr "Modifications restaurées depuis l’historique" + +#: surveybox/web/routes/admin.py +msgid "Deleted form restored" +msgstr "Formulaire supprimé restauré" + +#: surveybox/web/routes/admin.py +msgid "Form history settings changed" +msgstr "Paramètres de l’historique et de la corbeille modifiés" + #: surveybox/web/routes/admin.py msgid "Account deleted" msgstr "Compte supprimé" @@ -1445,6 +1471,147 @@ msgstr "remis au serveur de messagerie" msgid "sending failed" msgstr "échec de l’envoi" +#: surveybox/web/routes/form_history.py +msgid "Before a change to questions or settings" +msgstr "Avant une modification des questions ou des paramètres" + +#: surveybox/web/routes/form_history.py +msgid "Before an answer was changed by a manager" +msgstr "Avant qu’une réponse soit modifiée par un gestionnaire" + +#: surveybox/web/routes/form_history.py +msgid "Before an answer was deleted by a manager" +msgstr "Avant qu’une réponse soit supprimée par un gestionnaire" + +#: surveybox/web/routes/form_history.py +msgid "Daily" +msgstr "Quotidien" + +#: surveybox/web/routes/form_history.py +msgid "Before a restore" +msgstr "Avant une restauration" + +#: surveybox/web/routes/form_history.py +msgid "When the form was deleted" +msgstr "À la suppression du formulaire" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +#: surveybox/web/templates/forms_list.html +msgid "Title" +msgstr "Titre" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Description (optional)" +msgstr "Description (facultatif)" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Opens at (optional)" +msgstr "Ouverture le (facultatif)" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Closes at (optional)" +msgstr "Fermeture le (facultatif)" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_access.html +#: surveybox/web/templates/form_designer.html surveybox/web/templates/form_settings.html +msgid "Who may fill in" +msgstr "Qui peut remplir" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Password for access via link" +msgstr "Mot de passe pour l’accès par lien" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "A person may fill in the form several times" +msgstr "Une personne peut remplir le formulaire plusieurs fois" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Participants may change their answer" +msgstr "Les participants peuvent modifier leur réponse" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Email address of guests" +msgstr "Adresse e-mail des invités" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Participants see the results" +msgstr "Les participants voient les résultats" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Retention period in days after the end of the form" +msgstr "Durée de conservation en jours après la fin du formulaire" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "When the retention period ends or a participant is deleted" +msgstr "Lorsque la durée de conservation expire ou qu’un participant est supprimé" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Privacy notice shown with the form (optional)" +msgstr "Mention de confidentialité affichée avec le formulaire (facultatif)" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Participants must give their consent" +msgstr "Les participants doivent donner leur consentement" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Consent text" +msgstr "Texte de consentement" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Show who has signed up" +msgstr "Afficher les inscrits" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Places per person across all participation fields (empty: no limit)" +msgstr "Places par personne pour tous les champs de participation (vide : sans limite)" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Remind invited people who have not taken part yet … days before the end (empty: no reminder)" +msgstr "" +"Rappeler aux personnes invitées n’ayant pas encore participé … jours avant la fin (vide : aucun " +"rappel)" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Confirmed dates as calendar" +msgstr "Dates confirmées sous forme d’agenda" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/_comments.html +#: surveybox/web/templates/form_comments.html surveybox/web/templates/form_designer.html +#: surveybox/web/templates/form_settings.html +msgid "Comments" +msgstr "Commentaires" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Publish comments without the author’s name (managers still see it)" +msgstr "Publier les commentaires sans le nom de l’auteur (les gestionnaires le voient)" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Reply-to address for messages about this form (optional)" +msgstr "Adresse de réponse pour les messages sur ce formulaire (facultatif)" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/form_settings.html +msgid "Notify managers about new comments by email" +msgstr "Informer les gestionnaires des nouveaux commentaires par e-mail" + +#: surveybox/web/routes/form_history.py surveybox/web/templates/admin_audit.html +#: surveybox/web/templates/form_settings.html surveybox/web/templates/form_team.html +#: surveybox/web/templates/forms_list.html +msgid "Group" +msgstr "Groupe" + +#: surveybox/web/routes/form_history.py +msgid "Please choose at least one change to restore." +msgstr "Veuillez choisir au moins une modification à restaurer." + +#: surveybox/web/routes/form_history.py surveybox/web/routes/forms.py +msgid "This form can no longer be restored." +msgstr "Ce formulaire ne peut plus être restauré." + +#: surveybox/web/routes/form_history.py +#, python-format +msgid "Restored from the form history (state of %(date)s)." +msgstr "Restauré depuis l’historique (état du %(date)s)." + #: surveybox/web/routes/form_results.py msgid "Please describe why you change this answer." msgstr "Veuillez indiquer pourquoi vous modifiez cette réponse." @@ -1740,11 +1907,6 @@ msgstr "Un compte existe déjà pour cette adresse. Veuillez vous connecter." msgid "Registration is switched off." msgstr "L’inscription est désactivée." -#: surveybox/web/templates/_comments.html surveybox/web/templates/form_comments.html -#: surveybox/web/templates/form_designer.html surveybox/web/templates/form_settings.html -msgid "Comments" -msgstr "Commentaires" - #: surveybox/web/templates/_comments.html msgid "edited" msgstr "modifié" @@ -2360,7 +2522,8 @@ msgstr "Mise en page" #: surveybox/web/templates/admin_appearance.html surveybox/web/templates/admin_settings.html #: surveybox/web/templates/base.html surveybox/web/templates/form_designer.html -#: surveybox/web/templates/form_responses.html surveybox/web/templates/form_settings.html +#: surveybox/web/templates/form_history_compare.html surveybox/web/templates/form_responses.html +#: surveybox/web/templates/form_settings.html msgid "Settings" msgstr "Paramètres" @@ -2631,7 +2794,7 @@ msgstr "" msgid "Action" msgstr "Action" -#: surveybox/web/templates/admin_audit.html +#: surveybox/web/templates/admin_audit.html surveybox/web/templates/form_history.html msgid "By" msgstr "Par" @@ -2649,12 +2812,7 @@ msgstr "Compte supprimé n° %(n)s" msgid "Guest address no. %(n)s" msgstr "Adresse d’invité n° %(n)s" -#: surveybox/web/templates/admin_audit.html surveybox/web/templates/form_settings.html -#: surveybox/web/templates/form_team.html surveybox/web/templates/forms_list.html -msgid "Group" -msgstr "Groupe" - -#: surveybox/web/templates/admin_audit.html +#: surveybox/web/templates/admin_audit.html surveybox/web/templates/form_history_compare.html msgid "deleted" msgstr "supprimé" @@ -3203,6 +3361,47 @@ msgstr "" "supprimées, selon le réglage du formulaire. Le propriétaire est prévenu 14 jours avant ; si " "l’avis arrive plus tard, au moins 7 jours s’écoulent avant toute suppression." +#: surveybox/web/templates/admin_settings.html +msgid "Form history and trash" +msgstr "Historique et corbeille" + +#: surveybox/web/templates/admin_settings.html +#, python-format +msgid "The history can be kept for %(a)d to %(b)d days, the trash for %(c)d to %(d)d days." +msgstr "L’historique peut être conservé de %(a)d à %(b)d jours, la corbeille de %(c)d à %(d)d jours." + +#: surveybox/web/templates/admin_settings.html +msgid "Keep saved states of forms for … days" +msgstr "Conserver les états enregistrés des formulaires pendant … jours" + +#: surveybox/web/templates/admin_settings.html +msgid "" +"States are saved before changes to questions, options, settings and access, before managers " +"change or delete answers, and once a day if a form changed. Managers use them to restore " +"individual questions, options, settings or answers. They contain the answers, so they never " +"outlast them: when a form is deleted or its retention period ends, its states are deleted too." +msgstr "" +"Des états sont enregistrés avant les modifications des questions, options, paramètres et accès, " +"avant que des gestionnaires modifient ou suppriment des réponses, et une fois par jour si un " +"formulaire a changé. Ils permettent de restaurer des questions, options, paramètres ou réponses " +"individuels. Ils contiennent les réponses et ne leur survivent donc jamais : si un formulaire est" +" supprimé ou si son délai de conservation expire, ses états sont supprimés aussi." + +#: surveybox/web/templates/admin_settings.html +msgid "Keep deleted forms in the trash for … days" +msgstr "Conserver les formulaires supprimés dans la corbeille pendant … jours" + +#: surveybox/web/templates/admin_settings.html +msgid "" +"During this time the owner, the person who deleted it, group administrators and administrators " +"can restore a deleted form with all questions and answers. Afterwards it is deleted for good. If " +"a person is deleted, their answers are also removed from the trash and the history at once." +msgstr "" +"Pendant ce temps, le propriétaire, la personne qui l’a supprimé, les administrateurs de groupe et" +" les administrateurs peuvent restaurer un formulaire supprimé avec toutes ses questions et " +"réponses. Ensuite, il est supprimé définitivement. Si une personne est supprimée, ses réponses " +"disparaissent aussitôt aussi de la corbeille et de l’historique." + #: surveybox/web/templates/admin_user_delete.html surveybox/web/templates/admin_user_edit.html msgid "Delete user" msgstr "Supprimer l’utilisateur" @@ -4015,11 +4214,6 @@ msgstr "" msgid "Access" msgstr "Accès" -#: surveybox/web/templates/form_access.html surveybox/web/templates/form_designer.html -#: surveybox/web/templates/form_settings.html -msgid "Who may fill in" -msgstr "Qui peut remplir" - #: surveybox/web/templates/form_access.html msgid "" "Choose groups and individual users. Members of a chosen group always have access, also if they " @@ -4040,10 +4234,14 @@ msgstr "Valider" msgid "All forms" msgstr "Tous les formulaires" -#: surveybox/web/templates/form_designer.html +#: surveybox/web/templates/form_designer.html surveybox/web/templates/forms_list.html msgid "Template" msgstr "Modèle" +#: surveybox/web/templates/form_designer.html surveybox/web/templates/form_history.html +msgid "More places are booked than available:" +msgstr "Plus de places sont réservées que disponibles :" + #: surveybox/web/templates/form_designer.html surveybox/web/templates/form_preview.html msgid "Live preview" msgstr "Aperçu en direct" @@ -4052,6 +4250,11 @@ msgstr "Aperçu en direct" msgid "Team" msgstr "Équipe" +#: surveybox/web/templates/form_designer.html surveybox/web/templates/form_history.html +#: surveybox/web/templates/form_history_compare.html +msgid "History" +msgstr "Historique" + #: surveybox/web/templates/form_designer.html #, python-format msgid "%(num)d new" @@ -4273,6 +4476,182 @@ msgstr[1] "%(num)d personnes" msgid "No follow-up emails yet." msgstr "Aucun e-mail de suivi pour l’instant." +#: surveybox/web/templates/form_history.html +msgid "Nobody was moved to the waiting list. Raise the number of places or contact the people concerned." +msgstr "" +"Personne n’a été placé sur la liste d’attente. Augmentez le nombre de places ou contactez les " +"personnes concernées." + +#: surveybox/web/templates/form_history.html +msgid "" +"Surveybox saves the state of this form before questions, options, settings or access are changed," +" before a manager changes or deletes an answer, and once a day if anything changed. Choose a " +"state to see what differs from now and to restore individual questions, options, settings or " +"answers. Everything else stays as it is." +msgstr "" +"Surveybox enregistre l’état de ce formulaire avant toute modification des questions, options, " +"paramètres ou accès, avant qu’un gestionnaire modifie ou supprime une réponse, et une fois par " +"jour en cas de changement. Choisissez un état pour voir ce qui diffère d’aujourd’hui et restaurer" +" des questions, options, paramètres ou réponses individuels. Tout le reste reste inchangé." + +#: surveybox/web/templates/form_history.html +#, python-format +msgid "States are kept for %(num)d day, at most as long as the answers themselves." +msgid_plural "States are kept for %(num)d days, at most as long as the answers themselves." +msgstr[0] "Les états sont conservés %(num)d jour, au plus aussi longtemps que les réponses elles-mêmes." +msgstr[1] "Les états sont conservés %(num)d jours, au plus aussi longtemps que les réponses elles-mêmes." + +#: surveybox/web/templates/form_history.html +msgid "" +"Changes and deletions by participants themselves are not restored; what participants delete also " +"disappears from the history." +msgstr "" +"Les modifications et suppressions faites par les participants eux-mêmes ne sont pas restaurées ; " +"ce que les participants suppriment disparaît aussi de l’historique." + +#: surveybox/web/templates/form_history.html +msgid "Saved" +msgstr "Enregistré" + +#: surveybox/web/templates/form_history.html +msgid "Occasion" +msgstr "Occasion" + +#: surveybox/web/templates/form_history.html +msgid "Compare" +msgstr "Comparer" + +#: surveybox/web/templates/form_history.html +msgid "No states yet. The first one is saved with the next change." +msgstr "Aucun état pour l’instant. Le premier sera enregistré à la prochaine modification." + +#: surveybox/web/templates/form_history_compare.html +msgid "empty" +msgstr "vide" + +#: surveybox/web/templates/form_history_compare.html +#, python-format +msgid "State of %(date)s" +msgstr "État du %(date)s" + +#: surveybox/web/templates/form_history_compare.html +msgid "Nothing in this state differs from the form as it is now in a way that can be restored." +msgstr "Rien dans cet état ne diffère du formulaire actuel d’une manière qui puisse être restaurée." + +#: surveybox/web/templates/form_history_compare.html +msgid "" +"Choose what to restore. Only the chosen items change; questions, answers and settings that are " +"not chosen stay as they are now." +msgstr "" +"Choisissez ce qu’il faut restaurer. Seuls les éléments choisis changent ; les questions, réponses" +" et paramètres non choisis restent tels quels." + +#: surveybox/web/templates/form_history_compare.html +msgid "Access for people and groups" +msgstr "Accès pour des personnes et des groupes" + +#: surveybox/web/templates/form_history_compare.html +#, python-format +msgid "Then: %(old)d entries, now: %(new)d entries" +msgstr "Alors : %(old)d entrées, maintenant : %(new)d entrées" + +#: surveybox/web/templates/form_history_compare.html +msgid "Then" +msgstr "Alors" + +#: surveybox/web/templates/form_history_compare.html +msgid "Now" +msgstr "Maintenant" + +#: surveybox/web/templates/form_history_compare.html +msgid "changed" +msgstr "modifié" + +#: surveybox/web/templates/form_history_compare.html +msgid "Questions and options" +msgstr "Questions et options" + +#: surveybox/web/templates/form_history_compare.html +#, python-format +msgid "With %(num)d answer" +msgid_plural "With %(num)d answers" +msgstr[0] "Avec %(num)d réponse" +msgstr[1] "Avec %(num)d réponses" + +#: surveybox/web/templates/form_history_compare.html +#, python-format +msgid "%(num)d booked place" +msgid_plural "%(num)d booked places" +msgstr[0] "%(num)d place réservée" +msgstr[1] "%(num)d places réservées" + +#: surveybox/web/templates/form_history_compare.html +msgid "" +"Text, settings and options as they were then. Options added since are kept; removed options are " +"listed separately." +msgstr "" +"Texte, paramètres et options tels qu’ils étaient alors. Les options ajoutées depuis sont " +"conservées ; les options supprimées sont listées séparément." + +#: surveybox/web/templates/form_history_compare.html +msgid "option removed" +msgstr "option supprimée" + +#: surveybox/web/templates/form_history_compare.html +#, python-format +msgid "Question: %(question)s" +msgstr "Question : %(question)s" + +#: surveybox/web/templates/form_history_compare.html +msgid "Answer without name" +msgstr "Réponse sans nom" + +#: surveybox/web/templates/form_history_compare.html +msgid "deleted by a manager" +msgstr "supprimée par un gestionnaire" + +#: surveybox/web/templates/form_history_compare.html +#, python-format +msgid "Submitted %(date)s" +msgstr "Envoyée le %(date)s" + +#: surveybox/web/templates/form_history_compare.html +#, python-format +msgid "%(num)d answered question" +msgid_plural "%(num)d answered questions" +msgstr[0] "%(num)d question répondue" +msgstr[1] "%(num)d questions répondues" + +#: surveybox/web/templates/form_history_compare.html +msgid "changed by a manager" +msgstr "modifiée par un gestionnaire" + +#: surveybox/web/templates/form_history_compare.html +#, python-format +msgid "Changed %(date)s" +msgstr "Modifiée le %(date)s" + +#: surveybox/web/templates/form_history_compare.html +#, python-format +msgid "%(num)d question differs" +msgid_plural "%(num)d questions differ" +msgstr[0] "%(num)d question diffère" +msgstr[1] "%(num)d questions diffèrent" + +#: surveybox/web/templates/form_history_compare.html +msgid "" +"Before restoring, the current state is saved too, so this step can be undone in the history. " +"Booked places are restored even if there are not enough places any more; the option is then shown" +" as overbooked." +msgstr "" +"Avant la restauration, l’état actuel est aussi enregistré : cette étape peut donc être annulée " +"dans l’historique. Les places réservées sont restaurées même s’il n’y a plus assez de places ; " +"l’option est alors signalée comme surréservée." + +#: surveybox/web/templates/form_history_compare.html +msgid "Restore selected" +msgstr "Restaurer la sélection" + #: surveybox/web/templates/form_preview.html msgid "Phone" msgstr "Téléphone" @@ -4431,6 +4810,10 @@ msgstr "Entrée" msgid "Signed up" msgstr "Inscrits" +#: surveybox/web/templates/form_responses.html +msgid "overbooked" +msgstr "surréservé" + #: surveybox/web/templates/form_responses.html surveybox/web/templates/results_public.html #, python-format msgid "%(num)d waiting" @@ -4522,22 +4905,6 @@ msgstr "" msgid "General" msgstr "Général" -#: surveybox/web/templates/form_settings.html surveybox/web/templates/forms_list.html -msgid "Title" -msgstr "Titre" - -#: surveybox/web/templates/form_settings.html -msgid "Description (optional)" -msgstr "Description (facultatif)" - -#: surveybox/web/templates/form_settings.html -msgid "Opens at (optional)" -msgstr "Ouverture le (facultatif)" - -#: surveybox/web/templates/form_settings.html -msgid "Closes at (optional)" -msgstr "Fermeture le (facultatif)" - #: surveybox/web/templates/form_settings.html surveybox/web/templates/forms_list.html msgid "no group (instance-wide)" msgstr "aucun groupe (toute l’instance)" @@ -4546,10 +4913,6 @@ msgstr "aucun groupe (toute l’instance)" msgid "Group administrators of this group and the groups above manage the form too." msgstr "Les administrateurs de ce groupe et des groupes supérieurs gèrent aussi le formulaire." -#: surveybox/web/templates/form_settings.html -msgid "Password for access via link" -msgstr "Mot de passe pour l’accès par lien" - #: surveybox/web/templates/form_settings.html msgid "A password is set. Leave empty to keep it." msgstr "Un mot de passe est défini. Laissez vide pour le conserver." @@ -4566,18 +4929,10 @@ msgstr "Pour « utilisateurs et groupes sélectionnés », vous les choisissez msgid "Participation" msgstr "Participation" -#: surveybox/web/templates/form_settings.html -msgid "A person may fill in the form several times" -msgstr "Une personne peut remplir le formulaire plusieurs fois" - #: surveybox/web/templates/form_settings.html msgid "Anonymous: answers are stored without reference to the person" msgstr "Anonyme : les réponses sont enregistrées sans lien avec la personne" -#: surveybox/web/templates/form_settings.html -msgid "Participants may change their answer" -msgstr "Les participants peuvent modifier leur réponse" - #: surveybox/web/templates/form_settings.html msgid "Yes, until the form closes" msgstr "Oui, jusqu’à la fermeture du formulaire" @@ -4588,12 +4943,6 @@ msgstr "" "Pour les participants connectés et les invités avec leur lien personnel ; pas pour les " "formulaires anonymes." -#: surveybox/web/templates/form_settings.html -msgid "Remind invited people who have not taken part yet … days before the end (empty: no reminder)" -msgstr "" -"Rappeler aux personnes invitées n’ayant pas encore participé … jours avant la fin (vide : aucun " -"rappel)" - #: surveybox/web/templates/form_settings.html msgid "" "Only for access “Selected users and groups” and with an end date. Each person gets the reminder " @@ -4602,10 +4951,6 @@ msgstr "" "Uniquement pour l’accès « Utilisateurs et groupes sélectionnés » et avec une date de fin. Chaque " "personne reçoit le rappel une fois par e-mail ; elle peut le désactiver dans son compte." -#: surveybox/web/templates/form_settings.html -msgid "Participants see the results" -msgstr "Les participants voient les résultats" - #: surveybox/web/templates/form_settings.html msgid "Never" msgstr "Jamais" @@ -4636,14 +4981,6 @@ msgstr "" msgid "Places, calendar and comments" msgstr "Places, agenda et commentaires" -#: surveybox/web/templates/form_settings.html -msgid "Places per person across all participation fields (empty: no limit)" -msgstr "Places par personne pour tous les champs de participation (vide : sans limite)" - -#: surveybox/web/templates/form_settings.html -msgid "Show who has signed up" -msgstr "Afficher les inscrits" - #: surveybox/web/templates/form_settings.html msgid "Yes, first name and initial of the last name" msgstr "Oui, prénom et initiale du nom" @@ -4663,10 +5000,6 @@ msgstr "" "adresses e-mail ne sont jamais affichées. Le formulaire en informe les participants. Pas pour les" " formulaires anonymes." -#: surveybox/web/templates/form_settings.html -msgid "Confirmed dates as calendar" -msgstr "Dates confirmées sous forme d’agenda" - #: surveybox/web/templates/form_settings.html msgid "Off" msgstr "Désactivé" @@ -4695,18 +5028,6 @@ msgstr "Modéré : les nouveaux commentaires sont visibles après validation" msgid "Public: new comments are visible at once" msgstr "Public : les nouveaux commentaires sont visibles immédiatement" -#: surveybox/web/templates/form_settings.html -msgid "Publish comments without the author’s name (managers still see it)" -msgstr "Publier les commentaires sans le nom de l’auteur (les gestionnaires le voient)" - -#: surveybox/web/templates/form_settings.html -msgid "Notify managers about new comments by email" -msgstr "Informer les gestionnaires des nouveaux commentaires par e-mail" - -#: surveybox/web/templates/form_settings.html -msgid "Reply-to address for messages about this form (optional)" -msgstr "Adresse de réponse pour les messages sur ce formulaire (facultatif)" - #: surveybox/web/templates/form_settings.html msgid "" "Replies to messages about this form go to this address. Empty: the address from the email " @@ -4719,22 +5040,6 @@ msgstr "" msgid "Data protection" msgstr "Protection des données" -#: surveybox/web/templates/form_settings.html -msgid "Privacy notice shown with the form (optional)" -msgstr "Mention de confidentialité affichée avec le formulaire (facultatif)" - -#: surveybox/web/templates/form_settings.html -msgid "Participants must give their consent" -msgstr "Les participants doivent donner leur consentement" - -#: surveybox/web/templates/form_settings.html -msgid "Consent text" -msgstr "Texte de consentement" - -#: surveybox/web/templates/form_settings.html -msgid "Retention period in days after the end of the form" -msgstr "Durée de conservation en jours après la fin du formulaire" - #: surveybox/web/templates/form_settings.html #, python-format msgid "" @@ -4754,10 +5059,6 @@ msgstr "Les réponses seront supprimées le %(date)s." msgid "The answers will be anonymized on %(date)s." msgstr "Les réponses seront anonymisées le %(date)s." -#: surveybox/web/templates/form_settings.html -msgid "When the retention period ends or a participant is deleted" -msgstr "Lorsque la durée de conservation expire ou qu’un participant est supprimé" - #: surveybox/web/templates/form_settings.html msgid "Keep the answer anonymized" msgstr "Conserver la réponse anonymisée" @@ -4766,10 +5067,6 @@ msgstr "Conserver la réponse anonymisée" msgid "Delete the answer completely" msgstr "Supprimer complètement la réponse" -#: surveybox/web/templates/form_settings.html -msgid "Email address of guests" -msgstr "Adresse e-mail des invités" - #: surveybox/web/templates/form_settings.html surveybox/web/templates/question_edit.html msgid "Do not ask" msgstr "Ne pas demander" @@ -4829,6 +5126,21 @@ msgstr "Renouveler le lien" msgid "Delete form" msgstr "Supprimer le formulaire" +#: surveybox/web/templates/form_settings.html +#, python-format +msgid "" +"The form goes to the trash in the form list. There you can restore it for %(num)d day; after that" +" it is deleted for good." +msgid_plural "" +"The form goes to the trash in the form list. There you can restore it for %(num)d days; after " +"that it is deleted for good." +msgstr[0] "" +"Le formulaire va dans la corbeille de la liste des formulaires. Vous pouvez l’y restaurer pendant" +" %(num)d jour ; ensuite, il est supprimé définitivement." +msgstr[1] "" +"Le formulaire va dans la corbeille de la liste des formulaires. Vous pouvez l’y restaurer pendant" +" %(num)d jours ; ensuite, il est supprimé définitivement." + #: surveybox/web/templates/form_settings.html msgid "Yes, delete this form with all questions and answers." msgstr "Oui, supprimer ce formulaire avec toutes les questions et réponses." @@ -4869,6 +5181,30 @@ msgstr "Coéditeur" msgid "No forms yet." msgstr "Pas encore de formulaires." +#: surveybox/web/templates/forms_list.html +msgid "Trash" +msgstr "Corbeille" + +#: surveybox/web/templates/forms_list.html +msgid "" +"Deleted forms can be restored with all questions and answers until the date shown. After that " +"they are deleted for good." +msgstr "" +"Les formulaires supprimés peuvent être restaurés avec toutes leurs questions et réponses jusqu’à " +"la date indiquée. Ensuite, ils sont supprimés définitivement." + +#: surveybox/web/templates/forms_list.html +msgid "Deleted" +msgstr "Supprimé" + +#: surveybox/web/templates/forms_list.html +msgid "Restorable until" +msgstr "Restaurable jusqu’au" + +#: surveybox/web/templates/forms_list.html +msgid "Restore" +msgstr "Restaurer" + #: surveybox/web/templates/forms_list.html msgid "Templates" msgstr "Modèles" diff --git a/surveybox/locale/messages.pot b/surveybox/locale/messages.pot index 121de11..1626283 100644 --- a/surveybox/locale/messages.pot +++ b/surveybox/locale/messages.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2026-11-25 16:57+0100\n" +"POT-Creation-Date: 2026-11-26 08:43+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -29,7 +29,7 @@ msgstr "" msgid "Links must start with https:// (at most 500 characters)." msgstr "" -#: surveybox/appearance.py:132 surveybox/web/routes/forms.py:53 +#: surveybox/appearance.py:132 surveybox/web/routes/forms.py:55 msgid "A text is too long." msgstr "" @@ -69,7 +69,7 @@ msgid "" "1, at least 3 : 1 is needed for markings)." msgstr "" -#: surveybox/forms/booking.py:162 surveybox/forms/evaluation.py:193 +#: surveybox/forms/booking.py:170 surveybox/forms/evaluation.py:193 #: surveybox/forms/export.py:133 #: surveybox/web/templates/followup_recipients.html:25 #: surveybox/web/templates/form_comments.html:12 @@ -78,6 +78,7 @@ msgid "Guest" msgstr "" #: surveybox/forms/comments.py:148 surveybox/web/templates/admin_audit.html:17 +#: surveybox/web/templates/form_history.html:26 #: surveybox/web/templates/response_view.html:44 msgid "Deleted user" msgstr "" @@ -121,11 +122,12 @@ msgstr "" #: surveybox/forms/conditions.py:452 surveybox/forms/evaluation.py:82 #: surveybox/forms/export.py:85 surveybox/forms/summary.py:73 #: surveybox/forms/types.py:775 surveybox/forms/types.py:798 -#: surveybox/web/routes/forms.py:313 +#: surveybox/web/routes/forms.py:320 #: surveybox/web/templates/_fill_fields.html:89 #: surveybox/web/templates/_fill_fields.html:198 #: surveybox/web/templates/_fill_fields.html:371 #: surveybox/web/templates/_fill_fields.html:408 +#: surveybox/web/templates/form_history_compare.html:6 #: surveybox/web/templates/form_responses.html:82 #: surveybox/web/templates/results_public.html:21 msgid "Yes" @@ -134,11 +136,12 @@ msgstr "" #: surveybox/forms/conditions.py:452 surveybox/forms/evaluation.py:83 #: surveybox/forms/export.py:85 surveybox/forms/summary.py:74 #: surveybox/forms/types.py:776 surveybox/forms/types.py:798 -#: surveybox/web/routes/forms.py:313 +#: surveybox/web/routes/forms.py:320 #: surveybox/web/templates/_fill_fields.html:90 #: surveybox/web/templates/_fill_fields.html:198 #: surveybox/web/templates/_fill_fields.html:372 #: surveybox/web/templates/_fill_fields.html:409 +#: surveybox/web/templates/form_history_compare.html:7 #: surveybox/web/templates/form_responses.html:82 #: surveybox/web/templates/form_settings.html:57 #: surveybox/web/templates/form_settings.html:79 @@ -149,13 +152,13 @@ msgstr "" #: surveybox/forms/conditions.py:454 surveybox/forms/evaluation.py:87 #: surveybox/forms/evaluation.py:184 surveybox/forms/export.py:94 #: surveybox/forms/summary.py:134 surveybox/forms/types.py:792 -#: surveybox/web/routes/forms.py:320 +#: surveybox/web/routes/forms.py:327 msgid "signed up" msgstr "" #: surveybox/forms/conditions.py:456 surveybox/forms/summary.py:92 #: surveybox/forms/types.py:782 surveybox/forms/types.py:788 -#: surveybox/web/routes/forms.py:313 +#: surveybox/web/routes/forms.py:320 #: surveybox/web/templates/_fill_fields.html:96 #: surveybox/web/templates/_fill_fields.html:97 #: surveybox/web/templates/_fill_fields.html:106 @@ -263,59 +266,61 @@ msgstr "" msgid "received" msgstr "" -#: surveybox/forms/export.py:143 +#: surveybox/forms/export.py:144 msgid "no response yet" msgstr "" -#: surveybox/forms/export.py:208 surveybox/forms/export.py:221 +#: surveybox/forms/export.py:209 surveybox/forms/export.py:222 #: surveybox/forms/pdf_export.py:181 #, python-format msgid "Page %(page)s of %(pages)s" msgstr "" -#: surveybox/forms/export.py:210 surveybox/forms/export.py:241 -#: surveybox/forms/export.py:266 surveybox/forms/pdf_export.py:289 -#: surveybox/web/templates/form_designer.html:24 +#: surveybox/forms/export.py:211 surveybox/forms/export.py:242 +#: surveybox/forms/export.py:267 surveybox/forms/pdf_export.py:289 +#: surveybox/web/templates/form_designer.html:29 +#: surveybox/web/templates/form_history_compare.html:79 #: surveybox/web/templates/form_responses.html:2 #: surveybox/web/templates/form_responses.html:6 #: surveybox/web/templates/forms_list.html:9 +#: surveybox/web/templates/forms_list.html:36 msgid "Answers" msgstr "" -#: surveybox/forms/export.py:230 surveybox/forms/export.py:257 -#: surveybox/forms/export.py:264 +#: surveybox/forms/export.py:231 surveybox/forms/export.py:258 +#: surveybox/forms/export.py:265 msgid "Form" msgstr "" -#: surveybox/forms/export.py:265 +#: surveybox/forms/export.py:266 msgid "Exported" msgstr "" -#: surveybox/forms/export.py:267 +#: surveybox/forms/export.py:268 msgid "Period" msgstr "" -#: surveybox/forms/export.py:270 surveybox/web/templates/admin_groups.html:25 +#: surveybox/forms/export.py:271 surveybox/web/templates/admin_groups.html:25 msgid "all" msgstr "" -#: surveybox/forms/export.py:271 surveybox/web/routes/form_results.py:123 +#: surveybox/forms/export.py:272 surveybox/web/routes/form_results.py:124 msgid "Answer filter" msgstr "" -#: surveybox/forms/export.py:271 +#: surveybox/forms/export.py:272 msgid "none" msgstr "" -#: surveybox/forms/export.py:272 +#: surveybox/forms/export.py:273 msgid "Personal data" msgstr "" -#: surveybox/forms/export.py:272 +#: surveybox/forms/export.py:273 msgid "included" msgstr "" -#: surveybox/forms/export.py:273 +#: surveybox/forms/export.py:274 msgid "left out" msgstr "" @@ -508,7 +513,7 @@ msgstr "" msgid "Please enter a valid time." msgstr "" -#: surveybox/forms/types.py:447 surveybox/web/routes/forms.py:54 +#: surveybox/forms/types.py:447 surveybox/web/routes/forms.py:56 msgid "Please enter a valid date and time." msgstr "" @@ -915,41 +920,55 @@ msgstr "" msgid "The form has been deleted." msgstr "" -#: surveybox/web/templating.py:47 +#: surveybox/web/templating.py:48 +msgid "" +"The form has been moved to the trash. It can be restored there for a " +"limited time." +msgstr "" + +#: surveybox/web/templating.py:50 +msgid "The form has been restored from the trash." +msgstr "" + +#: surveybox/web/templating.py:51 +msgid "The selected changes have been restored." +msgstr "" + +#: surveybox/web/templating.py:52 msgid "The copy has been created. It is a draft." msgstr "" -#: surveybox/web/templating.py:49 +#: surveybox/web/templating.py:54 msgid "" "The template has been saved. New forms can be created from it in the form" " list." msgstr "" -#: surveybox/web/templating.py:51 +#: surveybox/web/templating.py:56 msgid "The settings have been saved." msgstr "" -#: surveybox/web/templating.py:52 +#: surveybox/web/templating.py:57 msgid "Waiting messages are sent within the next minute." msgstr "" -#: surveybox/web/templating.py:53 +#: surveybox/web/templating.py:58 msgid "Your notification settings have been saved." msgstr "" -#: surveybox/web/templating.py:54 +#: surveybox/web/templating.py:59 msgid "The invitation has been sent by email." msgstr "" -#: surveybox/web/templating.py:55 +#: surveybox/web/templating.py:60 msgid "A link to set a new password has been sent by email." msgstr "" -#: surveybox/web/templating.py:56 +#: surveybox/web/templating.py:61 msgid "Your account has been created. You can now sign in." msgstr "" -#: surveybox/web/templating.py:58 +#: surveybox/web/templating.py:63 msgid "" "The question has been deleted. Rules of other questions that referred to " "it were removed." @@ -981,7 +1000,7 @@ msgstr "" msgid "This passkey is not registered here." msgstr "" -#: surveybox/web/routes/account.py:37 surveybox/web/routes/forms.py:73 +#: surveybox/web/routes/account.py:37 surveybox/web/routes/forms.py:75 #: surveybox/web/routes/groups.py:32 #: surveybox/web/templates/guest_erase.html:18 #: surveybox/web/templates/personal.html:87 @@ -1180,54 +1199,66 @@ msgid "Retention period applied to a form" msgstr "" #: surveybox/web/routes/admin.py:94 -msgid "Account deleted" +msgid "Changes restored from the form history" msgstr "" #: surveybox/web/routes/admin.py:95 -msgid "Own data downloaded" +msgid "Deleted form restored" msgstr "" #: surveybox/web/routes/admin.py:96 -msgid "Data of a user exported" +msgid "Form history settings changed" msgstr "" #: surveybox/web/routes/admin.py:97 -msgid "Data of a guest address exported" +msgid "Account deleted" msgstr "" #: surveybox/web/routes/admin.py:98 -msgid "Guest downloaded their data" +msgid "Own data downloaded" msgstr "" #: surveybox/web/routes/admin.py:99 -msgid "Logo changed" +msgid "Data of a user exported" msgstr "" #: surveybox/web/routes/admin.py:100 -msgid "Design changed" +msgid "Data of a guest address exported" msgstr "" #: surveybox/web/routes/admin.py:101 -msgid "Email template changed" +msgid "Guest downloaded their data" msgstr "" #: surveybox/web/routes/admin.py:102 -msgid "Answers exported" +msgid "Logo changed" msgstr "" #: surveybox/web/routes/admin.py:103 -msgid "Answer deleted by a manager" +msgid "Design changed" msgstr "" #: surveybox/web/routes/admin.py:104 -msgid "Answer changed by a manager" +msgid "Email template changed" msgstr "" #: surveybox/web/routes/admin.py:105 +msgid "Answers exported" +msgstr "" + +#: surveybox/web/routes/admin.py:106 +msgid "Answer deleted by a manager" +msgstr "" + +#: surveybox/web/routes/admin.py:107 +msgid "Answer changed by a manager" +msgstr "" + +#: surveybox/web/routes/admin.py:108 msgid "Guest address and its answers deleted" msgstr "" -#: surveybox/web/routes/admin.py:179 +#: surveybox/web/routes/admin.py:182 msgid "A chosen group does not fit this user type." msgstr "" @@ -1323,41 +1354,41 @@ msgstr "" msgid "Shift" msgstr "" -#: surveybox/web/routes/admin_settings.py:51 +#: surveybox/web/routes/admin_settings.py:56 msgid "Please upload a PNG, JPEG or WebP image (SVG is not accepted)." msgstr "" -#: surveybox/web/routes/admin_settings.py:52 +#: surveybox/web/routes/admin_settings.py:57 msgid "The image is too large (at most 5 MB)." msgstr "" -#: surveybox/web/routes/admin_settings.py:53 +#: surveybox/web/routes/admin_settings.py:58 msgid "Please upload your own logo first; the dark version is added to it." msgstr "" -#: surveybox/web/routes/admin_settings.py:117 +#: surveybox/web/routes/admin_settings.py:138 msgid "Off: only administrators create accounts" msgstr "" -#: surveybox/web/routes/admin_settings.py:118 +#: surveybox/web/routes/admin_settings.py:139 msgid "" "Guests: people who confirmed their address when taking part via a form " "link" msgstr "" -#: surveybox/web/routes/admin_settings.py:119 +#: surveybox/web/routes/admin_settings.py:140 msgid "Open: anyone with an email address" msgstr "" -#: surveybox/web/routes/admin_settings.py:135 +#: surveybox/web/routes/admin_settings.py:156 msgid "MediaCMS" msgstr "" -#: surveybox/web/routes/admin_settings.py:136 +#: surveybox/web/routes/admin_settings.py:157 msgid "Player page (embedded as a frame)" msgstr "" -#: surveybox/web/routes/admin_settings.py:137 +#: surveybox/web/routes/admin_settings.py:158 msgid "Video file (MP4 or WebM, played directly)" msgstr "" @@ -1488,7 +1519,7 @@ msgstr "" msgid "Only manually" msgstr "" -#: surveybox/web/routes/form_followups.py:51 surveybox/web/routes/forms.py:129 +#: surveybox/web/routes/form_followups.py:51 surveybox/web/routes/forms.py:131 msgid "The input could not be processed." msgstr "" @@ -1528,11 +1559,182 @@ msgstr "" msgid "sending failed" msgstr "" -#: surveybox/web/routes/form_results.py:217 +#: surveybox/web/routes/form_history.py:26 +msgid "Before a change to questions or settings" +msgstr "" + +#: surveybox/web/routes/form_history.py:27 +msgid "Before an answer was changed by a manager" +msgstr "" + +#: surveybox/web/routes/form_history.py:28 +msgid "Before an answer was deleted by a manager" +msgstr "" + +#: surveybox/web/routes/form_history.py:29 +msgid "Daily" +msgstr "" + +#: surveybox/web/routes/form_history.py:30 +msgid "Before a restore" +msgstr "" + +#: surveybox/web/routes/form_history.py:31 +msgid "When the form was deleted" +msgstr "" + +#: surveybox/web/routes/form_history.py:36 +#: surveybox/web/templates/form_settings.html:16 +#: surveybox/web/templates/forms_list.html:9 +#: surveybox/web/templates/forms_list.html:36 +#: surveybox/web/templates/forms_list.html:78 +msgid "Title" +msgstr "" + +#: surveybox/web/routes/form_history.py:37 +#: surveybox/web/templates/form_settings.html:18 +msgid "Description (optional)" +msgstr "" + +#: surveybox/web/routes/form_history.py:38 +#: surveybox/web/templates/form_settings.html:20 +msgid "Opens at (optional)" +msgstr "" + +#: surveybox/web/routes/form_history.py:39 +#: surveybox/web/templates/form_settings.html:22 +msgid "Closes at (optional)" +msgstr "" + +#: surveybox/web/routes/form_history.py:40 +#: surveybox/web/templates/form_access.html:6 +#: surveybox/web/templates/form_designer.html:70 +#: surveybox/web/templates/form_settings.html:35 +msgid "Who may fill in" +msgstr "" + +#: surveybox/web/routes/form_history.py:41 +#: surveybox/web/templates/form_settings.html:40 +msgid "Password for access via link" +msgstr "" + +#: surveybox/web/routes/form_history.py:42 +#: surveybox/web/templates/form_settings.html:50 +msgid "A person may fill in the form several times" +msgstr "" + +#: surveybox/web/routes/form_history.py:43 +#: surveybox/web/templates/form_settings.html:54 +msgid "Participants may change their answer" +msgstr "" + +#: surveybox/web/routes/form_history.py:44 +#: surveybox/web/templates/form_settings.html:128 +msgid "Email address of guests" +msgstr "" + +#: surveybox/web/routes/form_history.py:45 +#: surveybox/web/templates/form_settings.html:63 +msgid "Participants see the results" +msgstr "" + +#: surveybox/web/routes/form_history.py:46 +#: surveybox/web/templates/form_settings.html:119 +msgid "Retention period in days after the end of the form" +msgstr "" + +#: surveybox/web/routes/form_history.py:47 +#: surveybox/web/templates/form_settings.html:123 +msgid "When the retention period ends or a participant is deleted" +msgstr "" + +#: surveybox/web/routes/form_history.py:48 +#: surveybox/web/templates/form_settings.html:114 +msgid "Privacy notice shown with the form (optional)" +msgstr "" + +#: surveybox/web/routes/form_history.py:49 +#: surveybox/web/templates/form_settings.html:116 +msgid "Participants must give their consent" +msgstr "" + +#: surveybox/web/routes/form_history.py:50 +#: surveybox/web/templates/form_settings.html:117 +msgid "Consent text" +msgstr "" + +#: surveybox/web/routes/form_history.py:51 +#: surveybox/web/templates/form_settings.html:77 +msgid "Show who has signed up" +msgstr "" + +#: surveybox/web/routes/form_history.py:53 +#: surveybox/web/templates/form_settings.html:74 +msgid "Places per person across all participation fields (empty: no limit)" +msgstr "" + +#: surveybox/web/routes/form_history.py:55 +#: surveybox/web/templates/form_settings.html:60 +msgid "" +"Remind invited people who have not taken part yet … days before the end " +"(empty: no reminder)" +msgstr "" + +#: surveybox/web/routes/form_history.py:58 +#: surveybox/web/templates/form_settings.html:86 +msgid "Confirmed dates as calendar" +msgstr "" + +#: surveybox/web/routes/form_history.py:59 +#: surveybox/web/templates/_comments.html:4 +#: surveybox/web/templates/form_comments.html:2 +#: surveybox/web/templates/form_comments.html:6 +#: surveybox/web/templates/form_designer.html:34 +#: surveybox/web/templates/form_settings.html:99 +msgid "Comments" +msgstr "" + +#: surveybox/web/routes/form_history.py:61 +#: surveybox/web/templates/form_settings.html:103 +msgid "Publish comments without the author’s name (managers still see it)" +msgstr "" + +#: surveybox/web/routes/form_history.py:62 +#: surveybox/web/templates/form_settings.html:107 +msgid "Reply-to address for messages about this form (optional)" +msgstr "" + +#: surveybox/web/routes/form_history.py:63 +#: surveybox/web/templates/form_settings.html:104 +msgid "Notify managers about new comments by email" +msgstr "" + +#: surveybox/web/routes/form_history.py:64 +#: surveybox/web/templates/admin_audit.html:24 +#: surveybox/web/templates/form_settings.html:25 +#: surveybox/web/templates/form_team.html:15 +#: surveybox/web/templates/forms_list.html:81 +msgid "Group" +msgstr "" + +#: surveybox/web/routes/form_history.py:73 +msgid "Please choose at least one change to restore." +msgstr "" + +#: surveybox/web/routes/form_history.py:74 surveybox/web/routes/forms.py:181 +msgid "This form can no longer be restored." +msgstr "" + +#: surveybox/web/routes/form_history.py:153 +#, python-format +msgid "Restored from the form history (state of %(date)s)." +msgstr "" + +#: surveybox/web/routes/form_results.py:220 msgid "Please describe why you change this answer." msgstr "" -#: surveybox/web/routes/form_results.py:218 +#: surveybox/web/routes/form_results.py:221 msgid "The note is too long (at most 1000 characters)." msgstr "" @@ -1553,210 +1755,210 @@ msgstr "" msgid "Copy of %(title)s" msgstr "" -#: surveybox/web/routes/forms.py:52 +#: surveybox/web/routes/forms.py:54 msgid "Please enter a title (at most 200 characters)." msgstr "" -#: surveybox/web/routes/forms.py:55 +#: surveybox/web/routes/forms.py:57 msgid "The end must be after the start." msgstr "" -#: surveybox/web/routes/forms.py:56 +#: surveybox/web/routes/forms.py:58 msgid "Please choose who may fill in the form." msgstr "" -#: surveybox/web/routes/forms.py:57 +#: surveybox/web/routes/forms.py:59 msgid "The password must be between 6 and 200 characters long." msgstr "" -#: surveybox/web/routes/forms.py:58 +#: surveybox/web/routes/forms.py:60 msgid "Please set a password for access via link." msgstr "" -#: surveybox/web/routes/forms.py:59 +#: surveybox/web/routes/forms.py:61 #: surveybox/web/templates/form_settings.html:53 msgid "Anonymity cannot be changed once answers exist." msgstr "" -#: surveybox/web/routes/forms.py:60 +#: surveybox/web/routes/forms.py:62 #: surveybox/web/templates/admin_settings.html:65 msgid "The retention period must be between 1 and 3650 days." msgstr "" -#: surveybox/web/routes/forms.py:61 +#: surveybox/web/routes/forms.py:63 msgid "Please enter the text the participants consent to." msgstr "" -#: surveybox/web/routes/forms.py:62 +#: surveybox/web/routes/forms.py:64 msgid "Unknown status." msgstr "" -#: surveybox/web/routes/forms.py:63 +#: surveybox/web/routes/forms.py:65 msgid "Add at least one question before opening the form." msgstr "" -#: surveybox/web/routes/forms.py:64 +#: surveybox/web/routes/forms.py:66 msgid "Unknown question type." msgstr "" -#: surveybox/web/routes/forms.py:65 +#: surveybox/web/routes/forms.py:67 msgid "The form has reached the maximum number of questions." msgstr "" -#: surveybox/web/routes/forms.py:66 +#: surveybox/web/routes/forms.py:68 msgid "Please enter the question text." msgstr "" -#: surveybox/web/routes/forms.py:67 +#: surveybox/web/routes/forms.py:69 msgid "The question text is too long." msgstr "" -#: surveybox/web/routes/forms.py:68 +#: surveybox/web/routes/forms.py:70 msgid "Please enter at least two options." msgstr "" -#: surveybox/web/routes/forms.py:69 +#: surveybox/web/routes/forms.py:71 msgid "Too many options (at most 100)." msgstr "" -#: surveybox/web/routes/forms.py:70 +#: surveybox/web/routes/forms.py:72 msgid "Please check the numbers in the settings." msgstr "" -#: surveybox/web/routes/forms.py:71 +#: surveybox/web/routes/forms.py:73 msgid "The minimum must not be greater than the maximum." msgstr "" -#: surveybox/web/routes/forms.py:72 +#: surveybox/web/routes/forms.py:74 msgid "Please enter valid dates." msgstr "" -#: surveybox/web/routes/forms.py:74 +#: surveybox/web/routes/forms.py:76 msgid "Please allow at least one file type." msgstr "" -#: surveybox/web/routes/forms.py:75 +#: surveybox/web/routes/forms.py:77 msgid "A rule may only refer to an earlier question with an answer." msgstr "" -#: surveybox/web/routes/forms.py:76 +#: surveybox/web/routes/forms.py:78 msgid "This comparison does not fit the chosen question." msgstr "" -#: surveybox/web/routes/forms.py:77 +#: surveybox/web/routes/forms.py:79 msgid "Please check the value of the rule." msgstr "" -#: surveybox/web/routes/forms.py:78 +#: surveybox/web/routes/forms.py:80 msgid "At most 20 rules per condition." msgstr "" -#: surveybox/web/routes/forms.py:80 +#: surveybox/web/routes/forms.py:82 msgid "This order is not possible: a condition would refer to a later question." msgstr "" -#: surveybox/web/routes/forms.py:82 +#: surveybox/web/routes/forms.py:84 msgid "A template cannot be published. Create a form from it." msgstr "" -#: surveybox/web/routes/forms.py:83 +#: surveybox/web/routes/forms.py:85 msgid "Please choose one of your groups." msgstr "" -#: surveybox/web/routes/forms.py:84 +#: surveybox/web/routes/forms.py:86 msgid "The number of places per person must be between 1 and 1000." msgstr "" -#: surveybox/web/routes/forms.py:85 +#: surveybox/web/routes/forms.py:87 msgid "Please choose which kind of questions the group holds." msgstr "" -#: surveybox/web/routes/forms.py:86 +#: surveybox/web/routes/forms.py:88 msgid "Please enter a valid reply-to address (without a name)." msgstr "" -#: surveybox/web/routes/forms.py:87 +#: surveybox/web/routes/forms.py:89 msgid "The reminder must be between 1 and 30 days before the end." msgstr "" -#: surveybox/web/routes/forms.py:89 +#: surveybox/web/routes/forms.py:91 msgid "" "“All signed-in users” is reserved for instance-wide roles. Choose groups " "or a link." msgstr "" -#: surveybox/web/routes/forms.py:94 +#: surveybox/web/routes/forms.py:96 msgid "Draft" msgstr "" -#: surveybox/web/routes/forms.py:95 +#: surveybox/web/routes/forms.py:97 msgid "Scheduled" msgstr "" -#: surveybox/web/routes/forms.py:96 +#: surveybox/web/routes/forms.py:98 msgid "Open" msgstr "" -#: surveybox/web/routes/forms.py:97 +#: surveybox/web/routes/forms.py:99 msgid "Closed" msgstr "" -#: surveybox/web/routes/forms.py:101 +#: surveybox/web/routes/forms.py:103 msgid "All signed-in users" msgstr "" -#: surveybox/web/routes/forms.py:102 +#: surveybox/web/routes/forms.py:104 msgid "Selected users and groups" msgstr "" -#: surveybox/web/routes/forms.py:103 +#: surveybox/web/routes/forms.py:105 msgid "Anyone with the link, also without an account" msgstr "" -#: surveybox/web/routes/forms.py:104 +#: surveybox/web/routes/forms.py:106 msgid "Anyone with the link and the password" msgstr "" -#: surveybox/web/routes/forms.py:110 +#: surveybox/web/routes/forms.py:112 msgid "Please describe the image in a few words (for screen readers)." msgstr "" -#: surveybox/web/routes/forms.py:111 +#: surveybox/web/routes/forms.py:113 msgid "At most 12 images per question." msgstr "" -#: surveybox/web/routes/forms.py:112 +#: surveybox/web/routes/forms.py:114 msgid "Please choose a video file." msgstr "" -#: surveybox/web/routes/forms.py:113 +#: surveybox/web/routes/forms.py:115 msgid "This video address was not recognised." msgstr "" -#: surveybox/web/routes/forms.py:115 +#: surveybox/web/routes/forms.py:117 msgid "" "Videos from this provider are not enabled. An administrator can enable " "them." msgstr "" -#: surveybox/web/routes/forms.py:120 +#: surveybox/web/routes/forms.py:122 #: surveybox/web/templates/form_responses.html:160 msgid "PDF" msgstr "" -#: surveybox/web/routes/forms.py:121 +#: surveybox/web/routes/forms.py:123 msgid "Images (JPEG, PNG, WebP)" msgstr "" -#: surveybox/web/routes/forms.py:122 +#: surveybox/web/routes/forms.py:124 msgid "Office documents (Word, Excel, PowerPoint, OpenDocument)" msgstr "" -#: surveybox/web/routes/forms.py:123 +#: surveybox/web/routes/forms.py:125 msgid "Text and CSV" msgstr "" -#: surveybox/web/routes/forms.py:124 +#: surveybox/web/routes/forms.py:126 msgid "ZIP archives" msgstr "" @@ -1830,14 +2032,6 @@ msgstr "" msgid "Registration is switched off." msgstr "" -#: surveybox/web/templates/_comments.html:4 -#: surveybox/web/templates/form_comments.html:2 -#: surveybox/web/templates/form_comments.html:6 -#: surveybox/web/templates/form_designer.html:28 -#: surveybox/web/templates/form_settings.html:99 -msgid "Comments" -msgstr "" - #: surveybox/web/templates/_comments.html:10 msgid "edited" msgstr "" @@ -1864,10 +2058,11 @@ msgstr "" #: surveybox/web/templates/admin_mail_template_edit.html:24 #: surveybox/web/templates/admin_settings.html:60 #: surveybox/web/templates/admin_settings.html:71 +#: surveybox/web/templates/admin_settings.html:85 #: surveybox/web/templates/admin_user_edit.html:21 #: surveybox/web/templates/followup_edit.html:57 #: surveybox/web/templates/form_access.html:26 -#: surveybox/web/templates/form_designer.html:44 +#: surveybox/web/templates/form_designer.html:50 #: surveybox/web/templates/personal.html:59 #: surveybox/web/templates/question_edit.html:276 #: surveybox/web/templates/question_edit.html:298 @@ -2506,7 +2701,8 @@ msgstr "" #: surveybox/web/templates/admin_settings.html:2 #: surveybox/web/templates/admin_settings.html:5 #: surveybox/web/templates/base.html:53 -#: surveybox/web/templates/form_designer.html:21 +#: surveybox/web/templates/form_designer.html:26 +#: surveybox/web/templates/form_history_compare.html:29 #: surveybox/web/templates/form_responses.html:8 #: surveybox/web/templates/form_settings.html:2 #: surveybox/web/templates/form_settings.html:10 @@ -2782,6 +2978,7 @@ msgid "Action" msgstr "" #: surveybox/web/templates/admin_audit.html:10 +#: surveybox/web/templates/form_history.html:20 msgid "By" msgstr "" @@ -2800,13 +2997,7 @@ msgid "Guest address no. %(n)s" msgstr "" #: surveybox/web/templates/admin_audit.html:24 -#: surveybox/web/templates/form_settings.html:25 -#: surveybox/web/templates/form_team.html:15 -#: surveybox/web/templates/forms_list.html:54 -msgid "Group" -msgstr "" - -#: surveybox/web/templates/admin_audit.html:24 +#: surveybox/web/templates/form_history_compare.html:62 msgid "deleted" msgstr "" @@ -3366,6 +3557,44 @@ msgid "" "is deleted." msgstr "" +#: surveybox/web/templates/admin_settings.html:75 +msgid "Form history and trash" +msgstr "" + +#: surveybox/web/templates/admin_settings.html:76 +#, python-format +msgid "" +"The history can be kept for %(a)d to %(b)d days, the trash for %(c)d to " +"%(d)d days." +msgstr "" + +#: surveybox/web/templates/admin_settings.html:79 +msgid "Keep saved states of forms for … days" +msgstr "" + +#: surveybox/web/templates/admin_settings.html:81 +msgid "" +"States are saved before changes to questions, options, settings and " +"access, before managers change or delete answers, and once a day if a " +"form changed. Managers use them to restore individual questions, options," +" settings or answers. They contain the answers, so they never outlast " +"them: when a form is deleted or its retention period ends, its states are" +" deleted too." +msgstr "" + +#: surveybox/web/templates/admin_settings.html:82 +msgid "Keep deleted forms in the trash for … days" +msgstr "" + +#: surveybox/web/templates/admin_settings.html:84 +msgid "" +"During this time the owner, the person who deleted it, group " +"administrators and administrators can restore a deleted form with all " +"questions and answers. Afterwards it is deleted for good. If a person is " +"deleted, their answers are also removed from the trash and the history at" +" once." +msgstr "" + #: surveybox/web/templates/admin_user_delete.html:3 #: surveybox/web/templates/admin_user_edit.html:72 msgid "Delete user" @@ -3870,7 +4099,7 @@ msgid "Follow-up email" msgstr "" #: surveybox/web/templates/followup_edit.html:7 -#: surveybox/web/templates/form_designer.html:27 +#: surveybox/web/templates/form_designer.html:33 #: surveybox/web/templates/form_followups.html:2 #: surveybox/web/templates/form_followups.html:7 msgid "Follow-up emails" @@ -4161,12 +4390,6 @@ msgstr "" msgid "Access" msgstr "" -#: surveybox/web/templates/form_access.html:6 -#: surveybox/web/templates/form_designer.html:64 -#: surveybox/web/templates/form_settings.html:35 -msgid "Who may fill in" -msgstr "" - #: surveybox/web/templates/form_access.html:7 msgid "" "Choose groups and individual users. Members of a chosen group always have" @@ -4186,195 +4409,209 @@ msgid "All forms" msgstr "" #: surveybox/web/templates/form_designer.html:10 +#: surveybox/web/templates/forms_list.html:40 msgid "Template" msgstr "" -#: surveybox/web/templates/form_designer.html:22 +#: surveybox/web/templates/form_designer.html:20 +#: surveybox/web/templates/form_history.html:9 +msgid "More places are booked than available:" +msgstr "" + +#: surveybox/web/templates/form_designer.html:27 #: surveybox/web/templates/form_preview.html:2 #: surveybox/web/templates/form_preview.html:8 msgid "Live preview" msgstr "" -#: surveybox/web/templates/form_designer.html:26 +#: surveybox/web/templates/form_designer.html:31 #: surveybox/web/templates/form_team.html:2 #: surveybox/web/templates/form_team.html:6 msgid "Team" msgstr "" -#: surveybox/web/templates/form_designer.html:28 +#: surveybox/web/templates/form_designer.html:32 +#: surveybox/web/templates/form_history.html:2 +#: surveybox/web/templates/form_history.html:6 +#: surveybox/web/templates/form_history_compare.html:2 +#: surveybox/web/templates/form_history_compare.html:13 +msgid "History" +msgstr "" + +#: surveybox/web/templates/form_designer.html:34 #, python-format msgid "%(num)d new" msgid_plural "%(num)d new" msgstr[0] "" msgstr[1] "" -#: surveybox/web/templates/form_designer.html:31 +#: surveybox/web/templates/form_designer.html:37 msgid "Copy template" msgstr "" -#: surveybox/web/templates/form_designer.html:31 +#: surveybox/web/templates/form_designer.html:37 msgid "Copy" msgstr "" -#: surveybox/web/templates/form_designer.html:35 +#: surveybox/web/templates/form_designer.html:41 msgid "Save as template" msgstr "" -#: surveybox/web/templates/form_designer.html:43 +#: surveybox/web/templates/form_designer.html:49 msgid "Available to all creators" msgstr "" -#: surveybox/web/templates/form_designer.html:52 +#: surveybox/web/templates/form_designer.html:58 msgid "Publish" msgstr "" -#: surveybox/web/templates/form_designer.html:55 +#: surveybox/web/templates/form_designer.html:61 msgid "Close" msgstr "" -#: surveybox/web/templates/form_designer.html:58 +#: surveybox/web/templates/form_designer.html:64 msgid "Reopen" msgstr "" -#: surveybox/web/templates/form_designer.html:65 +#: surveybox/web/templates/form_designer.html:71 msgid "Opens" msgstr "" -#: surveybox/web/templates/form_designer.html:66 +#: surveybox/web/templates/form_designer.html:72 msgid "Closes" msgstr "" -#: surveybox/web/templates/form_designer.html:67 +#: surveybox/web/templates/form_designer.html:73 msgid "Link" msgstr "" -#: surveybox/web/templates/form_designer.html:70 +#: surveybox/web/templates/form_designer.html:76 msgid "Available after publishing." msgstr "" -#: surveybox/web/templates/form_designer.html:76 +#: surveybox/web/templates/form_designer.html:82 msgid "Embed" msgstr "" -#: surveybox/web/templates/form_designer.html:78 +#: surveybox/web/templates/form_designer.html:84 msgid "" "Only on pages that the administrator has allowed for embedding and that " "belong to the same domain (e.g. the Nextcloud). Elsewhere, browsers block" " the cookies the form needs: link to the form there instead." msgstr "" -#: surveybox/web/templates/form_designer.html:84 +#: surveybox/web/templates/form_designer.html:90 msgid "Questions" msgstr "" -#: surveybox/web/templates/form_designer.html:86 +#: surveybox/web/templates/form_designer.html:92 msgid "No questions yet. Add the first one below." msgstr "" -#: surveybox/web/templates/form_designer.html:88 +#: surveybox/web/templates/form_designer.html:94 msgid "Order saved." msgstr "" -#: surveybox/web/templates/form_designer.html:92 +#: surveybox/web/templates/form_designer.html:98 msgid "Drag to move, or use the arrow keys" msgstr "" -#: surveybox/web/templates/form_designer.html:92 +#: surveybox/web/templates/form_designer.html:98 msgid "Drag to move" msgstr "" -#: surveybox/web/templates/form_designer.html:95 +#: surveybox/web/templates/form_designer.html:101 msgid "required" msgstr "" -#: surveybox/web/templates/form_designer.html:96 +#: surveybox/web/templates/form_designer.html:102 msgid "personal data" msgstr "" -#: surveybox/web/templates/form_designer.html:98 +#: surveybox/web/templates/form_designer.html:104 msgid "Images" msgstr "" -#: surveybox/web/templates/form_designer.html:98 +#: surveybox/web/templates/form_designer.html:104 msgid "Video" msgstr "" -#: surveybox/web/templates/form_designer.html:99 +#: surveybox/web/templates/form_designer.html:105 #: surveybox/web/templates/question_edit.html:165 #: surveybox/web/templates/question_edit.html:171 msgid "Image tiles" msgstr "" -#: surveybox/web/templates/form_designer.html:100 +#: surveybox/web/templates/form_designer.html:106 #, python-format msgid "controls %(num)d condition" msgid_plural "controls %(num)d conditions" msgstr[0] "" msgstr[1] "" -#: surveybox/web/templates/form_designer.html:107 +#: surveybox/web/templates/form_designer.html:113 #, python-format msgid "%(num)d question" msgid_plural "%(num)d questions" msgstr[0] "" msgstr[1] "" -#: surveybox/web/templates/form_designer.html:108 +#: surveybox/web/templates/form_designer.html:114 #, python-format msgid "at least %(n)s required" msgstr "" -#: surveybox/web/templates/form_designer.html:109 +#: surveybox/web/templates/form_designer.html:115 #, python-format msgid "at most %(n)s selectable" msgstr "" -#: surveybox/web/templates/form_designer.html:110 +#: surveybox/web/templates/form_designer.html:116 msgid "No questions yet: add questions of this type directly below the group." msgstr "" -#: surveybox/web/templates/form_designer.html:118 +#: surveybox/web/templates/form_designer.html:124 #: surveybox/web/templates/question_edit.html:226 msgid "Applies to the whole page." msgstr "" -#: surveybox/web/templates/form_designer.html:118 +#: surveybox/web/templates/form_designer.html:124 #: surveybox/web/templates/question_edit.html:227 msgid "Applies to the whole section up to the next heading or page." msgstr "" -#: surveybox/web/templates/form_designer.html:118 +#: surveybox/web/templates/form_designer.html:124 #: surveybox/web/templates/question_edit.html:228 msgid "Applies to all questions of the group." msgstr "" -#: surveybox/web/templates/form_designer.html:123 +#: surveybox/web/templates/form_designer.html:129 msgid "Edit" msgstr "" -#: surveybox/web/templates/form_designer.html:125 +#: surveybox/web/templates/form_designer.html:131 msgid "Add question to group" msgstr "" -#: surveybox/web/templates/form_designer.html:130 +#: surveybox/web/templates/form_designer.html:136 #: surveybox/web/templates/question_edit.html:299 msgid "Move up" msgstr "" -#: surveybox/web/templates/form_designer.html:136 +#: surveybox/web/templates/form_designer.html:142 #: surveybox/web/templates/question_edit.html:300 msgid "Move down" msgstr "" -#: surveybox/web/templates/form_designer.html:144 +#: surveybox/web/templates/form_designer.html:150 msgid "Question type" msgstr "" -#: surveybox/web/templates/form_designer.html:148 +#: surveybox/web/templates/form_designer.html:154 msgid "Add question" msgstr "" -#: surveybox/web/templates/form_designer.html:150 +#: surveybox/web/templates/form_designer.html:156 msgid "" "Questions that should appear only in certain cases (e.g. “How many " "people?” only after “Yes”): add the question, open it with “Edit” and set" @@ -4420,6 +4657,179 @@ msgstr[1] "" msgid "No follow-up emails yet." msgstr "" +#: surveybox/web/templates/form_history.html:11 +msgid "" +"Nobody was moved to the waiting list. Raise the number of places or " +"contact the people concerned." +msgstr "" + +#: surveybox/web/templates/form_history.html:15 +msgid "" +"Surveybox saves the state of this form before questions, options, " +"settings or access are changed, before a manager changes or deletes an " +"answer, and once a day if anything changed. Choose a state to see what " +"differs from now and to restore individual questions, options, settings " +"or answers. Everything else stays as it is." +msgstr "" + +#: surveybox/web/templates/form_history.html:16 +#, python-format +msgid "" +"States are kept for %(num)d day, at most as long as the answers " +"themselves." +msgid_plural "" +"States are kept for %(num)d days, at most as long as the answers " +"themselves." +msgstr[0] "" +msgstr[1] "" + +#: surveybox/web/templates/form_history.html:16 +msgid "" +"Changes and deletions by participants themselves are not restored; what " +"participants delete also disappears from the history." +msgstr "" + +#: surveybox/web/templates/form_history.html:20 +msgid "Saved" +msgstr "" + +#: surveybox/web/templates/form_history.html:20 +msgid "Occasion" +msgstr "" + +#: surveybox/web/templates/form_history.html:27 +msgid "Compare" +msgstr "" + +#: surveybox/web/templates/form_history.html:34 +msgid "No states yet. The first one is saved with the next change." +msgstr "" + +#: surveybox/web/templates/form_history_compare.html:5 +msgid "empty" +msgstr "" + +#: surveybox/web/templates/form_history_compare.html:14 +#, python-format +msgid "State of %(date)s" +msgstr "" + +#: surveybox/web/templates/form_history_compare.html:20 +msgid "" +"Nothing in this state differs from the form as it is now in a way that " +"can be restored." +msgstr "" + +#: surveybox/web/templates/form_history_compare.html:25 +msgid "" +"Choose what to restore. Only the chosen items change; questions, answers " +"and settings that are not chosen stay as they are now." +msgstr "" + +#: surveybox/web/templates/form_history_compare.html:35 +msgid "Access for people and groups" +msgstr "" + +#: surveybox/web/templates/form_history_compare.html:36 +#, python-format +msgid "Then: %(old)d entries, now: %(new)d entries" +msgstr "" + +#: surveybox/web/templates/form_history_compare.html:41 +msgid "Then" +msgstr "" + +#: surveybox/web/templates/form_history_compare.html:42 +msgid "Now" +msgstr "" + +#: surveybox/web/templates/form_history_compare.html:45 +#: surveybox/web/templates/form_history_compare.html:65 +msgid "changed" +msgstr "" + +#: surveybox/web/templates/form_history_compare.html:56 +msgid "Questions and options" +msgstr "" + +#: surveybox/web/templates/form_history_compare.html:63 +#, python-format +msgid "With %(num)d answer" +msgid_plural "With %(num)d answers" +msgstr[0] "" +msgstr[1] "" + +#: surveybox/web/templates/form_history_compare.html:63 +#: surveybox/web/templates/form_history_compare.html:69 +#: surveybox/web/templates/form_history_compare.html:87 +#, python-format +msgid "%(num)d booked place" +msgid_plural "%(num)d booked places" +msgstr[0] "" +msgstr[1] "" + +#: surveybox/web/templates/form_history_compare.html:66 +msgid "" +"Text, settings and options as they were then. Options added since are " +"kept; removed options are listed separately." +msgstr "" + +#: surveybox/web/templates/form_history_compare.html:68 +msgid "option removed" +msgstr "" + +#: surveybox/web/templates/form_history_compare.html:69 +#, python-format +msgid "Question: %(question)s" +msgstr "" + +#: surveybox/web/templates/form_history_compare.html:84 +msgid "Answer without name" +msgstr "" + +#: surveybox/web/templates/form_history_compare.html:86 +msgid "deleted by a manager" +msgstr "" + +#: surveybox/web/templates/form_history_compare.html:87 +#, python-format +msgid "Submitted %(date)s" +msgstr "" + +#: surveybox/web/templates/form_history_compare.html:87 +#, python-format +msgid "%(num)d answered question" +msgid_plural "%(num)d answered questions" +msgstr[0] "" +msgstr[1] "" + +#: surveybox/web/templates/form_history_compare.html:89 +msgid "changed by a manager" +msgstr "" + +#: surveybox/web/templates/form_history_compare.html:90 +#, python-format +msgid "Changed %(date)s" +msgstr "" + +#: surveybox/web/templates/form_history_compare.html:90 +#, python-format +msgid "%(num)d question differs" +msgid_plural "%(num)d questions differ" +msgstr[0] "" +msgstr[1] "" + +#: surveybox/web/templates/form_history_compare.html:98 +msgid "" +"Before restoring, the current state is saved too, so this step can be " +"undone in the history. Booked places are restored even if there are not " +"enough places any more; the option is then shown as overbooked." +msgstr "" + +#: surveybox/web/templates/form_history_compare.html:99 +msgid "Restore selected" +msgstr "" + #: surveybox/web/templates/form_preview.html:10 msgid "Phone" msgstr "" @@ -4578,6 +4988,11 @@ msgstr "" msgid "Signed up" msgstr "" +#: surveybox/web/templates/form_responses.html:107 +#: surveybox/web/templates/form_responses.html:121 +msgid "overbooked" +msgstr "" + #: surveybox/web/templates/form_responses.html:121 #: surveybox/web/templates/results_public.html:39 #, python-format @@ -4667,26 +5082,8 @@ msgstr "" msgid "General" msgstr "" -#: surveybox/web/templates/form_settings.html:16 -#: surveybox/web/templates/forms_list.html:9 -#: surveybox/web/templates/forms_list.html:51 -msgid "Title" -msgstr "" - -#: surveybox/web/templates/form_settings.html:18 -msgid "Description (optional)" -msgstr "" - -#: surveybox/web/templates/form_settings.html:20 -msgid "Opens at (optional)" -msgstr "" - -#: surveybox/web/templates/form_settings.html:22 -msgid "Closes at (optional)" -msgstr "" - #: surveybox/web/templates/form_settings.html:27 -#: surveybox/web/templates/forms_list.html:56 +#: surveybox/web/templates/forms_list.html:83 msgid "no group (instance-wide)" msgstr "" @@ -4696,10 +5093,6 @@ msgid "" "too." msgstr "" -#: surveybox/web/templates/form_settings.html:40 -msgid "Password for access via link" -msgstr "" - #: surveybox/web/templates/form_settings.html:43 msgid "A password is set. Leave empty to keep it." msgstr "" @@ -4716,18 +5109,10 @@ msgstr "" msgid "Participation" msgstr "" -#: surveybox/web/templates/form_settings.html:50 -msgid "A person may fill in the form several times" -msgstr "" - #: surveybox/web/templates/form_settings.html:51 msgid "Anonymous: answers are stored without reference to the person" msgstr "" -#: surveybox/web/templates/form_settings.html:54 -msgid "Participants may change their answer" -msgstr "" - #: surveybox/web/templates/form_settings.html:56 msgid "Yes, until the form closes" msgstr "" @@ -4738,12 +5123,6 @@ msgid "" "for anonymous forms." msgstr "" -#: surveybox/web/templates/form_settings.html:60 -msgid "" -"Remind invited people who have not taken part yet … days before the end " -"(empty: no reminder)" -msgstr "" - #: surveybox/web/templates/form_settings.html:62 msgid "" "Only for access “Selected users and groups” and with an end date. Each " @@ -4751,10 +5130,6 @@ msgid "" " their account." msgstr "" -#: surveybox/web/templates/form_settings.html:63 -msgid "Participants see the results" -msgstr "" - #: surveybox/web/templates/form_settings.html:65 msgid "Never" msgstr "" @@ -4781,14 +5156,6 @@ msgstr "" msgid "Places, calendar and comments" msgstr "" -#: surveybox/web/templates/form_settings.html:74 -msgid "Places per person across all participation fields (empty: no limit)" -msgstr "" - -#: surveybox/web/templates/form_settings.html:77 -msgid "Show who has signed up" -msgstr "" - #: surveybox/web/templates/form_settings.html:80 msgid "Yes, first name and initial of the last name" msgstr "" @@ -4805,10 +5172,6 @@ msgid "" "tells participants about it. Not for anonymous forms." msgstr "" -#: surveybox/web/templates/form_settings.html:86 -msgid "Confirmed dates as calendar" -msgstr "" - #: surveybox/web/templates/form_settings.html:87 #: surveybox/web/templates/form_settings.html:100 msgid "Off" @@ -4840,18 +5203,6 @@ msgstr "" msgid "Public: new comments are visible at once" msgstr "" -#: surveybox/web/templates/form_settings.html:103 -msgid "Publish comments without the author’s name (managers still see it)" -msgstr "" - -#: surveybox/web/templates/form_settings.html:104 -msgid "Notify managers about new comments by email" -msgstr "" - -#: surveybox/web/templates/form_settings.html:107 -msgid "Reply-to address for messages about this form (optional)" -msgstr "" - #: surveybox/web/templates/form_settings.html:109 msgid "" "Replies to messages about this form go to this address. Empty: the " @@ -4862,22 +5213,6 @@ msgstr "" msgid "Data protection" msgstr "" -#: surveybox/web/templates/form_settings.html:114 -msgid "Privacy notice shown with the form (optional)" -msgstr "" - -#: surveybox/web/templates/form_settings.html:116 -msgid "Participants must give their consent" -msgstr "" - -#: surveybox/web/templates/form_settings.html:117 -msgid "Consent text" -msgstr "" - -#: surveybox/web/templates/form_settings.html:119 -msgid "Retention period in days after the end of the form" -msgstr "" - #: surveybox/web/templates/form_settings.html:121 #, python-format msgid "" @@ -4895,10 +5230,6 @@ msgstr "" msgid "The answers will be anonymized on %(date)s." msgstr "" -#: surveybox/web/templates/form_settings.html:123 -msgid "When the retention period ends or a participant is deleted" -msgstr "" - #: surveybox/web/templates/form_settings.html:125 msgid "Keep the answer anonymized" msgstr "" @@ -4907,10 +5238,6 @@ msgstr "" msgid "Delete the answer completely" msgstr "" -#: surveybox/web/templates/form_settings.html:128 -msgid "Email address of guests" -msgstr "" - #: surveybox/web/templates/form_settings.html:130 #: surveybox/web/templates/question_edit.html:59 msgid "Do not ask" @@ -4965,11 +5292,22 @@ msgid "Renew link" msgstr "" #: surveybox/web/templates/form_settings.html:159 -#: surveybox/web/templates/form_settings.html:164 +#: surveybox/web/templates/form_settings.html:165 msgid "Delete form" msgstr "" #: surveybox/web/templates/form_settings.html:163 +#, python-format +msgid "" +"The form goes to the trash in the form list. There you can restore it for" +" %(num)d day; after that it is deleted for good." +msgid_plural "" +"The form goes to the trash in the form list. There you can restore it for" +" %(num)d days; after that it is deleted for good." +msgstr[0] "" +msgstr[1] "" + +#: surveybox/web/templates/form_settings.html:164 msgid "Yes, delete this form with all questions and answers." msgstr "" @@ -5009,33 +5347,55 @@ msgstr "" msgid "No forms yet." msgstr "" -#: surveybox/web/templates/forms_list.html:32 -msgid "Templates" +#: surveybox/web/templates/forms_list.html:31 +msgid "Trash" msgstr "" -#: surveybox/web/templates/forms_list.html:37 -msgid "shared" +#: surveybox/web/templates/forms_list.html:33 +msgid "" +"Deleted forms can be restored with all questions and answers until the " +"date shown. After that they are deleted for good." msgstr "" -#: surveybox/web/templates/forms_list.html:39 -msgid "New form from this template" +#: surveybox/web/templates/forms_list.html:36 +msgid "Deleted" msgstr "" -#: surveybox/web/templates/forms_list.html:47 -msgid "New form" +#: surveybox/web/templates/forms_list.html:36 +msgid "Restorable until" +msgstr "" + +#: surveybox/web/templates/forms_list.html:46 +msgid "Restore" msgstr "" #: surveybox/web/templates/forms_list.html:59 +msgid "Templates" +msgstr "" + +#: surveybox/web/templates/forms_list.html:64 +msgid "shared" +msgstr "" + +#: surveybox/web/templates/forms_list.html:66 +msgid "New form from this template" +msgstr "" + +#: surveybox/web/templates/forms_list.html:74 +msgid "New form" +msgstr "" + +#: surveybox/web/templates/forms_list.html:86 msgid "" "The form belongs to this group and is shared with it at first. Its group " "administrators manage it too." msgstr "" -#: surveybox/web/templates/forms_list.html:59 +#: surveybox/web/templates/forms_list.html:86 msgid "Optional. Group administrators of the chosen group manage the form too." msgstr "" -#: surveybox/web/templates/forms_list.html:61 +#: surveybox/web/templates/forms_list.html:88 msgid "Create form" msgstr "" diff --git a/surveybox/media/service.py b/surveybox/media/service.py index 92fe5d2..fb2f7e4 100644 --- a/surveybox/media/service.py +++ b/surveybox/media/service.py @@ -182,8 +182,13 @@ def by_ids(db: Session, form: Form, ids: list[str]) -> dict[str, MediaFile]: def referenced_keys(db: Session) -> set[str]: + """Dateien, die noch gebraucht werden: aus der Datenbank und aus dem Verlauf + der Formulare (dort bleiben sie wiederherstellbar).""" + from surveybox.forms import history + keys = set(db.scalars(select(MediaFile.storage_key))) keys.update(k for k in db.scalars(select(MediaFile.thumb_key)) if k) + keys.update(history.referenced_media_keys(db)) return keys diff --git a/surveybox/migrations/versions/0018_form_history.py b/surveybox/migrations/versions/0018_form_history.py new file mode 100644 index 0000000..b963bfd --- /dev/null +++ b/surveybox/migrations/versions/0018_form_history.py @@ -0,0 +1,83 @@ +# SPDX-License-Identifier: AGPL-3.0-or-later +"""Verlauf von Formularen (Stände zum punktuellen Wiederherstellen) und Papierkorb. + +Revision: 0018_form_history +Vorgänger: 0017_response_note +""" + +from collections.abc import Sequence + +import sqlalchemy as sa +from alembic import op +from sqlalchemy.dialects import postgresql + +revision: str = "0018_form_history" +down_revision: str | None = "0017_response_note" +branch_labels: str | Sequence[str] | None = None +depends_on: str | Sequence[str] | None = None + +EMPTY = sa.text("'[]'::jsonb") + + +def upgrade() -> None: + op.create_table( + "form_snapshot", + sa.Column("id", sa.BigInteger(), autoincrement=True, nullable=False), + sa.Column("form_id", sa.BigInteger(), nullable=False), + sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.text("now()"), + nullable=False), + sa.Column("reason", sa.Text(), nullable=False), + sa.Column("actor_id", sa.BigInteger(), nullable=True), + sa.Column("full_hash", postgresql.BYTEA(), nullable=False), + sa.Column("data_hash", postgresql.BYTEA(), nullable=False), + sa.Column("size", sa.Integer(), nullable=False), + sa.Column("payload", postgresql.BYTEA(), nullable=False), + sa.Column("media_keys", postgresql.JSONB(astext_type=sa.Text()), server_default=EMPTY, + nullable=False), + sa.Column("user_ids", postgresql.JSONB(astext_type=sa.Text()), server_default=EMPTY, + nullable=False), + sa.Column("guest_ids", postgresql.JSONB(astext_type=sa.Text()), server_default=EMPTY, + nullable=False), + sa.ForeignKeyConstraint(["actor_id"], ["user_account.id"], + name=op.f("fk_form_snapshot_actor_id_user_account"), + ondelete="SET NULL"), + sa.PrimaryKeyConstraint("id", name=op.f("pk_form_snapshot")), + ) + op.create_index(op.f("ix_form_snapshot_form_id"), "form_snapshot", ["form_id"]) + op.create_index(op.f("ix_form_snapshot_actor_id"), "form_snapshot", ["actor_id"]) + op.create_table( + "form_trash", + sa.Column("form_id", sa.BigInteger(), nullable=False), + sa.Column("public_id", postgresql.UUID(as_uuid=True), nullable=False), + sa.Column("title", sa.Text(), nullable=False), + sa.Column("owner_id", sa.BigInteger(), nullable=True), + sa.Column("deleted_by", sa.BigInteger(), nullable=True), + sa.Column("deleted_at", sa.DateTime(timezone=True), server_default=sa.text("now()"), + nullable=False), + sa.Column("snapshot_id", sa.BigInteger(), nullable=False), + sa.Column("responses", sa.Integer(), server_default=sa.text("0"), nullable=False), + sa.Column("extra", postgresql.JSONB(astext_type=sa.Text()), + server_default=sa.text("'{}'::jsonb"), nullable=False), + sa.ForeignKeyConstraint(["owner_id"], ["user_account.id"], + name=op.f("fk_form_trash_owner_id_user_account"), + ondelete="SET NULL"), + sa.ForeignKeyConstraint(["deleted_by"], ["user_account.id"], + name=op.f("fk_form_trash_deleted_by_user_account"), + ondelete="SET NULL"), + sa.ForeignKeyConstraint(["snapshot_id"], ["form_snapshot.id"], + name=op.f("fk_form_trash_snapshot_id_form_snapshot"), + ondelete="CASCADE"), + sa.PrimaryKeyConstraint("form_id", name=op.f("pk_form_trash")), + sa.UniqueConstraint("public_id", name=op.f("uq_form_trash_public_id")), + ) + op.create_index(op.f("ix_form_trash_owner_id"), "form_trash", ["owner_id"]) + op.add_column("response", sa.Column("edited_by", sa.Text(), nullable=True)) + + +def downgrade() -> None: + op.drop_column("response", "edited_by") + op.drop_index(op.f("ix_form_trash_owner_id"), table_name="form_trash") + op.drop_table("form_trash") + op.drop_index(op.f("ix_form_snapshot_actor_id"), table_name="form_snapshot") + op.drop_index(op.f("ix_form_snapshot_form_id"), table_name="form_snapshot") + op.drop_table("form_snapshot") diff --git a/surveybox/models/__init__.py b/surveybox/models/__init__.py index e91c96a..58f9e5c 100644 --- a/surveybox/models/__init__.py +++ b/surveybox/models/__init__.py @@ -45,6 +45,7 @@ from surveybox.models.forms import ( Response, ResponseNote, ) +from surveybox.models.history import FormSnapshot, FormTrash from surveybox.models.mail import FormMute, GuestContact, MailMessage, MailStatus from surveybox.models.system import AppSetting, JobState @@ -70,7 +71,9 @@ __all__ = [ "FormMember", "FormMute", "FormParticipation", + "FormSnapshot", "FormStatus", + "FormTrash", "GroupMember", "GroupRole", "GroupRoleKind", diff --git a/surveybox/models/forms.py b/surveybox/models/forms.py index f327848..8184367 100644 --- a/surveybox/models/forms.py +++ b/surveybox/models/forms.py @@ -238,6 +238,9 @@ class Response(Base): access_hash: Mapped[bytes | None] = mapped_column(BYTEA, unique=True) # Nach Ablauf der Löschfrist oder Löschung der Person: ohne Bezug zur Person anonymized_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True)) + # Wer zuletzt geändert hat: participant oder manager (Verlauf: nur Änderungen + # von Verwaltern lassen sich zurücknehmen) + edited_by: Mapped[str | None] = mapped_column(Text) answers: Mapped[list[Answer]] = relationship( back_populates="response", cascade="all, delete-orphan", passive_deletes=True diff --git a/surveybox/models/history.py b/surveybox/models/history.py new file mode 100644 index 0000000..54791d6 --- /dev/null +++ b/surveybox/models/history.py @@ -0,0 +1,78 @@ +# SPDX-License-Identifier: AGPL-3.0-or-later +"""Verlauf von Formularen und Papierkorb. + +Ein Stand (`form_snapshot`) hält ein Formular mit allem, was dazugehört: +Einstellungen, Fragen, Antworten, Buchungen, Vermerke, Medienverweise. Er +verweist absichtlich NICHT per Fremdschlüssel auf `form`: Ein gelöschtes +Formular lebt im Papierkorb aus seinen Ständen weiter, bis die Frist abläuft. +Aufräumen übernimmt der Worker (forms.history.prune). +""" + +from __future__ import annotations + +import uuid +from datetime import datetime +from typing import Any + +from sqlalchemy import BigInteger, DateTime, ForeignKey, Integer, Text, func, text +from sqlalchemy.dialects.postgresql import BYTEA, JSONB, UUID +from sqlalchemy.orm import Mapped, mapped_column + +from surveybox.models.base import Base + + +class FormSnapshot(Base): + __tablename__ = "form_snapshot" + + id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True) + form_id: Mapped[int] = mapped_column(BigInteger, nullable=False, index=True) + created_at: Mapped[datetime] = mapped_column( + DateTime(timezone=True), nullable=False, server_default=func.now() + ) + # Anlass: edit, answer_edit, answer_delete, daily, before_restore, deleted + reason: Mapped[str] = mapped_column(Text, nullable=False) + actor_id: Mapped[int | None] = mapped_column( + BigInteger, ForeignKey("user_account.id", ondelete="SET NULL"), index=True + ) + # Prüfsummen: alles / nur Antworten (Entprellen beim Bearbeiten) + full_hash: Mapped[bytes] = mapped_column(BYTEA, nullable=False) + data_hash: Mapped[bytes] = mapped_column(BYTEA, nullable=False) + size: Mapped[int] = mapped_column(Integer, nullable=False) + # zlib-komprimiertes JSON (forms.history.serialize) + payload: Mapped[bytes] = mapped_column(BYTEA, nullable=False) + # Für das Aufräumen der Dateien und das Löschen von Personen ohne Auspacken + media_keys: Mapped[list[str]] = mapped_column( + JSONB, nullable=False, server_default=text("'[]'::jsonb") + ) + user_ids: Mapped[list[int]] = mapped_column( + JSONB, nullable=False, server_default=text("'[]'::jsonb") + ) + guest_ids: Mapped[list[int]] = mapped_column( + JSONB, nullable=False, server_default=text("'[]'::jsonb") + ) + + +class FormTrash(Base): + """Gelöschtes Formular, das sich bis `expires_at` wiederherstellen lässt.""" + + __tablename__ = "form_trash" + + form_id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=False) + public_id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), nullable=False, unique=True) + title: Mapped[str] = mapped_column(Text, nullable=False) + owner_id: Mapped[int | None] = mapped_column( + BigInteger, ForeignKey("user_account.id", ondelete="SET NULL"), index=True + ) + deleted_by: Mapped[int | None] = mapped_column( + BigInteger, ForeignKey("user_account.id", ondelete="SET NULL") + ) + deleted_at: Mapped[datetime] = mapped_column( + DateTime(timezone=True), nullable=False, server_default=func.now() + ) + snapshot_id: Mapped[int] = mapped_column( + BigInteger, ForeignKey("form_snapshot.id", ondelete="CASCADE"), nullable=False + ) + responses: Mapped[int] = mapped_column(Integer, nullable=False, server_default=text("0")) + extra: Mapped[dict[str, Any]] = mapped_column( + JSONB, nullable=False, server_default=text("'{}'::jsonb") + ) diff --git a/surveybox/web/app.py b/surveybox/web/app.py index 21fd758..815f108 100644 --- a/surveybox/web/app.py +++ b/surveybox/web/app.py @@ -33,6 +33,7 @@ from surveybox.web.routes import ( fill, form_comments, form_followups, + form_history, form_media, form_results, form_team, @@ -156,6 +157,7 @@ def create_app() -> FastAPI: app.include_router(admin_mail_templates.router, dependencies=protected) app.include_router(admin_mail.router, dependencies=protected) app.include_router(groups.router, dependencies=protected) + app.include_router(form_history.router, dependencies=protected) app.include_router(forms.router, dependencies=protected) app.include_router(form_results.router, dependencies=protected) app.include_router(form_team.router, dependencies=protected) diff --git a/surveybox/web/form_deps.py b/surveybox/web/form_deps.py index 8efbab3..7395b49 100644 --- a/surveybox/web/form_deps.py +++ b/surveybox/web/form_deps.py @@ -8,7 +8,7 @@ from typing import Annotated from fastapi import Depends, Request -from surveybox.forms import service +from surveybox.forms import history, service from surveybox.forms.team import Level, level from surveybox.models import Form from surveybox.web.deps import CurrentUser, Db, Forbidden, NotFound @@ -31,3 +31,13 @@ def _form_at(needed: Level) -> Callable[..., Form]: EvalForm = Annotated[Form, Depends(_form_at(Level.EVALUATE))] EditForm = Annotated[Form, Depends(_form_at(Level.EDIT))] OwnForm = Annotated[Form, Depends(_form_at(Level.OWN))] + + +def _changed_form(db: Db, auth: CurrentUser, form: EditForm) -> Form: + """Wie EditForm; vorher entsteht ein Stand im Verlauf (siehe forms.history).""" + history.before_change(db, form, auth.user) + return form + + +# Für Routen, die Fragen, Optionen, Einstellungen oder Freigaben ändern +ChangedForm = Annotated[Form, Depends(_changed_form)] diff --git a/surveybox/web/routes/admin.py b/surveybox/web/routes/admin.py index 3c029e4..149a659 100644 --- a/surveybox/web/routes/admin.py +++ b/surveybox/web/routes/admin.py @@ -91,6 +91,9 @@ ACTION_NAMES: dict[str, str] = { "admin.registration_changed": N_("Self-registration changed"), "admin.privacy_changed": N_("Default retention period changed"), "form.retention_applied": N_("Retention period applied to a form"), + "form.history_restored": N_("Changes restored from the form history"), + "form.trash_restored": N_("Deleted form restored"), + "admin.history_changed": N_("Form history settings changed"), "account.deleted": N_("Account deleted"), "account.exported": N_("Own data downloaded"), "admin.user_exported": N_("Data of a user exported"), diff --git a/surveybox/web/routes/admin_settings.py b/surveybox/web/routes/admin_settings.py index 5335e4d..df3e092 100644 --- a/surveybox/web/routes/admin_settings.py +++ b/surveybox/web/routes/admin_settings.py @@ -10,7 +10,7 @@ from fastapi.responses import RedirectResponse, Response from surveybox import branding from surveybox.accounts import audit, registration -from surveybox.forms import retention +from surveybox.forms import history, retention from surveybox.i18n import N_ from surveybox.media import config as media_config from surveybox.media import images @@ -43,6 +43,11 @@ def settings_page(request: Request, db: Db, settings: AppSettings, _auth: AdminU "registration_levels": REGISTRATION_LEVELS, "retention_days": retention.default_days(db), "retention_error": request.query_params.get("error") == "retention", + "history_days": history.history_days(db), + "trash_days": history.trash_days(db), + "history_range": history.HISTORY_DAYS_RANGE, + "trash_range": history.TRASH_DAYS_RANGE, + "history_error": request.query_params.get("error") == "history", }, ) @@ -113,6 +118,22 @@ def save_privacy(db: Db, auth: AdminUser, fields: FormFields) -> Response: return RedirectResponse("/admin/settings?notice=settings_saved#privacy", status_code=303) +@router.post("/settings/history") +def save_history(db: Db, auth: AdminUser, fields: FormFields) -> Response: + """Aufbewahrung des Verlaufs der Formulare und des Papierkorbs.""" + try: + days = int(_first(fields, "history_days").strip()) + trash = int(_first(fields, "trash_days").strip()) + history.set_days(db, days, trash) + except ValueError: + return RedirectResponse("/admin/settings?error=history#history", status_code=303) + audit.record(db, "admin.history_changed", actor_id=auth.user.id, + target_type="settings", target_id="history", + details={"history_days": days, "trash_days": trash}) + db.commit() + return RedirectResponse("/admin/settings?notice=settings_saved#history", status_code=303) + + REGISTRATION_LEVELS = { "off": N_("Off: only administrators create accounts"), "guests": N_("Guests: people who confirmed their address when taking part via a form link"), @@ -179,6 +200,10 @@ def save_settings( "registration": registration.level(db), "registration_levels": REGISTRATION_LEVELS, "retention_days": retention.default_days(db), + "history_days": history.history_days(db), + "trash_days": history.trash_days(db), + "history_range": history.HISTORY_DAYS_RANGE, + "trash_range": history.TRASH_DAYS_RANGE, }, status_code=400, ) diff --git a/surveybox/web/routes/form_history.py b/surveybox/web/routes/form_history.py new file mode 100644 index 0000000..3b8a325 --- /dev/null +++ b/surveybox/web/routes/form_history.py @@ -0,0 +1,199 @@ +# SPDX-License-Identifier: AGPL-3.0-or-later +"""Verlauf eines Formulars (Stände, Vergleich, punktuelle Wiederherstellung) und +Papierkorb gelöschter Formulare. Siehe forms.history.""" + +from __future__ import annotations + +from datetime import UTC, datetime +from typing import Any + +from fastapi import APIRouter, Request +from fastapi.responses import RedirectResponse, Response +from sqlalchemy import select + +from surveybox.accounts import audit +from surveybox.forms import history +from surveybox.i18n import N_, gettext +from surveybox.models import Form as FormModel +from surveybox.models import FormSnapshot, FormTrash, UserAccount +from surveybox.web.deps import AppSettings, CurrentUser, Db, FormFields, NotFound, UserScope +from surveybox.web.form_deps import EditForm +from surveybox.web.templating import render + +router = APIRouter(prefix="/forms", include_in_schema=False) + +REASON_NAMES = { + "edit": N_("Before a change to questions or settings"), + "answer_edit": N_("Before an answer was changed by a manager"), + "answer_delete": N_("Before an answer was deleted by a manager"), + "daily": N_("Daily"), + "before_restore": N_("Before a restore"), + "deleted": N_("When the form was deleted"), +} + +# Bezeichnungen wie auf der Seite Einstellungen +SETTING_NAMES = { + "title": N_("Title"), + "description": N_("Description (optional)"), + "opens_at": N_("Opens at (optional)"), + "closes_at": N_("Closes at (optional)"), + "access": N_("Who may fill in"), + "link_password_hash": N_("Password for access via link"), + "allow_multiple": N_("A person may fill in the form several times"), + "allow_edit": N_("Participants may change their answer"), + "guest_email": N_("Email address of guests"), + "results_visibility": N_("Participants see the results"), + "retention_days": N_("Retention period in days after the end of the form"), + "deletion_mode": N_("When the retention period ends or a participant is deleted"), + "privacy_notice": N_("Privacy notice shown with the form (optional)"), + "require_consent": N_("Participants must give their consent"), + "consent_text": N_("Consent text"), + "slot_names": N_("Show who has signed up"), + "slots_max_per_person": N_( + "Places per person across all participation fields (empty: no limit)"), + "reminder_days": N_( + "Remind invited people who have not taken part yet … days before the end " + "(empty: no reminder)" + ), + "calendar_mode": N_("Confirmed dates as calendar"), + "comments_mode": N_("Comments"), + "comments_anonymous": N_( + "Publish comments without the author’s name (managers still see it)"), # noqa: RUF001 + "reply_to": N_("Reply-to address for messages about this form (optional)"), + "comments_notify": N_("Notify managers about new comments by email"), + "group_id": N_("Group"), +} +# Werte, die als Text gezeigt werden; bei den übrigen nur „geändert“ +SHOWN_VALUES = {"title", "description", "opens_at", "closes_at", "allow_multiple", + "retention_days", "privacy_notice", "require_consent", "consent_text", + "slots_max_per_person", "reminder_days", "comments_anonymous", "reply_to", + "comments_notify"} + +ERRORS = { + "nothing_selected": N_("Please choose at least one change to restore."), + "trash_gone": N_("This form can no longer be restored."), +} + + +def _names(db: Db, ids: set[int]) -> dict[int, str]: + if not ids: + return {} + return {u.id: u.display_name for u in db.scalars( + select(UserAccount).where(UserAccount.id.in_(ids)))} + + +def _value(name: str, value: Any) -> Any: + """Für die Anzeige: Text, Zahl, Datum, ja/nein; None = nicht anzeigen.""" + if name not in SHOWN_VALUES: + return None + if isinstance(value, str) and len(value) > 200: + return value[:200] + "…" + return value + + +# -------------------------------------------------------------------------- +# Verlauf eines Formulars +# -------------------------------------------------------------------------- + + +@router.get("/{public_id}/history") +def history_page(request: Request, db: Db, form: EditForm) -> Response: + found = history.snapshots(db, form.id) + return render(request, "form_history.html", { + "form": form, + "snapshots": found, + "actors": _names(db, {s.actor_id for s in found if s.actor_id}), + "reason_names": REASON_NAMES, + "history_days": history.history_days(db), + "overbooked": history.overbooked(db, form), + }) + + +def _snapshot(db: Db, form: FormModel, snapshot_id: int) -> FormSnapshot: + snapshot = history.find_snapshot(db, form.id, snapshot_id) + if snapshot is None: + raise NotFound() + return snapshot + + +def _compare_page(request: Request, db: Db, form: FormModel, snapshot: FormSnapshot, + **extra: Any) -> Response: + status_code = int(extra.pop("status_code", 200)) + comparison = history.compare(db, form, snapshot) + for item in comparison.settings: + if item.kind == "setting": + item.title = SETTING_NAMES.get(item.setting, item.setting) + item.old = _value(item.setting, item.old) + item.new = _value(item.setting, item.new) + return render(request, "form_history_compare.html", { + "form": form, + "snapshot": snapshot, + "comparison": comparison, + "actor": _names(db, {snapshot.actor_id} if snapshot.actor_id else set()).get( + snapshot.actor_id or 0), + "reason_names": REASON_NAMES, + "selected": set(extra.pop("selected", [])), + **extra, + }, status_code=status_code) + + +@router.get("/{public_id}/history/{snapshot_id}") +def compare_page(request: Request, db: Db, form: EditForm, snapshot_id: int) -> Response: + return _compare_page(request, db, form, _snapshot(db, form, snapshot_id)) + + +@router.post("/{public_id}/history/{snapshot_id}/restore") +def restore( + request: Request, db: Db, settings: AppSettings, auth: CurrentUser, form: EditForm, + snapshot_id: int, fields: FormFields, +) -> Response: + snapshot = _snapshot(db, form, snapshot_id) + keys = [k for k in fields.get("item") or [] if len(k) <= 100][:500] + when = snapshot.created_at.astimezone(settings.tz) + note = gettext("Restored from the form history (state of %(date)s).") % { + "date": when.strftime("%Y-%m-%d %H:%M")} + try: + outcome = history.restore(db, form, snapshot, keys, auth.user, note) + except history.HistoryError as exc: + db.rollback() + return _compare_page(request, db, form, snapshot, error=ERRORS.get(exc.code, exc.code), + selected=keys, status_code=400) + audit.record(db, "form.history_restored", actor_id=auth.user.id, target_type="form", + target_id=form.id, details={"snapshot": snapshot.id, + "items": outcome.restored, + "overbooked": len(outcome.overbooked)}) + db.commit() + return RedirectResponse(f"/forms/{form.public_id}/history?notice=history_restored", + status_code=303) + + +# -------------------------------------------------------------------------- +# Papierkorb +# -------------------------------------------------------------------------- + + +def trash_entries(db: Db, user: UserAccount, managed: frozenset[int]) -> list[dict[str, Any]]: + """Für die Formularliste: gelöschte Formulare, die die Person zurückholen darf.""" + now = datetime.now(UTC) + entries = [] + for entry in history.visible_trash(db, user, managed): + expires = history.expires_at(db, entry) + entries.append({"entry": entry, "expires": expires, + "days": max((expires - now).days, 0)}) + return entries + + +@router.post("/trash/{public_id}/restore") +def restore_trashed(db: Db, auth: CurrentUser, found: UserScope, public_id: str) -> Response: + entry: FormTrash | None = history.find_trash(db, auth.user, found.managed, public_id) + if entry is None: + raise NotFound() + try: + form = history.restore_trashed(db, entry, auth.user) + except history.HistoryError: + db.rollback() + return RedirectResponse("/forms?problem=trash_gone", status_code=303) + audit.record(db, "form.trash_restored", actor_id=auth.user.id, target_type="form", + target_id=form.id) + db.commit() + return RedirectResponse(f"/forms/{form.public_id}?notice=form_restored", status_code=303) diff --git a/surveybox/web/routes/form_media.py b/surveybox/web/routes/form_media.py index e372de9..2aa2e11 100644 --- a/surveybox/web/routes/form_media.py +++ b/surveybox/web/routes/form_media.py @@ -17,7 +17,7 @@ from surveybox.media.service import MediaError from surveybox.models import Form as FormModel from surveybox.models import MediaKind, Question from surveybox.web.deps import AppSettings, Db, NotFound -from surveybox.web.form_deps import EditForm, EvalForm +from surveybox.web.form_deps import ChangedForm, EvalForm from surveybox.web.media_response import media_response router = APIRouter(prefix="/forms", include_in_schema=False) @@ -76,7 +76,7 @@ def _clean_alt(value: str) -> str: def add_image( db: Db, settings: AppSettings, - form: EditForm, + form: ChangedForm, question_id: int, image: UploadFile, alt: Text = "", @@ -110,7 +110,7 @@ def add_image( @router.post("/{public_id}/questions/{question_id}/media/image/{media_id}") def update_image( db: Db, - form: EditForm, + form: ChangedForm, question_id: int, media_id: str, action: Annotated[str, Form(max_length=10)], @@ -145,7 +145,7 @@ def update_image( def add_video( db: Db, settings: AppSettings, - form: EditForm, + form: ChangedForm, question_id: int, video: UploadFile | None = None, poster: UploadFile | None = None, @@ -198,7 +198,7 @@ def add_video( @router.post("/{public_id}/questions/{question_id}/media/video/remove") def remove_video_part( - db: Db, form: EditForm, question_id: int, part: Annotated[str, Form(max_length=10)] + db: Db, form: ChangedForm, question_id: int, part: Annotated[str, Form(max_length=10)] ) -> Response: question = _question(form, question_id) current = dict(question.config.get("media") or {}) @@ -216,7 +216,7 @@ def remove_video_part( def add_embed( db: Db, settings: AppSettings, - form: EditForm, + form: ChangedForm, question_id: int, url: Annotated[str, Form(max_length=500)], title: Text = "", @@ -234,7 +234,7 @@ def add_embed( @router.post("/{public_id}/questions/{question_id}/media/clear") -def clear_media(db: Db, form: EditForm, question_id: int) -> Response: +def clear_media(db: Db, form: ChangedForm, question_id: int) -> Response: question = _question(form, question_id) _set_media(question, None) media_service.drop_unused(db, question) diff --git a/surveybox/web/routes/form_results.py b/surveybox/web/routes/form_results.py index 2027867..774af50 100644 --- a/surveybox/web/routes/form_results.py +++ b/surveybox/web/routes/form_results.py @@ -15,6 +15,7 @@ from surveybox.forms import ( erasure, evaluation, export, + history, notes, pdf_export, retention, @@ -200,11 +201,13 @@ def delete_response( f"/forms/{form.public_id}/responses/{response_id}?error=confirm#delete", status_code=303) public_id = response.public_id - erasure.delete_response(db, settings, response) + history.before_change(db, form, auth.user, "answer_delete") + erasure.delete_response(db, settings, response, by_manager=True) audit.record(db, "response.deleted", actor_id=auth.user.id, target_type="form", target_id=form.id) db.commit() - erasure_journal.record(settings, "response", public_id) + # Von Verwaltern gelöscht: bleibt im Verlauf wiederherstellbar + erasure_journal.record(settings, "response", public_id, by="manager") return RedirectResponse(f"/forms/{form.public_id}/responses?notice=response_deleted", status_code=303) @@ -252,6 +255,8 @@ def save_response( page = {**_edit_page_context(db, form, response), "note_value": note, "note_error": NOTE_ERRORS[error] if error else None} before = service.display_rows(form, response, settings.tz) + if error is None: + history.before_change(db, form, auth.user, "answer_edit") failed = fill.save_edit_for(request, db, settings, form, response, fields, files, action_url=_edit_url(form, response), page=page, blocked=error is not None) @@ -260,6 +265,7 @@ def save_response( db.flush() changed = notes.changed_labels(before, service.display_rows(form, response, settings.tz)) notes.add(db, response, auth.user, note, changed) + response.edited_by = "manager" audit.record(db, "response.edited", actor_id=auth.user.id, target_type="form", target_id=form.id, details={"questions": len(changed)}) db.commit() diff --git a/surveybox/web/routes/forms.py b/surveybox/web/routes/forms.py index 77c28d6..175d21b 100644 --- a/surveybox/web/routes/forms.py +++ b/surveybox/web/routes/forms.py @@ -18,6 +18,7 @@ from surveybox.forms import ( comments, conditions, groups, + history, retention, service, team, @@ -42,7 +43,8 @@ from surveybox.web.deps import ( UserScope, ) from surveybox.web.fill_page import render_fill -from surveybox.web.form_deps import EditForm, EvalForm, OwnForm +from surveybox.web.form_deps import ChangedForm, EditForm, EvalForm, OwnForm +from surveybox.web.routes.form_history import trash_entries from surveybox.web.routes.form_media import apply_option_images from surveybox.web.templating import render @@ -160,6 +162,7 @@ def _designer( "group_of": groups.member_of(form.questions), "required_by_group": groups.required_by_group(form.questions), "member_types": groups.MEMBER_TYPES, + "overbooked": history.overbooked(db, form), **extra, }, status_code=status_code, @@ -173,6 +176,9 @@ def _designer( @router.get("") def list_forms(request: Request, db: Db, auth: CurrentUser, found: UserScope) -> Response: + if request.query_params.get("problem") == "trash_gone": + return _list_page(request, db, auth, found, + trash_error=N_("This form can no longer be restored.")) return _list_page(request, db, auth, found) @@ -191,6 +197,7 @@ def _list_page( "can_create": found.can_create_forms, "group_choices": scope.creatable_groups(db, found), "group_required": not found.global_creator, + "trash": trash_entries(db, auth.user, found.managed), **extra, }, status_code=status_code, @@ -508,7 +515,7 @@ def update_question( request: Request, db: Db, settings: AppSettings, - form: EditForm, + form: ChangedForm, question_id: int, fields: FormFields, files: FormFiles, @@ -553,7 +560,7 @@ def update_question( def delete_question( request: Request, db: Db, - form: EditForm, + form: ChangedForm, question_id: int, confirm: Annotated[str, Form(max_length=5)] = "", ) -> Response: @@ -660,6 +667,7 @@ def _settings_page( "has_responses": service.response_count(db, form) > 0, "retention_default": retention.default_days(db), "retention_date": retention.planned_date(db, form), + "trash_days": history.trash_days(db), **extra, }, status_code=status_code, @@ -678,7 +686,7 @@ def save_settings( request: Request, db: Db, settings: AppSettings, - form: EditForm, + form: ChangedForm, fields: FormFields, found: UserScope, ) -> Response: @@ -733,7 +741,7 @@ def access_form(request: Request, db: Db, form: EditForm, found: UserScope) -> R @router.post("/{public_id}/access") -def save_access(db: Db, form: EditForm, fields: FormFields, found: UserScope) -> Response: +def save_access(db: Db, form: ChangedForm, fields: FormFields, found: UserScope) -> Response: service.set_access_entries( db, form, fields.get("users") or [], fields.get("groups") or [], found ) @@ -801,6 +809,6 @@ def delete_form( request, db, settings, form, delete_error=_error("confirm_missing"), status_code=400 ) audit.record(db, "form.deleted", actor_id=auth.user.id, target_type="form", target_id=form.id) - service.delete_form(db, form) + history.trash_form(db, form, auth.user) # bleibt eine Weile wiederherstellbar db.commit() - return RedirectResponse("/forms?notice=form_deleted", status_code=303) + return RedirectResponse("/forms?notice=form_trashed", status_code=303) diff --git a/surveybox/web/static/css/app.css b/surveybox/web/static/css/app.css index 5a04405..3db52fe 100644 --- a/surveybox/web/static/css/app.css +++ b/surveybox/web/static/css/app.css @@ -557,3 +557,13 @@ input[type="file"]::file-selector-button { .open-tab { color: var(--sb-muted); font-size: 0.8125rem; white-space: nowrap; } body.compact .content { margin-top: 16px; margin-bottom: 16px; } body.compact .card { padding: 16px 20px; } + +/* Verlauf und Überbuchung */ +.badge.warn { color: var(--sb-error); border-color: var(--sb-error); } +.history-group { margin: 0 0 16px; } +.history-group h3 { margin: 16px 0 8px; font-size: 1rem; } +.history-item { display: flex; gap: 8px; align-items: flex-start; padding: 6px 0; border-bottom: 1px solid var(--sb-border); } +.history-item .hint { margin: 2px 0 0; } +.history-values { display: grid; grid-template-columns: max-content 1fr; gap: 2px 8px; font-size: 0.875rem; margin-top: 4px; } +.history-values dt { color: var(--sb-muted); } +.history-values dd { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; } diff --git a/surveybox/web/templates/admin_settings.html b/surveybox/web/templates/admin_settings.html index d3a2232..9328f0c 100644 --- a/surveybox/web/templates/admin_settings.html +++ b/surveybox/web/templates/admin_settings.html @@ -71,4 +71,18 @@ +
+

{{ _('Form history and trash') }}

+ {% if history_error %}{% endif %} +
+ {{ csrf_field(request) }} + + +

{{ _('States are saved before changes to questions, options, settings and access, before managers change or delete answers, and once a day if a form changed. Managers use them to restore individual questions, options, settings or answers. They contain the answers, so they never outlast them: when a form is deleted or its retention period ends, its states are deleted too.') }}

+ + +

{{ _('During this time the owner, the person who deleted it, group administrators and administrators can restore a deleted form with all questions and answers. Afterwards it is deleted for good. If a person is deleted, their answers are also removed from the trash and the history at once.') }}

+ +
+
{% endblock %} diff --git a/surveybox/web/templates/form_designer.html b/surveybox/web/templates/form_designer.html index 0f88611..1a45ab7 100644 --- a/surveybox/web/templates/form_designer.html +++ b/surveybox/web/templates/form_designer.html @@ -15,6 +15,11 @@ {% set is_owner = request.state.form_level >= 3 %} {% set is_creator = user.role in ('admin', 'creator') %} {% if error %}{% endif %} +{% if overbooked %} +
+

{{ _('More places are booked than available:') }} {{ overbooked | join('; ') }}

+
+{% endif %}
@@ -24,6 +29,7 @@ {{ _('Answers') }} ({{ responses }}) {% endif %} {% if is_owner %}{{ _('Team') }}{% endif %} + {% if request.state.form_level >= 2 %}{{ _('History') }}{% endif %} {% if not form.is_template %}{{ _('Follow-up emails') }}{% endif %} {% if form.comments_mode != 'off' and not form.is_template %}{{ _('Comments') }}{% if pending_comments %} ({{ ngettext('%(num)d new', '%(num)d new', pending_comments) }}){% endif %}{% endif %} {% if is_creator %} diff --git a/surveybox/web/templates/form_history.html b/surveybox/web/templates/form_history.html new file mode 100644 index 0000000..81ba5cc --- /dev/null +++ b/surveybox/web/templates/form_history.html @@ -0,0 +1,37 @@ +{% extends "base.html" %} +{% block title %}{{ _('History') }} · {{ form.title }} · {{ appearance.name }}{% endblock %} + +{% block content %} +

← {{ form.title }}

+

{{ _('History') }}

+{% if overbooked %} +
+

{{ _('More places are booked than available:') }}

+
    {% for name in overbooked %}
  • {{ name }}
  • {% endfor %}
+

{{ _('Nobody was moved to the waiting list. Raise the number of places or contact the people concerned.') }}

+
+{% endif %} +
+

{{ _('Surveybox saves the state of this form before questions, options, settings or access are changed, before a manager changes or deletes an answer, and once a day if anything changed. Choose a state to see what differs from now and to restore individual questions, options, settings or answers. Everything else stays as it is.') }}

+

{{ ngettext('States are kept for %(num)d day, at most as long as the answers themselves.', 'States are kept for %(num)d days, at most as long as the answers themselves.', history_days) }} {{ _('Changes and deletions by participants themselves are not restored; what participants delete also disappears from the history.') }}

+ {% if snapshots %} +
+ + + + {% for s in snapshots %} + + + + + + + {% endfor %} + +
{{ _('Saved') }}{{ _('Occasion') }}{{ _('By') }}
{{ s.created_at | datetime }}{{ _(reason_names.get(s.reason, s.reason)) }}{% if s.actor_id %}{{ actors.get(s.actor_id, _('Deleted user')) }}{% else %}–{% endif %}{{ _('Compare') }}
+
+ {% else %} +

{{ _('No states yet. The first one is saved with the next change.') }}

+ {% endif %} +
+{% endblock %} diff --git a/surveybox/web/templates/form_history_compare.html b/surveybox/web/templates/form_history_compare.html new file mode 100644 index 0000000..e85c5a6 --- /dev/null +++ b/surveybox/web/templates/form_history_compare.html @@ -0,0 +1,102 @@ +{% extends "base.html" %} +{% block title %}{{ _('History') }} · {{ form.title }} · {{ appearance.name }}{% endblock %} + +{% macro value(v) -%} + {%- if v is none or v == '' -%}{{ _('empty') }} + {%- elif v is sameas true -%}{{ _('Yes') }} + {%- elif v is sameas false -%}{{ _('No') }} + {%- elif v.tzinfo is defined and v.hour is defined -%}{{ v | datetime }} + {%- else -%}{{ v }}{%- endif -%} +{%- endmacro %} + +{% block content %} +

← {{ _('History') }}

+

{{ _('State of %(date)s', date=snapshot.created_at | datetime) }}

+

{{ _(reason_names.get(snapshot.reason, snapshot.reason)) }}{% if actor %} · {{ actor }}{% endif %}

+{% if error %}{% endif %} + +{% if comparison.empty %} +
+

{{ _('Nothing in this state differs from the form as it is now in a way that can be restored.') }}

+
+{% else %} +
+ {{ csrf_field(request) }} +

{{ _('Choose what to restore. Only the chosen items change; questions, answers and settings that are not chosen stay as they are now.') }}

+ + {% if comparison.settings %} +
+

{{ _('Settings') }}

+ {% for item in comparison.settings %} + + {% endfor %} +
+ {% endif %} + + {% if comparison.questions %} +
+

{{ _('Questions and options') }}

+ {% for item in comparison.questions %} + + {% endfor %} +
+ {% endif %} + + {% if comparison.responses %} +
+

{{ _('Answers') }}

+ {% for item in comparison.responses %} + + {% endfor %} +
+ {% endif %} + +

{{ _('Before restoring, the current state is saved too, so this step can be undone in the history. Booked places are restored even if there are not enough places any more; the option is then shown as overbooked.') }}

+ +
+{% endif %} +{% endblock %} diff --git a/surveybox/web/templates/form_responses.html b/surveybox/web/templates/form_responses.html index d1a7c96..9b71b06 100644 --- a/surveybox/web/templates/form_responses.html +++ b/surveybox/web/templates/form_responses.html @@ -104,7 +104,7 @@ {% for item in lists %} {{ item.text }} - {{ item.confirmed | length }}{% if item.capacity %} / {{ item.capacity }}{% endif %} + {{ item.confirmed | length }}{% if item.capacity %} / {{ item.capacity }}{% if item.confirmed | length > item.capacity | int %} {{ _('overbooked') }}{% endif %}{% endif %} {{ item.confirmed | join(', ') or '–' }} {{ item.waiting | join(', ') or '–' }} @@ -118,7 +118,7 @@ {{ row.text }} {% if row.capacity %}{{ row.confirmed }}{% endif %} - {{ row.confirmed }}{% if row.capacity %} / {{ row.capacity }}{% endif %}{% if row.waiting %} · {{ ngettext('%(num)d waiting', '%(num)d waiting', row.waiting) }}{% endif %} + {{ row.confirmed }}{% if row.capacity %} / {{ row.capacity }}{% if row.confirmed > row.capacity | int %} {{ _('overbooked') }}{% endif %}{% endif %}{% if row.waiting %} · {{ ngettext('%(num)d waiting', '%(num)d waiting', row.waiting) }}{% endif %} {% endfor %} diff --git a/surveybox/web/templates/form_settings.html b/surveybox/web/templates/form_settings.html index 3043ffd..5f8f88b 100644 --- a/surveybox/web/templates/form_settings.html +++ b/surveybox/web/templates/form_settings.html @@ -160,6 +160,7 @@ {% if delete_error %}{% endif %}
{{ csrf_field(request) }} +

{{ ngettext('The form goes to the trash in the form list. There you can restore it for %(num)d day; after that it is deleted for good.', 'The form goes to the trash in the form list. There you can restore it for %(num)d days; after that it is deleted for good.', trash_days) }}

diff --git a/surveybox/web/templates/forms_list.html b/surveybox/web/templates/forms_list.html index 23474a9..dcbb557 100644 --- a/surveybox/web/templates/forms_list.html +++ b/surveybox/web/templates/forms_list.html @@ -26,6 +26,33 @@
+{% if trash or trash_error %} +
+

{{ _('Trash') }}

+ {% if trash_error %}{% endif %} +

{{ _('Deleted forms can be restored with all questions and answers until the date shown. After that they are deleted for good.') }}

+ {% if trash %} + + + + {% for t in trash %} + + + + + + + + {% endfor %} + +
{{ _('Title') }}{{ _('Answers') }}{{ _('Deleted') }}{{ _('Restorable until') }}
{{ t.entry.title }}{% if t.entry.extra.get('is_template') %} {{ _('Template') }}{% endif %}{{ t.entry.responses }}{{ t.entry.deleted_at | datetime }}{{ t.expires | date }} +
+ {{ csrf_field(request) }} +
+
+ {% endif %} +
+{% endif %} {% if can_create %} {% if templates %}
diff --git a/surveybox/web/templating.py b/surveybox/web/templating.py index 427df8d..c295661 100644 --- a/surveybox/web/templating.py +++ b/surveybox/web/templating.py @@ -44,6 +44,11 @@ NOTICES: dict[str, str] = { "group_deleted": N_("The group has been deleted."), "form_saved": N_("The form has been saved."), "form_deleted": N_("The form has been deleted."), + "form_trashed": N_( + "The form has been moved to the trash. It can be restored there for a limited time." + ), + "form_restored": N_("The form has been restored from the trash."), + "history_restored": N_("The selected changes have been restored."), "form_copied": N_("The copy has been created. It is a draft."), "template_saved": N_( "The template has been saved. New forms can be created from it in the form list." diff --git a/surveybox/worker.py b/surveybox/worker.py index f1e2cd8..efd908c 100644 --- a/surveybox/worker.py +++ b/surveybox/worker.py @@ -45,6 +45,9 @@ DEADLINE_INTERVAL = timedelta(minutes=5) # Nur Enddaten der letzten Tage melden (z. B. nach einer Pause des Workers) DEADLINE_LOOKBACK = timedelta(days=3) DIGEST_JOB = "digest" +# Verlauf der Formulare: täglicher Stand, abgelaufene Stände und Papierkorb +HISTORY_JOB = "form_history" +HISTORY_INTERVAL = timedelta(hours=24) DIGEST_HOUR = 7 @@ -100,6 +103,8 @@ class Worker: self.run_daily_backup(now) if self.cleanup_due(now): self.run_cleanup(now) + if self._due(HISTORY_JOB, HISTORY_INTERVAL, now): + self.run_history(now) if self._due(DEADLINE_JOB, DEADLINE_INTERVAL, now): self.run_deadlines(now) if self.digest_due(now): @@ -242,6 +247,17 @@ class Worker: self._record(CLEANUP_JOB, started=now, finished=datetime.now(UTC), status="ok", message=message, success=True) + def run_history(self, now: datetime) -> None: + """Täglicher Stand geänderter Formulare; Abgelaufenes entfernen.""" + from surveybox.forms import history + + with Session(self.engine) as db, db.begin(): + removed = history.prune(db, now) + with Session(self.engine) as db, db.begin(): + created = history.daily(db, now) + self._record(HISTORY_JOB, started=now, finished=datetime.now(UTC), status="ok", + message=f"snapshots={created} removed={removed}", success=True) + def daily_backup_due(self, now: datetime) -> bool: local = now.astimezone(self.settings.tz) if local.hour < self.settings.backup_hour: diff --git a/tests/test_history.py b/tests/test_history.py new file mode 100644 index 0000000..453d7dd --- /dev/null +++ b/tests/test_history.py @@ -0,0 +1,337 @@ +# SPDX-License-Identifier: AGPL-3.0-or-later +"""Verlauf und Papierkorb gegen PostgreSQL: punktuell wiederherstellen, Überbuchung, +Löschen durch Teilnehmende, gelöschte Personen, Aufbewahrung (CI).""" + +from __future__ import annotations + +from datetime import UTC, datetime, timedelta +from typing import Any + +import pytest + +pytest.importorskip("fastapi") + +from fastapi.testclient import TestClient +from helpers import new_client, token_for +from sqlalchemy import func, select, update +from sqlalchemy.orm import Session +from test_forms import ( + creator, + fill, + form_row, + participant, + question_ids, + save_settings, + simple_form, +) +from test_mail import admin +from test_phase5 import bookings, options_of, slot_form + +from surveybox import db +from surveybox.forms import erasure, history +from surveybox.models import ( + Answer, + Form, + FormSnapshot, + FormTrash, + Response, + UserAccount, +) +from surveybox.settings import get_settings + +pytestmark = pytest.mark.db + + +def snapshots(pid: str) -> list[tuple[int, str, history.Payload]]: + """(Kennung, Anlass, Inhalt) aller Stände eines Formulars, älteste zuerst.""" + form_id = form_row(pid).id + with Session(db.get_engine()) as s: + rows = list(s.scalars(select(FormSnapshot).where(FormSnapshot.form_id == form_id) + .order_by(FormSnapshot.created_at, FormSnapshot.id))) + return [(r.id, r.reason, history.unpack(r)) for r in rows] + + +def responses_of(pid: str) -> list[Response]: + with Session(db.get_engine()) as s: + rows = list(s.scalars(select(Response).where(Response.form_id == form_row(pid).id) + .order_by(Response.id))) + for row in rows: + s.expunge(row) + return rows + + +def restore(client: TestClient, pid: str, snapshot_id: int, *items: str) -> Any: + url = f"/forms/{pid}/history/{snapshot_id}" + return client.post(f"{url}/restore", + data={"csrf_token": token_for(client, url), "item": list(items)}) + + +def remove_option(client: TestClient, pid: str, qid: int, keep: str) -> None: + csrf = token_for(client, f"/forms/{pid}/questions/{qid}") + resp = client.post(f"/forms/{pid}/questions/{qid}", data={ + "csrf_token": csrf, "label": "Schicht", "slot_mode": "list", + "option_id": [keep], "option_label": ["Spät"], "option_capacity": [""]}) + assert resp.status_code == 303, resp.text + + +# -------------------------------------------------------------------------- +# Der Fall aus der Praxis: gebuchte Option gelöscht, einzeln zurückholen +# -------------------------------------------------------------------------- + + +def test_restore_deleted_booked_option_only(app: Any) -> None: + owner = creator(app) + pid, token, qid, (early, late) = slot_form(owner, capacity="2") + assert fill(new_client(app), token, {f"q{qid}": early}).status_code == 303 # Anna + assert fill(new_client(app), token, {f"q{qid}": late}).status_code == 303 # Bert + remove_option(owner, pid, qid, late) + assert [b[0] for b in bookings(qid)] == [late] + # Danach geht es weiter: neue Antwort, neuer Titel + assert fill(new_client(app), token, {f"q{qid}": late}).status_code == 303 # Carl + assert save_settings(owner, pid, title="Herbstfest", access="link").status_code == 303 + + found = [s for s in snapshots(pid) + if any(o.get("id") == early for q in s[2].rows("question") + for o in (q["config"] or {}).get("options") or [])] + snapshot_id = found[-1][0] # der Stand direkt vor dem Streichen + page = owner.get(f"/forms/{pid}/history/{snapshot_id}").text + assert f'value="opt:{qid}:{early}"' in page and "Früh" in page + assert "1 booked place" in page + + resp = restore(owner, pid, snapshot_id, f"opt:{qid}:{early}") + assert resp.status_code == 303 and "history_restored" in resp.headers["location"] + assert [o["id"] for o in options_of(qid)] == [early, late] + assert sorted(b[0] for b in bookings(qid)) == sorted([early, late, late]) + # Alles andere bleibt, wie es ist + assert form_row(pid).title == "Herbstfest" + assert len(responses_of(pid)) == 3 + # Vorher wurde der jetzige Stand gesichert + assert snapshots(pid)[-1][1] == "before_restore" + + +def test_restore_nothing_selected(app: Any) -> None: + owner = creator(app) + pid, _, qid, (_, late) = slot_form(owner) + remove_option(owner, pid, qid, late) + snapshot_id = snapshots(pid)[-1][0] + resp = restore(owner, pid, snapshot_id) + assert resp.status_code == 400 and "Please choose at least one" in resp.text + resp = restore(owner, pid, snapshot_id, "opt:999:x", "setting:status") + assert resp.status_code == 400 + + +# -------------------------------------------------------------------------- +# Antworten: von Verwaltern gelöscht, zurück trotz voller Plätze +# -------------------------------------------------------------------------- + + +def test_restore_deleted_answer_overbooks(app: Any) -> None: + owner = creator(app) + pid, token, qid, (early, _) = slot_form(owner, capacity="1") + assert fill(new_client(app), token, {f"q{qid}": early}).status_code == 303 + (first,) = responses_of(pid) + url = f"/forms/{pid}/responses/{first.public_id}" + resp = owner.post(f"{url}/delete", data={"csrf_token": token_for(owner, url), + "confirm": "on"}) + assert resp.status_code == 303 + # Der frei gewordene Platz ist inzwischen vergeben + assert fill(new_client(app), token, {f"q{qid}": early}).status_code == 303 + + snapshot_id, reason, _ = snapshots(pid)[-1] + assert reason == "answer_delete" + page = owner.get(f"/forms/{pid}/history/{snapshot_id}").text + assert f'value="r_del:{first.id}"' in page + assert restore(owner, pid, snapshot_id, f"r_del:{first.id}").status_code == 303 + assert len(responses_of(pid)) == 2 + assert [b[:2] for b in bookings(qid)] == [(early, "confirmed"), (early, "confirmed")] + assert "More places are booked than available" in owner.get(f"/forms/{pid}/history").text + assert "More places are booked than available" in owner.get(f"/forms/{pid}").text + assert "overbooked" in owner.get(f"/forms/{pid}/responses").text + + +def test_restore_deleted_question_with_answers(app: Any) -> None: + owner = creator(app) + pid, token, (q_name, q_food) = simple_form(owner, access="link") + for name in ("Anna", "Bert"): + assert fill(new_client(app), token, {f"q{q_name}": name}).status_code == 303 + csrf = token_for(owner, f"/forms/{pid}/questions/{q_name}") + resp = owner.post(f"/forms/{pid}/questions/{q_name}/delete", + data={"csrf_token": csrf, "confirm": "on"}) + assert resp.status_code == 303 + assert question_ids(pid) == [q_food] + snapshot_id = snapshots(pid)[-1][0] + assert "With 2 answers" in owner.get(f"/forms/{pid}/history/{snapshot_id}").text + assert restore(owner, pid, snapshot_id, f"q_del:{q_name}").status_code == 303 + assert question_ids(pid) == [q_name, q_food] # wieder an erster Stelle + with Session(db.get_engine()) as s: + texts = sorted(s.scalars(select(Answer.value_text).where(Answer.question_id == q_name))) + assert texts == ["Anna", "Bert"] + + +def test_restore_setting_only(app: Any) -> None: + owner = creator(app) + pid, _, _ = simple_form(owner, access="link") + assert save_settings(owner, pid, title="Neu", access="link", + closes_at="2030-01-01T10:00").status_code == 303 + snapshot_id = snapshots(pid)[-1][0] + page = owner.get(f"/forms/{pid}/history/{snapshot_id}").text + assert 'value="setting:title"' in page and 'value="setting:closes_at"' in page + assert restore(owner, pid, snapshot_id, "setting:title").status_code == 303 + row = form_row(pid) + assert row.title == "Sommerfest" and row.closes_at is not None + + +def test_participant_edits_are_not_offered(app: Any) -> None: + owner = creator(app) + pid, token, (q_name, _) = simple_form(owner, access="users") + paul = participant(app) + assert fill(paul, token, {f"q{q_name}": "Paul"}).status_code == 303 + assert save_settings(owner, pid, title="Neu").status_code == 303 # neuer Stand + assert fill(paul, token, {f"q{q_name}": "Paula"}, path="/edit").status_code == 303 + snapshot_id = snapshots(pid)[-1][0] + assert "r_chg:" not in owner.get(f"/forms/{pid}/history/{snapshot_id}").text + + +def test_history_needs_edit_rights(app: Any) -> None: + from test_media_team import add_member + + owner = creator(app) + pid, _, _ = simple_form(owner, access="link") + assert save_settings(owner, pid, title="Neu", access="link").status_code == 303 + snapshot_id = snapshots(pid)[-1][0] + editor = participant(app, "erik@example.de") + evaluator = participant(app, "eva@example.de") + add_member(owner, pid, "erik@example.de", "editor") + add_member(owner, pid, "eva@example.de", "evaluator") + assert editor.get(f"/forms/{pid}/history").status_code == 200 + assert editor.get(f"/forms/{pid}/history/{snapshot_id}").status_code == 200 + for other in (evaluator, participant(app)): + assert other.get(f"/forms/{pid}/history").status_code in (403, 404) + assert other.get(f"/forms/{pid}/history/{snapshot_id}").status_code in (403, 404) + + +# -------------------------------------------------------------------------- +# Datenschutz +# -------------------------------------------------------------------------- + + +def test_self_deleted_answer_leaves_history(app: Any) -> None: + owner = creator(app) + pid, token, (q_name, _) = simple_form(owner, access="link") + assert fill(new_client(app), token, {f"q{q_name}": "Anna"}).status_code == 303 + assert save_settings(owner, pid, title="Neu", access="link").status_code == 303 + (response,) = responses_of(pid) + assert any(r["id"] == response.id for _, _, p in snapshots(pid) for r in p.rows("response")) + with Session(db.get_engine()) as s: + row = s.get(Response, response.id) + assert row is not None + erasure.delete_response(s, get_settings(), row) # wie über den persönlichen Link + s.commit() + assert not any(p.rows("response") for _, _, p in snapshots(pid)) + snapshot_id = snapshots(pid)[-1][0] + assert "r_del:" not in owner.get(f"/forms/{pid}/history/{snapshot_id}").text + + +def test_erased_user_leaves_history(app: Any) -> None: + owner = creator(app) + pid, token, (q_name, _) = simple_form(owner, access="users", deletion_mode="delete") + paul = participant(app) + assert fill(paul, token, {f"q{q_name}": "Paul"}).status_code == 303 + assert save_settings(owner, pid, title="Neu", deletion_mode="delete").status_code == 303 + with Session(db.get_engine()) as s: + user = s.scalar(select(UserAccount).where(UserAccount.email == "paul@example.de")) + assert user is not None + user_id = user.id + erasure.erase_user(s, get_settings(), user, {}, actor_id=None) + s.commit() + for _, _, payload in snapshots(pid): + assert not any(r.get("user_id") == user_id for r in payload.rows("response")) + with Session(db.get_engine()) as s: + assert not s.scalar(select(func.count()).select_from(FormSnapshot) + .where(FormSnapshot.user_ids.contains([user_id]))) + + +def test_retention_removes_history(app: Any) -> None: + from surveybox.forms import retention + + owner = creator(app) + pid, token, (q_name, _) = simple_form(owner, access="link") + assert fill(new_client(app), token, {f"q{q_name}": "Anna"}).status_code == 303 + assert save_settings(owner, pid, title="Neu", access="link").status_code == 303 + assert snapshots(pid) + with Session(db.get_engine()) as s: + form = s.get(Form, form_row(pid).id) + assert form is not None + retention.apply(s, form, datetime.now(UTC)) + s.commit() + assert snapshots(pid) == [] + + +# -------------------------------------------------------------------------- +# Papierkorb und Aufbewahrung +# -------------------------------------------------------------------------- + + +def test_trash_and_restore_form(app: Any) -> None: + owner = creator(app) + pid, token, (q_name, q_food) = simple_form(owner, access="link") + assert fill(new_client(app), token, {f"q{q_name}": "Anna"}).status_code == 303 + csrf = token_for(owner, f"/forms/{pid}/settings") + resp = owner.post(f"/forms/{pid}/delete", data={"csrf_token": csrf, "confirm": "on"}) + assert resp.status_code == 303 and "form_trashed" in resp.headers["location"] + assert new_client(app).get(f"/f/{token}").status_code == 404 + listing = owner.get("/forms").text + assert "Trash" in listing and f"/forms/trash/{pid}/restore" in listing + # Andere sehen den Papierkorb nicht und können nichts zurückholen + other = creator(app, "otto@example.de") + assert f"/forms/trash/{pid}/restore" not in other.get("/forms").text + csrf = token_for(other, "/forms") + assert other.post(f"/forms/trash/{pid}/restore", + data={"csrf_token": csrf}).status_code == 404 + + csrf = token_for(owner, "/forms") + resp = owner.post(f"/forms/trash/{pid}/restore", data={"csrf_token": csrf}) + assert resp.status_code == 303 and "form_restored" in resp.headers["location"] + assert question_ids(pid) == [q_name, q_food] + assert len(responses_of(pid)) == 1 + assert new_client(app).get(f"/f/{token}").status_code == 200 + with Session(db.get_engine()) as s: + assert s.scalar(select(func.count()).select_from(FormTrash)) == 0 + + +def test_prune_expired(app: Any) -> None: + owner = creator(app) + pid, _, _ = simple_form(owner, access="link") + assert save_settings(owner, pid, title="Neu", access="link").status_code == 303 + keep_pid, _, _ = simple_form(owner, access="link") + csrf = token_for(owner, f"/forms/{keep_pid}/settings") + owner.post(f"/forms/{keep_pid}/delete", data={"csrf_token": csrf, "confirm": "on"}) + form_id = form_row(pid).id + old = datetime.now(UTC) - timedelta(days=history.DEFAULT_HISTORY_DAYS + 1) + with Session(db.get_engine()) as s: + s.execute(update(FormSnapshot).values(created_at=old)) + s.execute(update(FormTrash).values( + deleted_at=datetime.now(UTC) - timedelta(days=history.DEFAULT_TRASH_DAYS + 1))) + s.commit() + assert history.prune(s, datetime.now(UTC)) >= 2 + s.commit() + assert s.scalar(select(func.count()).select_from(FormSnapshot)) == 0 + assert s.scalar(select(func.count()).select_from(FormTrash)) == 0 + # Der tägliche Stand legt wieder einen an + assert history.daily(s, datetime.now(UTC)) == 1 + s.commit() + assert s.scalar(select(FormSnapshot.form_id)) == form_id + assert history.daily(s, datetime.now(UTC)) == 0 # nichts geändert + + +def test_instance_settings(app: Any) -> None: + client = admin(app) + url = "/admin/settings" + resp = client.post(f"{url}/history", data={"csrf_token": token_for(client, url), + "history_days": "30", "trash_days": "7"}) + assert resp.status_code == 303 and "settings_saved" in resp.headers["location"] + resp = client.post(f"{url}/history", data={"csrf_token": token_for(client, url), + "history_days": "0", "trash_days": "7"}) + assert "error=history" in resp.headers["location"] + with Session(db.get_engine()) as s: + assert history.history_days(s) == 30 and history.trash_days(s) == 7 diff --git a/tests/test_history_units.py b/tests/test_history_units.py new file mode 100644 index 0000000..7f07d28 --- /dev/null +++ b/tests/test_history_units.py @@ -0,0 +1,132 @@ +# SPDX-License-Identifier: AGPL-3.0-or-later +"""Verlauf der Formulare ohne Datenbank: Kodierung, Prüfsummen, Vergleich, Bereinigung.""" + +from __future__ import annotations + +import uuid +from datetime import UTC, date, datetime, time +from decimal import Decimal +from typing import Any + +import pytest + +pytest.importorskip("sqlalchemy") + +from surveybox.forms import history +from surveybox.forms.booking import Availability + + +def test_values_survive_encoding() -> None: + values = [None, True, 3, 1.5, "Text", Decimal("12.500000"), + datetime(2026, 11, 26, 9, 30, tzinfo=UTC), date(2026, 11, 26), time(9, 30), + uuid.uuid4(), b"\x00\xffmarker", {"selected": ["a", "b"]}, ["x", 1]] + for value in values: + assert history.decode_value(history.encode_value(value)) == value + + +def payload(**tables: list[dict[str, Any]]) -> history.Payload: + return history.Payload(1, dict(tables)) + + +def form_row(**values: Any) -> dict[str, Any]: + return {"id": 1, "title": "Sommerfest", "updated_at": datetime(2026, 1, 1, tzinfo=UTC), + **values} + + +def test_hash_ignores_updated_at_and_separates_answers() -> None: + base = payload(form=[form_row()], response=[{"id": 5, "form_id": 1}]) + touched = payload(form=[form_row(updated_at=datetime(2026, 2, 1, tzinfo=UTC))], + response=[{"id": 5, "form_id": 1}]) + assert history.pack(base).full_hash == history.pack(touched).full_hash + renamed = payload(form=[form_row(title="Herbstfest")], response=[{"id": 5, "form_id": 1}]) + assert history.pack(base).full_hash != history.pack(renamed).full_hash + # Nur Einstellungen geändert: Antworten-Prüfsumme bleibt (Entprellen) + assert history.pack(base).data_hash == history.pack(renamed).data_hash + more = payload(form=[form_row()], response=[{"id": 5, "form_id": 1}, + {"id": 6, "form_id": 1}]) + assert history.pack(base).data_hash != history.pack(more).data_hash + + +def question(**values: Any) -> dict[str, Any]: + return {"id": 7, "label": "Schicht", "help_text": None, "required": False, + "personal": False, "config": {"options": [{"id": "a", "label": "Früh"}, + {"id": "b", "label": "Spät"}]}, + **values} + + +def test_removed_option_is_not_a_changed_question() -> None: + old = question() + fewer = question(config={"options": [{"id": "b", "label": "Spät"}]}) + added = question(config={"options": [{"id": "a", "label": "Früh"}, + {"id": "b", "label": "Spät"}, + {"id": "c", "label": "Abend"}]}) + relabeled = question(config={"options": [{"id": "a", "label": "Morgens"}, + {"id": "b", "label": "Spät"}]}) + confirmed = question(config={**old["config"], "confirmed": ["a"]}) + assert not history._definition_differs(old, fewer) + assert not history._definition_differs(old, added) + assert not history._definition_differs(old, confirmed) + assert history._definition_differs(old, relabeled) + assert history._definition_differs(old, question(label="Dienst")) + + +def test_compare_lists_deleted_question_and_removed_option() -> None: + old = payload(form=[form_row()], + question=[question(position=0), question(id=8, label="Name", position=1)], + answer=[{"question_id": 8, "response_id": 1}, + {"question_id": 7, "response_id": 1}], + booking=[{"question_id": 7, "option_id": "a", "response_id": 1}]) + now = payload(form=[form_row()], + question=[question(position=0, + config={"options": [{"id": "b", "label": "Spät"}]})]) + result = history.Comparison(snapshot=None) # type: ignore[arg-type] + history._compare_questions(old, now, result) + keys = {item.key: item for item in result.questions} + assert set(keys) == {"q_del:8", "opt:7:a"} + assert keys["q_del:8"].answers == 1 + assert keys["opt:7:a"].bookings == 1 and keys["opt:7:a"].title == "Früh" + + +def test_settings_compare_only_known_fields() -> None: + old = payload(form=[form_row(closes_at=None, status="open")]) + now = payload(form=[form_row(title="Neu", closes_at=datetime(2026, 12, 1, tzinfo=UTC), + status="closed")]) + result = history.Comparison(snapshot=None) # type: ignore[arg-type] + history._compare_settings(old, now, result) + assert [i.key for i in result.settings] == ["setting:title", "setting:closes_at"] + + +def test_drop_responses_removes_dependent_rows() -> None: + data = payload(response=[{"id": 1}, {"id": 2}], + answer=[{"response_id": 1}, {"response_id": 2}], + booking=[{"response_id": 1}], response_note=[{"response_id": 1}], + media_file=[{"response_id": 1, "storage_key": "k1"}, + {"response_id": None, "storage_key": "k2"}]) + assert history._drop_responses(data, {1}) + assert [r["id"] for r in data.rows("response")] == [2] + assert data.rows("answer") == [{"response_id": 2}] + assert data.rows("booking") == [] and data.rows("response_note") == [] + assert [m["storage_key"] for m in data.rows("media_file")] == ["k2"] + assert not history._drop_responses(data, {99}) + + +def test_people_index() -> None: + data = payload(form=[form_row(owner_id=3)], + response=[{"id": 1, "user_id": 4, "guest_contact_id": None}, + {"id": 2, "user_id": None, "guest_contact_id": 9}], + response_note=[{"author_id": 5}], form_access=[{"user_id": None}]) + assert history._people(data) == ([3, 4, 5], [9]) + + +def test_conditions_on_missing_questions_are_dropped() -> None: + config = {"condition": {"mode": "all", "rules": [{"q": 3, "op": "eq", "value": "x"}, + {"q": 4, "op": "eq", "value": "y"}]}} + cleaned = history._clean_conditions(config, {3}) + assert [r["q"] for r in cleaned["condition"]["rules"]] == [3] + assert "condition" not in history._clean_conditions(config, set()) + + +def test_overbooked() -> None: + assert Availability(capacity=1, confirmed=2, waiting=0).overbooked + assert not Availability(capacity=2, confirmed=2, waiting=1).overbooked + assert not Availability(capacity=None, confirmed=9, waiting=0).overbooked diff --git a/tests/test_security_matrix.py b/tests/test_security_matrix.py index b3b0c8b..172cf32 100644 --- a/tests/test_security_matrix.py +++ b/tests/test_security_matrix.py @@ -174,7 +174,7 @@ def test_protected_pages_need_login_and_rights(app: Any) -> None: if denied.status_code == 303: assert not denied.headers["location"].startswith(path), path checked += 1 - # Stand Phase 10: 38 geschützte Seiten; die Untergrenze fängt eine leere Erfassung ab + # Stand mit Verlauf: 40 geschützte Seiten; die Untergrenze fängt eine leere Erfassung ab assert checked > 30, _describe(app)