Skip to content

Commit 90c3426

Browse files
committed
updated mailtoken utilities to match the model refactor. Morphed all the code using the utilities to match. Added paths to get Cc through as needed. Next up: Recipient selection form for the iesg save-and-send-email workflow
- Legacy-Id: 10040
1 parent d16efcc commit 90c3426

24 files changed

Lines changed: 333 additions & 233 deletions

ietf/doc/expire.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
from ietf.person.models import Person
1111
from ietf.meeting.models import Meeting
1212
from ietf.doc.utils import add_state_change_event
13-
from ietf.mailtoken.utils import gather_address_list
14-
13+
from ietf.mailtoken.utils import gather_address_lists
1514

1615

1716
def expirable_draft(draft):
@@ -71,8 +70,7 @@ def send_expire_warning_for_draft(doc):
7170

7271
expiration = doc.expires.date()
7372

74-
to = gather_address_list('doc_expires_soon',doc=doc)
75-
cc = gather_address_list('doc_expires_soon_cc',doc=doc)
73+
(to,cc) = gather_address_lists('doc_expires_soon',doc=doc)
7674

7775
s = doc.get_state("draft-iesg")
7876
state = s.name if s else "I-D Exists"
@@ -97,8 +95,7 @@ def send_expire_notice_for_draft(doc):
9795
state = s.name if s else "I-D Exists"
9896

9997
request = None
100-
to = gather_address_list('doc_expired',doc=doc)
101-
cc = gather_address_list('doc_expired_cc',doc=doc)
98+
(to,cc) = gather_address_lists('doc_expired',doc=doc)
10299
send_mail(request, to,
103100
"I-D Expiring System <ietf-secretariat-reply@ietf.org>",
104101
u"I-D was expired %s" % doc.file_tag(),

ietf/doc/mails.py

Lines changed: 62 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
from ietf.person.models import Person
1515
from ietf.group.models import Role
1616
from ietf.doc.models import Document
17-
from ietf.mailtoken.utils import gather_addresses, gather_address_list
17+
from ietf.mailtoken.utils import gather_address_lists
1818

1919
def email_state_changed(request, doc, text, mailtoken_id=None):
20-
to = gather_address_list(mailtoken_id or 'doc_state_edited',doc=doc)
20+
(to,cc) = gather_address_lists(mailtoken_id or 'doc_state_edited',doc=doc)
2121
if not to:
2222
return
2323

@@ -26,7 +26,8 @@ def email_state_changed(request, doc, text, mailtoken_id=None):
2626
"ID Tracker State Update Notice: %s" % doc.file_tag(),
2727
"doc/mail/state_changed_email.txt",
2828
dict(text=text,
29-
url=settings.IDTRACKER_BASE_URL + doc.get_absolute_url()))
29+
url=settings.IDTRACKER_BASE_URL + doc.get_absolute_url()),
30+
cc=cc)
3031

3132
def email_stream_changed(request, doc, old_stream, new_stream, text=""):
3233
"""Email the change text to the notify group and to the stream chairs"""
@@ -35,7 +36,7 @@ def email_stream_changed(request, doc, old_stream, new_stream, text=""):
3536
streams.append(old_stream.slug)
3637
if new_stream:
3738
streams.append(new_stream.slug)
38-
to = gather_address_list('doc_stream_changed',doc=doc,streams=streams)
39+
(to,cc) = gather_address_lists('doc_stream_changed',doc=doc,streams=streams)
3940

4041
if not to:
4142
return
@@ -48,12 +49,14 @@ def email_stream_changed(request, doc, old_stream, new_stream, text=""):
4849
"ID Tracker Stream Change Notice: %s" % doc.file_tag(),
4950
"doc/mail/stream_changed_email.txt",
5051
dict(text=text,
51-
url=settings.IDTRACKER_BASE_URL + doc.get_absolute_url()))
52+
url=settings.IDTRACKER_BASE_URL + doc.get_absolute_url()),
53+
cc=cc)
5254

