Skip to content

Commit 9b27411

Browse files
committed
Added group secretaries to the alias lists. Refactored related utility functions to less code with fewer branches with greater generality.
- Legacy-Id: 10543
1 parent f5ca3a1 commit 9b27411

3 files changed

Lines changed: 34 additions & 50 deletions

File tree

ietf/bin/generate-draft-aliases

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ django.setup()
3838
from django.conf import settings
3939

4040
from ietf.doc.models import Document
41-
from ietf.group.utils import get_group_chairs_emails, get_group_ads_emails
41+
from ietf.group.utils import get_group_role_emails, get_group_ad_emails
4242
from ietf.utils.aliases import *
4343
import time
4444

@@ -47,7 +47,7 @@ def get_draft_ad_emails(draft):
4747
# If working group document, return current WG ADs
4848
wg = draft.group
4949
if wg and wg.acronym != 'none' and wg.parent and wg.parent.acronym != 'none':
50-
return get_group_ads_emails(wg)
50+
return get_group_ad_emails(wg)
5151
# If not, return explicit AD set (whether up to date or not)
5252
ad = draft.ad
5353
#return [ad and ad.user and ad.user.email]
@@ -147,7 +147,7 @@ if __name__ == '__main__':
147147

148148
# .chairs = group chairs
149149
if draft.group:
150-
handle_sublist(afile, vfile, alias+'.chairs', get_group_chairs_emails(draft.group))
150+
handle_sublist(afile, vfile, alias+'.chairs', get_group_role_emails(draft.group, ['chair', 'secr']))
151151

152152
# .ad = sponsoring AD / WG AD (WG document)
153153
handle_sublist(afile, vfile, alias+'.ad', get_draft_ad_emails(draft))

ietf/bin/generate-wg-aliases

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ django.setup()
2626
from django.conf import settings
2727

2828
from ietf.group.models import Group
29-
from ietf.group.utils import get_group_ads_emails, get_group_chairs_emails, get_area_ads_emails, get_area_chairs_emails
29+
from ietf.group.utils import get_group_ad_emails, get_group_role_emails, get_child_group_role_emails
3030
from ietf.utils.aliases import dump_sublist
3131

3232
# from secr/utils/group.py..
@@ -69,8 +69,8 @@ if __name__ == '__main__':
6969

7070
for wg in interesting_wgs.distinct().iterator():
7171
name = wg.acronym
72-
dump_sublist(afile, vfile, name+'-ads', settings.GROUP_VIRTUAL_DOMAIN, get_group_ads_emails(wg))
73-
dump_sublist(afile, vfile, name+'-chairs', settings.GROUP_VIRTUAL_DOMAIN, get_group_chairs_emails(wg))
72+
dump_sublist(afile, vfile, name+'-ads', settings.GROUP_VIRTUAL_DOMAIN, get_group_ad_emails(wg))
73+
dump_sublist(afile, vfile, name+'-chairs', settings.GROUP_VIRTUAL_DOMAIN, get_group_role_emails(wg, ['chair', 'secr']))
7474

7575
# - status = Active
7676
rgs = Group.objects.filter(type='rg').all()
@@ -82,15 +82,16 @@ if __name__ == '__main__':
8282

8383
for rg in interesting_rgs.distinct().iterator():
8484
name = rg.acronym
85-
#dump_sublist('%s%s' % (name, '-ads'), get_group_ads_emails, rg, True)
86-
dump_sublist(afile, vfile, name+'-chairs', settings.GROUP_VIRTUAL_DOMAIN, get_group_chairs_emails(rg))
85+
#dump_sublist('%s%s' % (name, '-ads'), get_group_ad_emails, rg, True)
86+
dump_sublist(afile, vfile, name+'-chairs', settings.GROUP_VIRTUAL_DOMAIN, get_group_role_emails(rg, ['chair', 'secr']))
8787

