-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Timeout to registrations and renewals (#3678)
* Add ratelimit to registration view * Add reminder mail for open registrations * Add test case open registration * oops * fix tests * Update website/registrations/templates/registrations/email/reminder_open_registration.txt * Update website/registrations/templates/registrations/email/reminder_open_registration.html --------- Co-authored-by: Dirk Doesburg <[email protected]>
- Loading branch information
1 parent
5e8b011
commit ea67f71
Showing
6 changed files
with
115 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,38 @@ | ||
from datetime import timedelta | ||
|
||
from django.utils import timezone | ||
|
||
from celery import shared_task | ||
|
||
from registrations import services | ||
from registrations import emails | ||
|
||
from . import services | ||
from .models import Registration, Renewal | ||
|
||
|
||
@shared_task | ||
def minimise_registrations(): | ||
services.execute_data_minimisation() | ||
|
||
|
||
@shared_task | ||
def notify_old_entries(): | ||
# delete entries w updated_at 1 month ago and created_at 3m ago | ||
# notify (and update updated_at) entries w updated_at 1 month ago | ||
|
||
Registration.objects.filter( | ||
updated_at__lt=timezone.now() - timedelta(days=30), | ||
created_at__lt=timezone.now() - timedelta(days=90), | ||
).delete() | ||
Renewal.objects.filter( | ||
updated_at__lt=timezone.now() - timedelta(days=30), | ||
created_at__lt=timezone.now() - timedelta(days=90), | ||
).delete() | ||
|
||
for registration in Registration.objects.filter( | ||
updated_at__lt=timezone.now() - timedelta(days=30) | ||
): | ||
# send email | ||
emails.send_reminder_open_registration(registration) | ||
registration.updated_at = timezone.now() | ||
registration.save() |
11 changes: 11 additions & 0 deletions
11
website/registrations/templates/registrations/email/reminder_open_registration.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{% extends "email/board_email.html" %} | ||
|
||
{% block content %} | ||
Dear board,<br> | ||
|
||
<p>{{ name }} has an open registration for more than a month. The registration was created at {{ created_at }}. </p> | ||
|
||
<p>If {{ name }} does not complete their registration, the registration will automatically be removed three months after {{ created_at }}</p> | ||
<p>You may want to reach out to them.</p> | ||
|
||
{% endblock %} |
11 changes: 11 additions & 0 deletions
11
website/registrations/templates/registrations/email/reminder_open_registration.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Dear board, | ||
|
||
{{ name }} has an open registration for more then a month. The registration was created at {{ created_at }}. | ||
|
||
If {{ name }} does not complete their registration, the registration will automatically be removed three months after {{ created_at }}. | ||
|
||
You may want to reach out to them. | ||
|
||
Kisses, | ||
|
||
The website |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,11 +7,15 @@ | |
from django.template.defaultfilters import floatformat | ||
from django.test import TestCase | ||
from django.urls import reverse | ||
from django.utils import translation | ||
from django.utils import timezone, translation | ||
|
||
from freezegun import freeze_time | ||
|
||
from members.models import Member, Profile | ||
from members.models.membership import Membership | ||
from registrations import emails | ||
from registrations.models import Registration, Renewal | ||
from registrations.models import Entry, Registration, Renewal | ||
from registrations.tasks import notify_old_entries | ||
from utils.snippets import send_email | ||
|
||
|
||
|
@@ -214,6 +218,41 @@ def test_send_new_renewal_board_message(self, send_email): | |
}, | ||
) | ||
|
||
@mock.patch("registrations.emails.send_email") | ||
def test_send_reminder_open_registration(self, send_email): | ||
with freeze_time("2024-01-01"): | ||
registration = Registration.objects.create( | ||
first_name="John", | ||
last_name="Doe", | ||
email="[email protected]", | ||
programme="computingscience", | ||
starting_year=2014, | ||
address_street="Heyendaalseweg 135", | ||
address_street2="", | ||
address_postal_code="6525AJ", | ||
address_city="Nijmegen", | ||
address_country="NL", | ||
phone_number="06123456789", | ||
birthday=timezone.now().replace(year=1990), | ||
length=Entry.MEMBERSHIP_YEAR, | ||
membership_type=Membership.MEMBER, | ||
status=Entry.STATUS_CONFIRM, | ||
) | ||
|
||
with freeze_time("2024-02-10"): | ||
notify_old_entries() | ||
|
||
send_email.assert_called_once_with( | ||
to=[settings.BOARD_NOTIFICATION_ADDRESS], | ||
subject="Open registration for more than one month", | ||
txt_template="registrations/email/reminder_open_registration.txt", | ||
html_template="registrations/email/reminder_open_registration.html", | ||
context={ | ||
"name": registration.get_full_name(), | ||
"created_at": registration.created_at, | ||
}, | ||
) | ||
|
||
@mock.patch("registrations.emails.send_email") | ||
def test_send_references_information_message(self, send_email): | ||
with self.subTest("Registrations"): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters