Repository: pretix/pretix

Issue:
Hard-coded constraint for shredding data
**Describe the bug**
The number of days after which admins are allowed to shred personal data of an event is hard-coded to 30 days. But some times there are scenarios like using Pretix just for Covid 19 contact registration in which shredding between 21 and 30 days after the event would be necessary.

**Expected behavior**
There should be a setting or a configuration option to change the number of days.

**Additional context**
Affected lines: https://github.com/pretix/pretix/blob/master/src/pretix/base/shredder.py#L65
Hard-coded constraint for shredding data
**Describe the bug**
The number of days after which admins are allowed to shred personal data of an event is hard-coded to 30 days. But some times there are scenarios like using Pretix just for Covid 19 contact registration in which shredding between 21 and 30 days after the event would be necessary.

**Expected behavior**
There should be a setting or a configuration option to change the number of days.

**Additional context**
Affected lines: https://github.com/pretix/pretix/blob/master/src/pretix/base/shredder.py#L65


Discussion:
we might just want to soften the limit to "as soon as the event is over", there is no good reason for the 30/60 days. I think the original idea was just too prevent people from accidentally deleting data before they really know if they'll need it again
If you agree with this solution, I could provide a fix for that.
Yes, fine with me!
we might just want to soften the limit to "as soon as the event is over", there is no good reason for the 30/60 days. I think the original idea was just too prevent people from accidentally deleting data before they really know if they'll need it again
If you agree with this solution, I could provide a fix for that.
Yes, fine with me!

Resolving patch:
diff --git a/src/pretix/base/shredder.py b/src/pretix/base/shredder.py
--- a/src/pretix/base/shredder.py
+++ b/src/pretix/base/shredder.py
@@ -34,7 +34,6 @@
 
 import json
 import os
-from datetime import timedelta
 from typing import List, Tuple
 
 from django.db import transaction
@@ -70,11 +69,11 @@ def shred_constraints(event: Event):
             max_fromto=Greatest(Max('date_to'), Max('date_from'))
         )
         max_date = max_date['max_fromto'] or max_date['max_to'] or max_date['max_from']
-        if max_date is not None and max_date > now() - timedelta(days=30):
-            return _('Your event needs to be over for at least 30 days to use this feature.')
+        if max_date is not None and max_date >= now():
+            return _('Your event needs to be over to use this feature.')
     else:
-        if (event.date_to or event.date_from) > now() - timedelta(days=30):
-            return _('Your event needs to be over for at least 30 days to use this feature.')
+        if (event.date_to or event.date_from) >= now():
+            return _('Your event needs to be over to use this feature.')
     if event.live:
         return _('Your ticket shop needs to be offline to use this feature.')
     return None


Test patch:
diff --git a/src/tests/base/test_shredders.py b/src/tests/base/test_shredders.py
--- a/src/tests/base/test_shredders.py
+++ b/src/tests/base/test_shredders.py
@@ -380,31 +380,34 @@ def test_shred_constraint_offline(event):
 
 
 @pytest.mark.django_db
-def test_shred_constraint_30_days(event):
+def test_shred_constraint_after_event(event):
     event.live = False
-    event.date_from = now() - timedelta(days=32)
-    event.date_to = now() - timedelta(days=32)
+    now_dt = now()
+    event.date_from = now_dt - timedelta(hours=1)
+    event.date_to = now_dt - timedelta(hours=1)
     assert shred_constraints(event) is None
-    event.date_from = now() - timedelta(days=22)
-    event.date_to = now() - timedelta(days=22)
-    assert shred_constraints(event)
-    event.date_from = now() - timedelta(days=32)
-    event.date_to = now() - timedelta(days=22)
+    event.date_from = now_dt - timedelta(hours=1)
+    event.date_to = now_dt - timedelta(hours=1)
+    assert shred_constraints(event) is None
+    event.date_from = now_dt - timedelta(hours=1)
+    event.date_to = now_dt + timedelta(hours=1)
     assert shred_constraints(event)
 
 
 @pytest.mark.django_db
-def test_shred_constraint_30_days_subevents(event):
+def test_shred_constraint_after_event_subevents(event):
     event.has_subevents = True
     event.live = False
 
+    now_dt = now()
+
     event.subevents.create(
-        date_from=now() - timedelta(days=32),
-        date_to=now() - timedelta(days=32)
+        date_from=now_dt - timedelta(hours=2),
+        date_to=now_dt - timedelta(hours=1)
     )
     assert shred_constraints(event) is None
     event.subevents.create(
-        date_from=now() - timedelta(days=22),
-        date_to=now() - timedelta(days=32)
+        date_from=now_dt - timedelta(hours=1),
+        date_to=now_dt + timedelta(hours=1)
     )
     assert shred_constraints(event)