Browse Source

Clear out `Profile.next_report_date` and `Profile.next_nag_date` when unsubscribing from reports.

pull/149/head
Pēteris Caune 7 years ago
parent
commit
fb17211320
2 changed files with 8 additions and 0 deletions
  1. +6
    -0
      hc/accounts/tests/test_unsubscribe_reports.py
  2. +2
    -0
      hc/accounts/views.py

+ 6
- 0
hc/accounts/tests/test_unsubscribe_reports.py View File

@ -1,13 +1,16 @@
from datetime import timedelta as td from datetime import timedelta as td
from django.core import signing from django.core import signing
from django.utils.timezone import now
from hc.test import BaseTestCase from hc.test import BaseTestCase
class UnsubscribeReportsTestCase(BaseTestCase): class UnsubscribeReportsTestCase(BaseTestCase):
def test_token_works(self): def test_token_works(self):
self.profile.next_report_date = now()
self.profile.nag_period = td(hours=1) self.profile.nag_period = td(hours=1)
self.profile.next_nag_date = now()
self.profile.save() self.profile.save()
token = signing.Signer().sign("foo") token = signing.Signer().sign("foo")
@ -17,7 +20,10 @@ class UnsubscribeReportsTestCase(BaseTestCase):
self.profile.refresh_from_db() self.profile.refresh_from_db()
self.assertFalse(self.profile.reports_allowed) self.assertFalse(self.profile.reports_allowed)
self.assertIsNone(self.profile.next_report_date)
self.assertEqual(self.profile.nag_period.total_seconds(), 0) self.assertEqual(self.profile.nag_period.total_seconds(), 0)
self.assertIsNone(self.profile.next_nag_date)
def test_bad_token_gets_rejected(self): def test_bad_token_gets_rejected(self):
url = "/accounts/unsubscribe_reports/alice/?token=invalid" url = "/accounts/unsubscribe_reports/alice/?token=invalid"


+ 2
- 0
hc/accounts/views.py View File

@ -370,7 +370,9 @@ def unsubscribe_reports(request, username):
user = User.objects.get(username=username) user = User.objects.get(username=username)
profile = Profile.objects.for_user(user) profile = Profile.objects.for_user(user)
profile.reports_allowed = False profile.reports_allowed = False
profile.next_report_date = None
profile.nag_period = td() profile.nag_period = td()
profile.next_nag_date = None
profile.save() profile.save()
return render(request, "accounts/unsubscribed.html") return render(request, "accounts/unsubscribed.html")


Loading…
Cancel
Save