fix: Don't send I-D expiration warning if it will happen within 12 hours. (#4700)

* fix: 4635

* fix: use timezone.now rather than datetime.datetime.now

* chore: fix merge error

Co-authored-by: Robert Sparks <rjsparks@nostrum.com>
This commit is contained in:
Russ Housley 2022-11-08 11:06:42 -05:00 committed by GitHub
parent d7e3bddeb4
commit 612f33e014
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 2 deletions

View file

@ -87,6 +87,13 @@ def send_expire_warning_for_draft(doc):
return # don't warn about dead or inactive documents
expiration = doc.expires.astimezone(DEADLINE_TZINFO).date()
now_plus_12hours = timezone.now() + datetime.timedelta(hours=12)
soon = now_plus_12hours.date()
if expiration <= soon:
# The document will expire very soon, which will send email to the
# same people, so do not send the warning at this point in time
return
(to,cc) = gather_address_lists('doc_expires_soon',doc=doc)

View file

@ -659,7 +659,7 @@ class ExpireIDsTests(DraftFileMixin, TestCase):
self.assertEqual(len(list(get_soon_to_expire_drafts(14))), 0)
# hack into expirable state
# hack into expirable state to expire in 10 days
draft.set_state(State.objects.get(type_id='draft-iesg',slug='idexists'))
draft.expires = timezone.now() + datetime.timedelta(days=10)
draft.save_with_history([DocEvent.objects.create(doc=draft, rev=draft.rev, type="changed_document", by=Person.objects.get(user__username="secretary"), desc="Test")])
@ -675,8 +675,17 @@ class ExpireIDsTests(DraftFileMixin, TestCase):
self.assertTrue('draft-ietf-mars-test@' in outbox[-1]['To']) # Gets the authors
self.assertTrue('mars-chairs@ietf.org' in outbox[-1]['Cc'])
self.assertTrue('aread@' in outbox[-1]['Cc'])
# hack into expirable state to expire in 10 hours
draft.expires = timezone.now() + datetime.timedelta(hours=10)
draft.save_with_history([DocEvent.objects.create(doc=draft, rev=draft.rev, type="changed_document", by=Person.objects.get(user__username="secretary"), desc="Test")])
# test send warning is not sent for a document so close to expiration
mailbox_before = len(outbox)
send_expire_warning_for_draft(draft)
self.assertEqual(len(outbox), mailbox_before)
#Check that we don't sent expiration warnings for dead or replaced drafts
# Check that we don't sent expiration warnings for dead or replaced drafts
old_state = draft.get_state_slug("draft-iesg")
mailbox_before = len(outbox)
draft.set_state(State.objects.get(type_id="draft-iesg",slug="dead"))