5355
def email_pulled_from_rfc_queue(request, doc, comment, prev_state, next_state):
5456
extra=extra_automation_headers(doc)
55-
extra['Cc'] = gather_addresses('doc_pulled_from_rfc_queue_cc',doc=doc)
56-
send_mail(request, gather_address_list('doc_pulled_from_rfc_queue',doc=doc), None,
57+
addrs = gather_address_lists('doc_pulled_from_rfc_queue',doc=doc)
58+
extra['Cc'] = addrs.as_strings().cc
59+
send_mail(request, addrs.to , None,
5760
"%s changed state from %s to %s" % (doc.name, prev_state.name, next_state.name),
5861
"doc/mail/pulled_from_rfc_queue_email.txt",
5962
dict(doc=doc,
@@ -112,12 +115,14 @@ def generate_last_call_announcement(request, doc):
112115
else:
113116
ipr_links = None
114117

118+
119+
addrs = gather_address_lists('last_call_issued',doc=doc).as_strings()
115120
mail = render_to_string("doc/mail/last_call_announcement.txt",
116121
dict(doc=doc,
117122
doc_url=settings.IDTRACKER_BASE_URL + doc.get_absolute_url() + "ballot/",
118123
expiration_date=expiration_date.strftime("%Y-%m-%d"), #.strftime("%B %-d, %Y"),
119-
to=gather_addresses('last_call_issued',doc=doc),
120-
cc=gather_addresses('last_call_issued_cc',doc=doc),
124+
to=addrs.to,
125+
cc=addrs.cc,
121126
group=group,
122127
docs=[ doc ],
123128
urls=[ settings.IDTRACKER_BASE_URL + doc.get_absolute_url() ],
@@ -187,12 +192,13 @@ def generate_approval_mail_approved(request, doc):
187192

188193
doc_type = "RFC" if doc.get_state_slug() == "rfc" else "Internet Draft"
189194

195+
addrs = gather_address_lists('ballot_approved_ietf_stream',doc=doc).as_strings()
190196
return render_to_string("doc/mail/approval_mail.txt",
191197
dict(doc=doc,
192198
docs=[doc],
193199
doc_url=settings.IDTRACKER_BASE_URL + doc.get_absolute_url(),
194-
to = gather_addresses('ballot_approved_ietf_stream',doc=doc),
195-
cc = gather_addresses('ballot_approved_ietf_stream_cc',doc=doc),
200+
to = addrs.to,
201+
cc = addrs.cc,
196202
doc_type=doc_type,
197203
made_by=made_by,
198204
contacts=contacts,
@@ -205,14 +211,15 @@ def generate_approval_mail_rfc_editor(request, doc):
205211
# which does not happen now that we have conflict reviews.
206212
disapproved = doc.get_state_slug("draft-iesg") in DO_NOT_PUBLISH_IESG_STATES
207213
doc_type = "RFC" if doc.get_state_slug() == "rfc" else "Internet Draft"
214+
addrs = gather_address_lists('ballot_approved_conflrev', doc=doc).as_strings()
208215

209216
return render_to_string("doc/mail/approval_mail_rfc_editor.txt",
210217
dict(doc=doc,
211218
doc_url=settings.IDTRACKER_BASE_URL + doc.get_absolute_url(),
212219
doc_type=doc_type,
213220
disapproved=disapproved,
214-
to = gather_addresses('ballot_approved_conflrev', doc=doc),
215-
cc = gather_addresses('ballot_approved_conflrev_cc', doc=doc),
221+
to = addrs.to,
222+
cc = addrs.cc,
216223
)
217224
)
218225

@@ -242,8 +249,7 @@ def generate_publication_request(request, doc):
242249
)
243250

244251
def send_last_call_request(request, doc):
245-
to = gather_addresses('last_call_requested',doc=doc)
246-
cc = gather_addresses('last_call_requested_cc',doc=doc)
252+
(to, cc) = gather_address_lists('last_call_requested',doc=doc)
247253
frm = '"DraftTracker Mail System" <iesg-secretary@ietf.org>'
248254

249255
send_mail(request, to, frm,
@@ -255,7 +261,7 @@ def send_last_call_request(request, doc):
255261
cc=cc)
256262

257263
def email_resurrect_requested(request, doc, by):
258-
to = gather_address_list('resurrection_requested',doc=doc)
264+
(to, cc) = gather_address_lists('resurrection_requested',doc=doc)
259265

260266
if by.role_set.filter(name="secr", group__acronym="secretariat"):
261267
e = by.role_email("secr", group="secretariat")
@@ -268,39 +274,43 @@ def email_resurrect_requested(request, doc, by):
268274
"doc/mail/resurrect_request_email.txt",
269275
dict(doc=doc,
270276
by=frm,
271-
url=settings.IDTRACKER_BASE_URL + doc.get_absolute_url()))
277+
url=settings.IDTRACKER_BASE_URL + doc.get_absolute_url()),
278+
cc=cc)
272279

273280
def email_resurrection_completed(request, doc, requester):
274-
to = gather_address_list('resurrection_completed',doc=doc)
281+
(to, cc) = gather_address_lists('resurrection_completed',doc=doc)
275282
frm = "I-D Administrator <internet-drafts-reply@ietf.org>"
276283
send_mail(request, to, frm,
277284
"I-D Resurrection Completed - %s" % doc.file_tag(),
278285
"doc/mail/resurrect_completed_email.txt",
279286
dict(doc=doc,
280287
by=frm,
281-
url=settings.IDTRACKER_BASE_URL + doc.get_absolute_url()))
288+
url=settings.IDTRACKER_BASE_URL + doc.get_absolute_url()),
289+
cc=cc)
282290

283291
def email_ballot_deferred(request, doc, by, telechat_date):
284-
to = gather_addresses('ballot_deferred',doc=doc)
292+
(to, cc) = gather_address_lists('ballot_deferred',doc=doc)
285293
frm = "DraftTracker Mail System <iesg-secretary@ietf.org>"
286294
send_mail(request, to, frm,
287295
"IESG Deferred Ballot notification: %s" % doc.file_tag(),
288296
"doc/mail/ballot_deferred_email.txt",
289297
dict(doc=doc,
290298
by=by,
291299
action='deferred',
292-
telechat_date=telechat_date))
300+
telechat_date=telechat_date),
301+
cc=cc)
293302