8888
# Additionally, for areaz, we should list -ads and -chairs
8989
# (for every chair in active groups within the area).
9090
areas = Group.objects.filter(type='area').all()
9191
active_areas = areas.filter(state__in=ACTIVE_STATES)
9292
for area in active_areas:
9393
name = area.acronym
94-
dump_sublist(afile, vfile, name+'-ads' , settings.GROUP_VIRTUAL_DOMAIN, get_area_ads_emails(area))
95-
dump_sublist(afile, vfile, name+'-chairs', settings.GROUP_VIRTUAL_DOMAIN, get_area_chairs_emails(area)+get_area_ads_emails(area))
94+
area_ad_emails = get_group_role_emails(area, ['pre-ad', 'ad', 'chair'])
95+
dump_sublist(afile, vfile, name+'-ads' , settings.GROUP_VIRTUAL_DOMAIN, area_ad_emails)
96+
dump_sublist(afile, vfile, name+'-chairs', settings.GROUP_VIRTUAL_DOMAIN, (get_child_group_role_emails(area, ['chair', 'secr']) | area_ad_emails))
9697

ietf/group/utils.py

Lines changed: 23 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from django.shortcuts import get_object_or_404
44

5+
import debug # pyflakes:ignore
6+
57
from ietf.group.models import Group, RoleHistory
68
from ietf.person.models import Email
79
from ietf.utils.history import get_history_object_for, copy_many_to_many_for_history
@@ -44,53 +46,34 @@ def get_charter_text(group):
4446
except IOError:
4547
return 'Error Loading Group Charter'
4648

47-
def get_area_ads_emails(area):
48-
if area.acronym == 'none':
49-
return []
50-
emails = [r.email.email_address()
51-
for r in area.role_set.filter(name__in=('pre-ad', 'ad', 'chair'))]
52-
return filter(None, emails)
53-
54-
def get_group_ads_emails(wg):
55-
" Get list of area directors' emails for a given WG "
56-
if wg.acronym == 'none':
57-
return []
58-
59-
ad_emails = set()
60-
61-
if wg.parent and wg.parent.acronym != 'none':
62-
# Include the _current_ list of ads for the area!
63-
ad_emails.update(get_area_ads_emails(wg.parent))
49+
def get_group_role_emails(group, roles):
50+
"Get a list of email addresses for a given WG and Role"
51+
if not group or not group.acronym or group.acronym == 'none':
52+
return set()
53+
emails = Email.objects.filter(role__group=group, role__name__in=roles)
54+
return set(filter(None, [e.email_address() for e in emails]))
55+
56+
def get_child_group_role_emails(parent, roles, group_type='wg'):
57+
"""Get a list of email addresses for a given set of
58+
roles for all child groups of a given type"""
59+
emails = set()
60+
groups = Group.objects.filter(parent=parent, type=group_type, state="active")
61+
for group in groups:
62+
emails |= get_group_role_emails(group, roles)
63+
return emails
6464

65+
def get_group_ad_emails(wg):
66+
" Get list of area directors' email addresses for a given WG "
67+
if not wg.acronym or wg.acronym == 'none':
68+
return set()
69+
emails = get_group_role_emails(wg.parent, roles=('pre-ad', 'ad', 'chair'))
6570
# Make sure the assigned AD is included (in case that is not one of the area ADs)
6671
if wg.state.slug=='active':
6772
wg_ad_email = wg.ad_role() and wg.ad_role().email.address
6873
if wg_ad_email:
69-
ad_emails.add(wg_ad_email)
70-
71-
return list(ad_emails)
72-
73-
def get_group_chairs_emails(wg):
74-
" Get list of area chairs' emails for a given WG "
75-
if wg.acronym == 'none':
76-
return []
77-
emails = Email.objects.filter(role__group=wg,
78-
role__name='chair')
79-
if not emails:
80-
return []
81-
emails = [e.email_address() for e in emails]
82-
emails = filter(None, emails)
74+
emails.add(wg_ad_email)
8375
return emails
8476

85-
def get_area_chairs_emails(area):
86-
emails = {}
87-
# XXX - should we filter these by validity? Or not?
88-
wgs = Group.objects.filter(parent=area, type="wg", state="active")
89-
for wg in wgs:
90-
for e in get_group_chairs_emails(wg):
91-
emails[e] = True
92-
return emails.keys()
93-
9477
def save_milestone_in_history(milestone):
9578
h = get_history_object_for(milestone)
9679
h.milestone = milestone

0 commit comments

Comments
 (0)