Browse Source

sendreports doesn't send nags if nag_period=0 ("disabled"). This would result in an infinite loop of nag emails.

pull/149/head
Pēteris Caune 7 years ago
parent
commit
266fbd225d
2 changed files with 11 additions and 1 deletions
  1. +2
    -1
      hc/api/management/commands/sendreports.py
  2. +9
    -0
      hc/api/tests/test_sendreports.py

+ 2
- 1
hc/api/management/commands/sendreports.py View File

@ -4,7 +4,7 @@ import time
from django.core.management.base import BaseCommand
from django.db.models import Q
from django.utils import timezone
from hc.accounts.models import Profile
from hc.accounts.models import NO_NAG, Profile
from hc.api.models import Check
@ -63,6 +63,7 @@ class Command(BaseCommand):
def handle_one_nag(self):
now = timezone.now()
q = Profile.objects.filter(next_nag_date__lt=now)
q = q.exclude(nag_period=NO_NAG)
profile = q.first()
if profile is None:


+ 9
- 0
hc/api/tests/test_sendreports.py View File

@ -70,6 +70,15 @@ class SendAlertsTestCase(BaseTestCase):
self.profile.next_nag_date = now() + td(days=1)
self.profile.save()
# If next_nag_date is in future, a nag should not get sent.
found = Command().handle_one_nag()
self.assertFalse(found)
def test_it_obeys_nag_period(self):
self.profile.nag_period = td()
self.profile.save()
# If nag_period is 0 ("disabled"), a nag should not get sent.
found = Command().handle_one_nag()
self.assertFalse(found)


Loading…
Cancel
Save