From 5396973302274e0ec8ea3d7469347962323ede18 Mon Sep 17 00:00:00 2001 From: Daniel Ursache Dogariu Date: Thu, 30 May 2024 11:09:42 +0300 Subject: [PATCH] Allow download of donations archive after the donation limit expired (#305) * Allow download of donations archive after the donation limit expired * Always use timedelta from timezone --- backend/donations/views/api.py | 4 +++- backend/donations/views/my_account.py | 6 ++++-- backend/donations/views/ngo.py | 4 ++-- backend/redirectioneaza/settings.py | 3 +++ 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/backend/donations/views/api.py b/backend/donations/views/api.py index c5d9656d..d9870193 100644 --- a/backend/donations/views/api.py +++ b/backend/donations/views/api.py @@ -188,7 +188,9 @@ def post(self, request, *args, **kwargs): day=settings.DONATIONS_LIMIT_DAY, ) - if timezone.now().date() > DONATION_LIMIT: + if timezone.now().date() > DONATION_LIMIT + timezone.timedelta( + days=settings.TIMEDELTA_DONATIONS_LIMIT_DOWNLOAD_DAYS + ): return redirect(reverse("contul-meu")) new_job: Job = Job(ngo=ngo, owner=request.user) diff --git a/backend/donations/views/my_account.py b/backend/donations/views/my_account.py index 995b4144..25dd2526 100644 --- a/backend/donations/views/my_account.py +++ b/backend/donations/views/my_account.py @@ -118,7 +118,9 @@ def get(self, request: HttpRequest, *args, **kwargs): "years": list(grouped_donors.keys()), } - can_donate = not now.date() > settings.DONATIONS_LIMIT + download_expired = not now.date() > settings.DONATIONS_LIMIT + timezone.timedelta( + days=settings.TIMEDELTA_DONATIONS_LIMIT_DOWNLOAD_DAYS + ) ngo_url = "" if user_ngo: @@ -145,7 +147,7 @@ def get(self, request: HttpRequest, *args, **kwargs): if not user_ngo or not user_ngo.is_active: disable_forms_download = True disable_past_download = True - elif settings.ENABLE_FORMS_DOWNLOAD and (not has_signed_form or not can_donate or last_job_was_recent): + elif settings.ENABLE_FORMS_DOWNLOAD and (not has_signed_form or not download_expired or last_job_was_recent): disable_forms_download = True context = { diff --git a/backend/donations/views/ngo.py b/backend/donations/views/ngo.py index 6b4563fc..b98b2577 100644 --- a/backend/donations/views/ngo.py +++ b/backend/donations/views/ngo.py @@ -1,6 +1,6 @@ import logging import re -from datetime import date, datetime, timedelta +from datetime import date, datetime from urllib.parse import urlparse from django.conf import settings @@ -443,7 +443,7 @@ def return_error(self, request, ngo, errors, is_ajax): class OwnFormDownloadLinkHandler(TemplateView): def get(self, request, donor_date_str, donor_id, donor_hash, *args, **kwargs): # Don't allow downloading donation forms older than this - cutoff_date = timezone.now() - timedelta(days=365) + cutoff_date = timezone.now() - timezone.timedelta(days=365) try: donor = Donor.objects.get(pk=donor_id, date_created__gte=cutoff_date) except Donor.DoesNotExist: diff --git a/backend/redirectioneaza/settings.py b/backend/redirectioneaza/settings.py index 2f355d6c..09346b5d 100644 --- a/backend/redirectioneaza/settings.py +++ b/backend/redirectioneaza/settings.py @@ -46,6 +46,7 @@ ENABLE_CACHE=(bool, True), ENABLE_FORMS_DOWNLOAD=(bool, True), TIMEDELTA_FORMS_DOWNLOAD_MINUTES=(int, 360), + TIMEDELTA_DONATIONS_LIMIT_DOWNLOAD_DAYS=(int, 31), IS_CONTAINERIZED=(bool, False), RECAPTCHA_ENABLED=(bool, True), # proxy headers @@ -541,6 +542,8 @@ day=DONATIONS_LIMIT_DAY, ).date() +TIMEDELTA_DONATIONS_LIMIT_DOWNLOAD_DAYS = env.int("TIMEDELTA_DONATIONS_LIMIT_DOWNLOAD_DAYS") + DONATIONS_XML_LIMIT_PER_FILE = env.int("DONATIONS_XML_LIMIT_PER_FILE") DONATIONS_LIMIT_MONTH_NAME = [