From e396e0c558cca8a4280782bf5b0096fb19e4e0ac Mon Sep 17 00:00:00 2001 From: Job Doesburg Date: Fri, 15 Apr 2022 14:43:46 +0200 Subject: [PATCH 1/3] Delete event information fields --- website/events/forms.py | 10 ++++- ...gistrationinformationfield_delete_after.py | 20 ++++++++++ .../models/registration_information_field.py | 9 +++++ website/events/services.py | 39 +++++++++++++++++-- 4 files changed, 73 insertions(+), 5 deletions(-) create mode 100644 website/events/migrations/0056_registrationinformationfield_delete_after.py diff --git a/website/events/forms.py b/website/events/forms.py index d087cb85f..ec7bdb85e 100644 --- a/website/events/forms.py +++ b/website/events/forms.py @@ -22,7 +22,15 @@ def __init__(self, *args, **kwargs): self.fields[key] = forms.CharField(required=field["required"]) self.fields[key].label = field["label"] - self.fields[key].help_text = field["description"] + if not field["description"]: + self.fields[ + key + ].help_text = f"{_('This data will be deleted after')} {field['delete_after']:%d-%m-%Y}." + else: + self.fields[key].help_text = ( + field["description"] + + f". {_('This data will be deleted after')} {field['delete_after']:%d-%m-%Y}." + ) self.fields[key].initial = field["value"] def field_values(self): diff --git a/website/events/migrations/0056_registrationinformationfield_delete_after.py b/website/events/migrations/0056_registrationinformationfield_delete_after.py new file mode 100644 index 000000000..34f321440 --- /dev/null +++ b/website/events/migrations/0056_registrationinformationfield_delete_after.py @@ -0,0 +1,20 @@ +# Generated by Django 4.0.3 on 2022-04-15 12:22 + +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('events', '0055_alter_event_no_registration_message'), + ] + + operations = [ + migrations.AddField( + model_name='registrationinformationfield', + name='delete_after', + field=models.DateField(default=django.utils.timezone.now, help_text='The data entered in this field will automatically be deleted after this date for privacy purposes. Please choose a value, e.g. 1 month after the event.', verbose_name='delete after'), + preserve_default=False, + ), + ] diff --git a/website/events/models/registration_information_field.py b/website/events/models/registration_information_field.py index f8850e7a7..584f38505 100644 --- a/website/events/models/registration_information_field.py +++ b/website/events/models/registration_information_field.py @@ -40,6 +40,15 @@ class RegistrationInformationField(models.Model): _("required"), ) + delete_after = models.DateField( + _("delete after"), + null=False, + blank=False, + help_text=_( + "The data entered in this field will automatically be deleted after this date for privacy purposes. Please choose a value, e.g. 1 month after the event." + ), + ) + def get_value_for(self, registration): if self.type == self.TEXT_FIELD: value_set = self.textregistrationinformation_set diff --git a/website/events/services.py b/website/events/services.py index 4a54fd604..e631ee4b3 100644 --- a/website/events/services.py +++ b/website/events/services.py @@ -12,6 +12,10 @@ EventRegistration, RegistrationInformationField, Event, + AbstractRegistrationInformation, + TextRegistrationInformation, + IntegerRegistrationInformation, + BooleanRegistrationInformation, ) from payments.api.v1.fields import PaymentTypeField from payments.services import create_payment, delete_payment @@ -303,6 +307,7 @@ def registration_fields(request, member=None, event=None, registration=None, nam "description": field.description, "value": information_field["value"], "required": field.required, + "delete_after": field.delete_after, } return fields @@ -359,11 +364,37 @@ def generate_category_statistics() -> dict: def execute_data_minimisation(dry_run=False): """Delete information about very old events.""" # Sometimes years are 366 days of course, but better delete 1 or 2 days early than late - deletion_period = timezone.now().date() - timezone.timedelta(days=(365 * 5)) + event_registration_deletion_period = timezone.now().date() - timezone.timedelta( + days=(365 * 5) + ) - queryset = EventRegistration.objects.filter(event__end__lte=deletion_period).filter( + event_registrations = EventRegistration.objects.filter( + event__end__lte=event_registration_deletion_period + ).filter( Q(payment__isnull=False) | Q(member__isnull=False) | ~Q(name__exact="") ) + + event_information_boolean = BooleanRegistrationInformation.objects.filter( + field__delete_after__lt=timezone.now().date() + ) + + event_information_integer = IntegerRegistrationInformation.objects.filter( + field__delete_after__lt=timezone.now().date() + ) + + event_information_text = TextRegistrationInformation.objects.filter( + field__delete_after__lt=timezone.now().date() + ) + if not dry_run: - queryset.update(payment=None, member=None, name="") - return queryset.all() + event_registrations.update(payment=None, member=None, name="") + event_information_boolean.delete() + event_information_integer.delete() + event_information_text.delete() + + return ( + event_registrations.all(), + event_information_boolean.all(), + event_information_integer.all(), + event_information_text.all(), + ) From b94ae58f276203f5b9d2d1180f4bd58f23676dbc Mon Sep 17 00:00:00 2001 From: Job Doesburg Date: Fri, 15 Apr 2022 14:46:57 +0200 Subject: [PATCH 2/3] Change admin ui --- website/events/admin/inlines.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/events/admin/inlines.py b/website/events/admin/inlines.py index 3444f893a..c70780f07 100644 --- a/website/events/admin/inlines.py +++ b/website/events/admin/inlines.py @@ -6,7 +6,7 @@ from pizzas.models import FoodEvent -class RegistrationInformationFieldInline(admin.TabularInline): +class RegistrationInformationFieldInline(admin.StackedInline): """The inline for registration information fields in the Event admin.""" form = RegistrationInformationFieldForm From 63bfb05d53e51be580bca5626fc8d56c56a74634 Mon Sep 17 00:00:00 2001 From: Job Doesburg Date: Fri, 15 Apr 2022 14:47:58 +0200 Subject: [PATCH 3/3] Fix pylint --- website/events/services.py | 1 - 1 file changed, 1 deletion(-) diff --git a/website/events/services.py b/website/events/services.py index e631ee4b3..636750410 100644 --- a/website/events/services.py +++ b/website/events/services.py @@ -12,7 +12,6 @@ EventRegistration, RegistrationInformationField, Event, - AbstractRegistrationInformation, TextRegistrationInformation, IntegerRegistrationInformation, BooleanRegistrationInformation,