Skip to content

Commit

Permalink
fix: repair generate_draft_aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
rjsparks committed Jul 7, 2023
1 parent 11ec368 commit 78b6f06
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 20 deletions.
12 changes: 8 additions & 4 deletions ietf/doc/management/commands/generate_draft_aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from ietf.group.utils import get_group_role_emails, get_group_ad_emails
from ietf.utils.aliases import dump_sublist
from utils.mail import parseaddr
from ietf.utils import log

DEFAULT_YEARS = 2

Expand Down Expand Up @@ -120,16 +121,19 @@ def handle(self, *args, **options):
vfile.write("%s anything\n" % settings.DRAFT_VIRTUAL_DOMAIN)

# Internet-Drafts with active status or expired within DEFAULT_YEARS
drafts = Document.objects.filter(name__startswith='draft-')
drafts = Document.objects.filter(type_id="draft")
active_drafts = drafts.filter(states__slug='active')
inactive_recent_drafts = drafts.exclude(states__slug='active').filter(expires__gte=show_since)
interesting_drafts = active_drafts | inactive_recent_drafts

alias_domains = ['ietf.org', ]
for draft in interesting_drafts.distinct().iterator():
# Omit RFCs, unless they were published in the last DEFAULT_YEARS
if draft.docalias.filter(name__startswith='rfc'):
if draft.latest_event(type='published_rfc').time < show_since:
# Omit drafts that became RFCs, unless they were published in the last DEFAULT_YEARS
if draft.get_state_slug()=="rfc":
rfc_alias = next(iter(draft.related_that_doc("became_rfc")), None)
log.assertion("rfc_alias is not None")
rfc = rfc_alias.document
if rfc.latest_event(type='published_rfc').time < show_since:
continue

alias = draft.name
Expand Down
46 changes: 30 additions & 16 deletions ietf/doc/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2079,10 +2079,14 @@ def testManagementCommand(self):
mars.role_set.create(name_id='chair', person=marschairman, email=marschairman.email())
doc1 = IndividualDraftFactory(authors=[author1], shepherd=shepherd.email(), ad=ad)
doc2 = WgDraftFactory(name='draft-ietf-mars-test', group__acronym='mars', authors=[author2], ad=ad)
doc3 = WgRfcFactory.create(name='draft-ietf-mars-finished', group__acronym='mars', authors=[author3], ad=ad, std_level_id='ps', states=[('draft','rfc'),('draft-iesg','pub')], time=a_month_ago)
DocEventFactory.create(doc=doc3, type='published_rfc', time=a_month_ago)
doc4 = WgRfcFactory.create(authors=[author4,author5], ad=ad, std_level_id='ps', states=[('draft','rfc'),('draft-iesg','pub')], time=datetime.datetime(2010,10,10, tzinfo=ZoneInfo(settings.TIME_ZONE)))
DocEventFactory.create(doc=doc4, type='published_rfc', time=datetime.datetime(2010, 10, 10, tzinfo=RPC_TZINFO))
doc3 = WgDraftFactory.create(name='draft-ietf-mars-finished', group__acronym='mars', authors=[author3], ad=ad, std_level_id='ps', states=[('draft','rfc'),('draft-iesg','pub')], time=a_month_ago)
rfc3 = WgRfcFactory()
DocEventFactory.create(doc=rfc3, type='published_rfc', time=a_month_ago)
doc3.relateddocument_set.create(relationship_id="became_rfc", target=rfc3.docalias.first())
doc4 = WgDraftFactory.create(authors=[author4,author5], ad=ad, std_level_id='ps', states=[('draft','rfc'),('draft-iesg','pub')], time=datetime.datetime(2010,10,10, tzinfo=ZoneInfo(settings.TIME_ZONE)))
rfc4 = WgRfcFactory()
DocEventFactory.create(doc=rfc4, type='published_rfc', time=datetime.datetime(2010, 10, 10, tzinfo=RPC_TZINFO))
doc4.relateddocument_set.create(relationship_id="became_rfc", target=rfc4.docalias.first())
doc5 = IndividualDraftFactory(authors=[author6])

args = [ ]
Expand All @@ -2093,7 +2097,7 @@ def testManagementCommand(self):

with open(settings.DRAFT_ALIASES_PATH) as afile:
acontent = afile.read()
self.assertTrue(all([x in acontent for x in [
for x in [
'xfilter-' + doc1.name,
'xfilter-' + doc1.name + '.ad',
'xfilter-' + doc1.name + '.authors',
Expand All @@ -2111,32 +2115,39 @@ def testManagementCommand(self):
'xfilter-' + doc5.name,
'xfilter-' + doc5.name + '.authors',
'xfilter-' + doc5.name + '.all',
]]))
self.assertFalse(all([x in acontent for x in [
]:
self.assertIn(x, acontent)

for x in [
'xfilter-' + doc1.name + '.chairs',
'xfilter-' + doc2.name + '.shepherd',
'xfilter-' + doc3.name + '.shepherd',
'xfilter-' + doc4.name,
'xfilter-' + doc5.name + '.shepherd',
'xfilter-' + doc5.name + '.ad',
]]))
]:
self.assertNotIn(x, acontent)

with open(settings.DRAFT_VIRTUAL_PATH) as vfile:
vcontent = vfile.read()
self.assertTrue(all([x in vcontent for x in [
for x in [
ad.email_address(),
shepherd.email_address(),
marschairman.email_address(),
author1.email_address(),
author2.email_address(),
author3.email_address(),
author6.email_address(),
]]))
self.assertFalse(all([x in vcontent for x in [
]:
self.assertIn(x, vcontent)

for x in [
author4.email_address(),
author5.email_address(),
]]))
self.assertTrue(all([x in vcontent for x in [
]:
self.assertNotIn(x, vcontent)

for x in [
'xfilter-' + doc1.name,
'xfilter-' + doc1.name + '.ad',
'xfilter-' + doc1.name + '.authors',
Expand All @@ -2154,15 +2165,18 @@ def testManagementCommand(self):
'xfilter-' + doc5.name,
'xfilter-' + doc5.name + '.authors',
'xfilter-' + doc5.name + '.all',
]]))
self.assertFalse(all([x in vcontent for x in [
]:
self.assertIn(x, vcontent)

for x in [
'xfilter-' + doc1.name + '.chairs',
'xfilter-' + doc2.name + '.shepherd',
'xfilter-' + doc3.name + '.shepherd',
'xfilter-' + doc4.name,
'xfilter-' + doc5.name + '.shepherd',
'xfilter-' + doc5.name + '.ad',
]]))
]:
self.assertNotIn(x, vcontent)

class EmailAliasesTests(TestCase):

Expand Down

0 comments on commit 78b6f06

Please sign in to comment.