From b1cffe9f728ec9885dc0124ad18016b688c1375b Mon Sep 17 00:00:00 2001 From: Maico Timmerman Date: Fri, 1 Jan 2021 20:20:42 +0100 Subject: [PATCH] Shredder: Only force download for tax-relevant data (#1801) --- src/pretix/base/services/shredder.py | 13 ++++--- src/pretix/base/shredder.py | 8 +++++ .../pretixcontrol/shredder/download.html | 35 +++++++++++-------- src/pretix/control/views/shredder.py | 21 +++++++++++ 4 files changed, 58 insertions(+), 19 deletions(-) diff --git a/src/pretix/base/services/shredder.py b/src/pretix/base/services/shredder.py index ced385179..3c160eeb1 100644 --- a/src/pretix/base/services/shredder.py +++ b/src/pretix/base/services/shredder.py @@ -75,16 +75,19 @@ def shred(event: Event, fileid: str, confirm_code: str) -> None: indexdata = json.loads(zipfile.read('index.json').decode()) if indexdata['organizer'] != event.organizer.slug or indexdata['event'] != event.slug: raise ShredError(_("This file is from a different event.")) - if indexdata['confirm_code'] != confirm_code: - raise ShredError(_("The confirm code you entered was incorrect.")) - if event.logentry_set.filter(datetime__gte=parse(indexdata['time'])): - raise ShredError(_("Something happened in your event after the export, please try again.")) - + shredders = [] for s in indexdata['shredders']: shredder = known_shredders.get(s) if not shredder: continue + shredders.append(shredder) + if any(shredder.require_download_confirmation for shredder in shredders): + if indexdata['confirm_code'] != confirm_code: + raise ShredError(_("The confirm code you entered was incorrect.")) + if event.logentry_set.filter(datetime__gte=parse(indexdata['time'])): + raise ShredError(_("Something happened in your event after the export, please try again.")) + for shredder in shredders: shredder.shred_data() cf.file.delete(save=False) diff --git a/src/pretix/base/shredder.py b/src/pretix/base/shredder.py index 9174c11ea..0fbe4561e 100644 --- a/src/pretix/base/shredder.py +++ b/src/pretix/base/shredder.py @@ -82,6 +82,14 @@ class BaseDataShredder: """ return False + @property + def require_download_confirmation(self): + """ + Indicates whether the data of this shredder needs to be downloaded, before it is actually shredded. By default + this value is equal to the tax relevant flag. + """ + return self.tax_relevant + @property def verbose_name(self) -> str: """ diff --git a/src/pretix/control/templates/pretixcontrol/shredder/download.html b/src/pretix/control/templates/pretixcontrol/shredder/download.html index d5e8bd866..e44750586 100644 --- a/src/pretix/control/templates/pretixcontrol/shredder/download.html +++ b/src/pretix/control/templates/pretixcontrol/shredder/download.html @@ -11,12 +11,16 @@ method="post" class="form-horizontal" data-asynctask> {% csrf_token %}
- {% trans "Step 1: Download data" %} + {% if download_on_shred %} + {% trans "Step 1: Download data" %} + {% else %} + {% trans "(Optional) Step 1: Download data" %} + {% endif %}

{% blocktrans trimmed %} You are about to permanently delete data from the server, even though you might be required to keep - some of this data on file. You should therefore download the following file and store it in a safe + some of this data on file. You can therefore download the following file and store it in a safe place: {% endblocktrans %}

@@ -27,18 +31,7 @@

- {% trans "Step 2: Confirm download" %} -

- {% blocktrans trimmed %} - In the downloaded file, there is a text file named "CONFIRM_CODE.txt" with a six-character code. - Please enter this code here to confirm that you successfully downloaded the file. - {% endblocktrans %} -

- -
-
-
- {% trans "Step 3: Confirm deletion" %} + {% trans "Step 2: Confirm deletion" %}

{% blocktrans trimmed with event=request.event.name slug=request.event.slug %} Please re-check that you are fully certain that you want to delete the selected categories of data from the event {{ event }}. @@ -46,7 +39,21 @@ {% endblocktrans %}

+
+ {% if download_on_shred %} +
+ {% trans "Step 3: Confirm download" %} +

+ {% blocktrans trimmed %} + In the downloaded file, there is a text file named "CONFIRM_CODE.txt" with a six-character code. + Please enter this code here to confirm that you successfully downloaded the file. + {% endblocktrans %} +

+ +
+
+ {% endif %}