forked from GithubBackups/healthchecks
Don't send monthly reports to inactive accounts (no pings in 6 months)
This commit is contained in:
parent
9f02371d6a
commit
58cfaaa527
@ -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
|
||||
|
@ -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?
|
||||
|
@ -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…
x
Reference in New Issue
Block a user