294303
def email_ballot_undeferred(request, doc, by, telechat_date):
295-
to = gather_addresses('ballot_deferred',doc=doc)
304+
(to, cc) = gather_address_lists('ballot_deferred',doc=doc)
296305
frm = "DraftTracker Mail System <iesg-secretary@ietf.org>"
297306
send_mail(request, to, frm,
298307
"IESG Undeferred Ballot notification: %s" % doc.file_tag(),
299308
"doc/mail/ballot_deferred_email.txt",
300309
dict(doc=doc,
301310
by=by,
302311
action='undeferred',
303-
telechat_date=telechat_date))
312+
telechat_date=telechat_date),
313+
cc=cc)
304314

305315
def generate_issue_ballot_mail(request, doc, ballot):
306316
active_ads = Person.objects.filter(role__name="ad", role__group__state="active", role__group__type="area").distinct()
@@ -370,7 +380,7 @@ def formatted(val):
370380
)
371381
)
372382

373-
def email_iana(request, doc, to, msg):
383+
def email_iana(request, doc, to, msg, cc=None):
374384
# fix up message and send it with extra info on doc in headers
375385
import email
376386
parsed_msg = email.message_from_string(msg.encode("utf-8"))
@@ -383,7 +393,8 @@ def email_iana(request, doc, to, msg):
383393
send_mail_text(request, "IANA <%s>" % to,
384394
parsed_msg["From"], parsed_msg["Subject"],
385395
parsed_msg.get_payload(),
386-
extra=extra)
396+
extra=extra,
397+
cc=cc)
387398

388399
def extra_automation_headers(doc):
389400
extra = {}
@@ -394,24 +405,24 @@ def extra_automation_headers(doc):
394405

395406
def email_last_call_expired(doc):
396407
text = "IETF Last Call has ended, and the state has been changed to\n%s." % doc.get_state("draft-iesg").name
408+
addrs = gather_address_lists('last_call_expired',doc=doc)
397409

398410
send_mail(None,
399-
gather_addresses('last_call_expired',doc=doc),
411+
addrs.to,
400412
"DraftTracker Mail System <iesg-secretary@ietf.org>",
401413
"Last Call Expired: %s" % doc.file_tag(),
402414
"doc/mail/change_notice.txt",
403415
dict(text=text,
404416
doc=doc,
405417
url=settings.IDTRACKER_BASE_URL + doc.get_absolute_url()),
406-
cc = gather_addresses('last_call_expired_cc',doc=doc)
407-
)
418+
cc = addrs.cc)
408419

409420
def email_stream_state_changed(request, doc, prev_state, new_state, by, comment=""):
410-
recipients = gather_address_list('doc_stream_state_edited',doc=doc)
421+
(to, cc)= gather_address_lists('doc_stream_state_edited',doc=doc)
411422

412423
state_type = (prev_state or new_state).type
413424

