Added group secretaries to the alias lists. Refactored related utility functions to less code with fewer branches with greater generality.

- Legacy-Id: 10543
This commit is contained in:
Henrik Levkowetz 2015-12-04 20:30:43 +00:00
parent f5ca3a12bc
commit 9b274111eb
3 changed files with 33 additions and 49 deletions

View file

@ -38,7 +38,7 @@ django.setup()
from django.conf import settings
from ietf.doc.models import Document
from ietf.group.utils import get_group_chairs_emails, get_group_ads_emails
from ietf.group.utils import get_group_role_emails, get_group_ad_emails
from ietf.utils.aliases import *
import time
@ -47,7 +47,7 @@ def get_draft_ad_emails(draft):
# If working group document, return current WG ADs
wg = draft.group
if wg and wg.acronym != 'none' and wg.parent and wg.parent.acronym != 'none':
return get_group_ads_emails(wg)
return get_group_ad_emails(wg)
# If not, return explicit AD set (whether up to date or not)
ad = draft.ad
#return [ad and ad.user and ad.user.email]
@ -147,7 +147,7 @@ if __name__ == '__main__':
# .chairs = group chairs
if draft.group:
handle_sublist(afile, vfile, alias+'.chairs', get_group_chairs_emails(draft.group))
handle_sublist(afile, vfile, alias+'.chairs', get_group_role_emails(draft.group, ['chair', 'secr']))
# .ad = sponsoring AD / WG AD (WG document)
handle_sublist(afile, vfile, alias+'.ad', get_draft_ad_emails(draft))

View file

@ -26,7 +26,7 @@ django.setup()
from django.conf import settings
from ietf.group.models import Group
from ietf.group.utils import get_group_ads_emails, get_group_chairs_emails, get_area_ads_emails, get_area_chairs_emails
from ietf.group.utils import get_group_ad_emails, get_group_role_emails, get_child_group_role_emails
from ietf.utils.aliases import dump_sublist
# from secr/utils/group.py..
@ -69,8 +69,8 @@ if __name__ == '__main__':
for wg in interesting_wgs.distinct().iterator():
name = wg.acronym
dump_sublist(afile, vfile, name+'-ads', settings.GROUP_VIRTUAL_DOMAIN, get_group_ads_emails(wg))
dump_sublist(afile, vfile, name+'-chairs', settings.GROUP_VIRTUAL_DOMAIN, get_group_chairs_emails(wg))
dump_sublist(afile, vfile, name+'-ads', settings.GROUP_VIRTUAL_DOMAIN, get_group_ad_emails(wg))
dump_sublist(afile, vfile, name+'-chairs', settings.GROUP_VIRTUAL_DOMAIN, get_group_role_emails(wg, ['chair', 'secr']))
# - status = Active
rgs = Group.objects.filter(type='rg').all()
@ -82,8 +82,8 @@ if __name__ == '__main__':
for rg in interesting_rgs.distinct().iterator():
name = rg.acronym
#dump_sublist('%s%s' % (name, '-ads'), get_group_ads_emails, rg, True)
dump_sublist(afile, vfile, name+'-chairs', settings.GROUP_VIRTUAL_DOMAIN, get_group_chairs_emails(rg))
#dump_sublist('%s%s' % (name, '-ads'), get_group_ad_emails, rg, True)
dump_sublist(afile, vfile, name+'-chairs', settings.GROUP_VIRTUAL_DOMAIN, get_group_role_emails(rg, ['chair', 'secr']))
# Additionally, for areaz, we should list -ads and -chairs
# (for every chair in active groups within the area).
@ -91,6 +91,7 @@ if __name__ == '__main__':
active_areas = areas.filter(state__in=ACTIVE_STATES)
for area in active_areas:
name = area.acronym
dump_sublist(afile, vfile, name+'-ads' , settings.GROUP_VIRTUAL_DOMAIN, get_area_ads_emails(area))
dump_sublist(afile, vfile, name+'-chairs', settings.GROUP_VIRTUAL_DOMAIN, get_area_chairs_emails(area)+get_area_ads_emails(area))
area_ad_emails = get_group_role_emails(area, ['pre-ad', 'ad', 'chair'])
dump_sublist(afile, vfile, name+'-ads' , settings.GROUP_VIRTUAL_DOMAIN, area_ad_emails)
dump_sublist(afile, vfile, name+'-chairs', settings.GROUP_VIRTUAL_DOMAIN, (get_child_group_role_emails(area, ['chair', 'secr']) | area_ad_emails))

View file

@ -2,6 +2,8 @@ import os
from django.shortcuts import get_object_or_404
import debug # pyflakes:ignore
from ietf.group.models import Group, RoleHistory
from ietf.person.models import Email
from ietf.utils.history import get_history_object_for, copy_many_to_many_for_history
@ -44,53 +46,34 @@ def get_charter_text(group):
except IOError:
return 'Error Loading Group Charter'
def get_area_ads_emails(area):
if area.acronym == 'none':
return []
emails = [r.email.email_address()
for r in area.role_set.filter(name__in=('pre-ad', 'ad', 'chair'))]
return filter(None, emails)
def get_group_role_emails(group, roles):
"Get a list of email addresses for a given WG and Role"
if not group or not group.acronym or group.acronym == 'none':
return set()
emails = Email.objects.filter(role__group=group, role__name__in=roles)
return set(filter(None, [e.email_address() for e in emails]))
def get_group_ads_emails(wg):
" Get list of area directors' emails for a given WG "
if wg.acronym == 'none':
return []
ad_emails = set()
if wg.parent and wg.parent.acronym != 'none':
# Include the _current_ list of ads for the area!
ad_emails.update(get_area_ads_emails(wg.parent))
def get_child_group_role_emails(parent, roles, group_type='wg'):
"""Get a list of email addresses for a given set of
roles for all child groups of a given type"""
emails = set()
groups = Group.objects.filter(parent=parent, type=group_type, state="active")
for group in groups:
emails |= get_group_role_emails(group, roles)
return emails
def get_group_ad_emails(wg):
" Get list of area directors' email addresses for a given WG "
if not wg.acronym or wg.acronym == 'none':
return set()
emails = get_group_role_emails(wg.parent, roles=('pre-ad', 'ad', 'chair'))
# Make sure the assigned AD is included (in case that is not one of the area ADs)
if wg.state.slug=='active':
wg_ad_email = wg.ad_role() and wg.ad_role().email.address
if wg_ad_email:
ad_emails.add(wg_ad_email)
return list(ad_emails)
def get_group_chairs_emails(wg):
" Get list of area chairs' emails for a given WG "
if wg.acronym == 'none':
return []
emails = Email.objects.filter(role__group=wg,
role__name='chair')
if not emails:
return []
emails = [e.email_address() for e in emails]
emails = filter(None, emails)
emails.add(wg_ad_email)
return emails
def get_area_chairs_emails(area):
emails = {}
# XXX - should we filter these by validity? Or not?
wgs = Group.objects.filter(parent=area, type="wg", state="active")
for wg in wgs:
for e in get_group_chairs_emails(wg):
emails[e] = True
return emails.keys()
def save_milestone_in_history(milestone):
h = get_history_object_for(milestone)
h.milestone = milestone