Skip to content

Commit

Permalink
Allow download of donations archive after the donation limit expired (#…
Browse files Browse the repository at this point in the history
…305)

* Allow download of donations archive after the donation limit expired

* Always use timedelta from timezone
  • Loading branch information
danniel authored May 30, 2024
1 parent f9df724 commit 5396973
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
4 changes: 3 additions & 1 deletion backend/donations/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions backend/donations/views/my_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 = {
Expand Down
4 changes: 2 additions & 2 deletions backend/donations/views/ngo.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions backend/redirectioneaza/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = [
Expand Down

0 comments on commit 5396973

Please sign in to comment.