Browse Source

Don't send monthly reports to inactive accounts (no pings in 6 months)

pull/199/head
Pēteris Caune 6 years ago
parent
commit
58cfaaa527
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
3 changed files with 26 additions and 2 deletions
  1. +1
    -0
      CHANGELOG.md
  2. +6
    -2
      hc/accounts/models.py
  3. +19
    -0
      hc/accounts/tests/test_profile.py

+ 1
- 0
CHANGELOG.md View File

@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.
### Improvements
- Load settings from environment variables
- Add "List-Unsubscribe" header to alert and report emails
- Don't send monthly reports to inactive accounts (no pings in 6 months)
### Bug Fixes
- During DST transition, handle ambiguous dates as pre-transition


+ 6
- 2
hc/accounts/models.py View File

@ -133,8 +133,12 @@ class Profile(models.Model):
def send_report(self, nag=False):
checks = self.checks_from_all_teams()
# Is there at least one check that has received a ping?
if not checks.filter(last_ping__isnull=False).exists():
# Has there been a ping in last 6 months?
result = checks.aggregate(models.Max("last_ping"))
last_ping = result["last_ping__max"]
six_months_ago = timezone.now() - timedelta(days=180)
if last_ping is None or last_ping < six_months_ago:
return False
# Is there at least one check that is down?


+ 19
- 0
hc/accounts/tests/test_profile.py View File

@ -64,6 +64,25 @@ class ProfileTestCase(BaseTestCase):
self.assertEqual(message.subject, 'Monthly Report')
self.assertIn("Test Check", message.body)
def test_it_skips_report_if_no_pings(self):
check = Check(name="Test Check", user=self.alice)
check.save()
sent = self.profile.send_report()
self.assertFalse(sent)
self.assertEqual(len(mail.outbox), 0)
def test_it_skips_report_if_no_recent_pings(self):
check = Check(name="Test Check", user=self.alice)
check.last_ping = now() - td(days=365)
check.save()
sent = self.profile.send_report()
self.assertFalse(sent)
self.assertEqual(len(mail.outbox), 0)
def test_it_sends_nag(self):
check = Check(name="Test Check", user=self.alice)
check.status = "down"


Loading…
Cancel
Save