414-
send_mail(request, recipients, settings.DEFAULT_FROM_EMAIL,
425+
send_mail(request, to, settings.DEFAULT_FROM_EMAIL,
415426
u"%s changed for %s" % (state_type.label, doc.name),
416427
'doc/mail/stream_state_changed_email.txt',
417428
dict(doc=doc,
@@ -420,46 +431,39 @@ def email_stream_state_changed(request, doc, prev_state, new_state, by, comment=
420431
prev_state=prev_state,
421432
new_state=new_state,
422433
by=by,
423-
comment=comment))
434+
comment=comment),
435+
cc=cc)
424436

425437
def email_stream_tags_changed(request, doc, added_tags, removed_tags, by, comment=""):
426438

427-
recipients = gather_address_list('doc_stream_state_edited',doc=doc)
439+
(to, cc) = gather_address_lists('doc_stream_state_edited',doc=doc)
428440

429-
send_mail(request, recipients, settings.DEFAULT_FROM_EMAIL,
441+
send_mail(request, to, settings.DEFAULT_FROM_EMAIL,
430442
u"Tags changed for %s" % doc.name,
431443
'doc/mail/stream_tags_changed_email.txt',
432444
dict(doc=doc,
433445
url=settings.IDTRACKER_BASE_URL + doc.get_absolute_url(),
434446
added=added_tags,
435447
removed=removed_tags,
436448
by=by,
437-
comment=comment))
449+
comment=comment),
450+
cc=cc)
438451

439452
def send_review_possibly_replaces_request(request, doc):
440-
to_email = []
441-
442-
if doc.stream_id == "ietf":
443-
to_email.extend(r.formatted_email() for r in Role.objects.filter(group=doc.group, name="chair").select_related("email", "person"))
444-
elif doc.stream_id == "iab":
445-
to_email.append("IAB Stream <iab-stream@iab.org>")
446-
elif doc.stream_id == "ise":
447-
to_email.append("Independent Submission Editor <rfc-ise@rfc-editor.org>")
448-
elif doc.stream_id == "irtf":
449-
to_email.append("IRSG <irsg@irtf.org>")
453+
addrs = gather_address_lists('doc_replacement_suggested',doc=doc)
454+
to = set(addrs.to)
455+
cc = set(addrs.cc)
450456

451457
possibly_replaces = Document.objects.filter(name__in=[alias.name for alias in doc.related_that_doc("possibly-replaces")])
452-
other_chairs = Role.objects.filter(group__in=[other.group for other in possibly_replaces], name="chair").select_related("email", "person")
453-
to_email.extend(r.formatted_email() for r in other_chairs)
454-
455-
if not to_email:
456-
to_email.append("internet-drafts@ietf.org")
457-
458-
if to_email:
459-
send_mail(request, list(set(to_email)), settings.DEFAULT_FROM_EMAIL,
460-
'Review of suggested possible replacements for %s-%s needed' % (doc.name, doc.rev),
461-
'doc/mail/review_possibly_replaces_request.txt', {
462-
'doc': doc,
463-
'possibly_replaces': doc.related_that_doc("possibly-replaces"),
464-
'review_url': settings.IDTRACKER_BASE_URL + urlreverse("doc_review_possibly_replaces", kwargs={ "name": doc.name }),
465-
})
458+
for other_doc in possibly_replaces:
459+
(other_to, other_cc) = gather_address_lists('doc_replacement_suggested',doc=other_doc)
460+
to.update(other_to)
461+
cc.update(other_cc)
462+
463+
send_mail(request, list(to), settings.DEFAULT_FROM_EMAIL,
464+
'Review of suggested possible replacements for %s-%s needed' % (doc.name, doc.rev),
465+
'doc/mail/review_possibly_replaces_request.txt',
466+
dict(doc= doc,
467+
possibly_replaces=doc.related_that_doc("possibly-replaces"),
468+
review_url=settings.IDTRACKER_BASE_URL + urlreverse("doc_review_possibly_replaces", kwargs={ "name": doc.name })),
469+
cc=list(cc),)

ietf/doc/tests_ballot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def test_send_ballot_comment(self):
173173
self.assertEqual(len(outbox), mailbox_before + 2)
174174
m = outbox[-1]
175175
self.assertTrue("iesg@" in m['To'])
176-
self.assertFalse(draft.group.list_email in m['Cc'])
176+
self.assertFalse(m['Cc'] and draft.group.list_email in m['Cc'])
177177

178178

179179
class BallotWriteupsTests(TestCase):

0 commit comments

Comments
 (0)