Skip to content

Commit 3594f08

Browse files
committed
Switch liaison over to using the IETF SMTP handling instead of
built-in Django, fix a couple of bugs, make pending liaison emails use the normal liaison email template too instead of duplicating the content - Legacy-Id: 3352
1 parent 2bbe307 commit 3594f08

6 files changed

Lines changed: 62 additions & 69 deletions

File tree

ietf/liaisons/mails.py

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
from django.template.loader import render_to_string
33
from django.core.urlresolvers import reverse as urlreverse
44

5-
from ietf.liaisons.mail import IETFEmailMessage
5+
from ietf.utils.mail import send_mail_text
66

7-
def send_liaison_by_email(liaison, fake=False):
8-
if not liaison.is_pending(): # this conditional should definitely be at the caller, not here
9-
return notify_pending_by_email(liaison, fake)
7+
def send_liaison_by_email(request, liaison, fake=False):
8+
if liaison.is_pending(): # this conditional should definitely be at the caller, not here
9+
return notify_pending_by_email(request, liaison, fake)
1010

1111
subject = u'New Liaison Statement, "%s"' % (liaison.title)
1212
from_email = settings.LIAISON_UNIVERSAL_FROM
@@ -17,23 +17,26 @@ def send_liaison_by_email(liaison, fake=False):
1717
if liaison.response_contact:
1818
cc += liaison.response_contact.split(',')
1919
bcc = ['statements@ietf.org']
20-
body = render_to_string('liaisons/liaison_mail.txt',
21-
{'liaison': liaison,
22-
'url': settings.IDTRACKER_BASE_URL + urlreverse("liaison_detail", kwargs=dict(object_id=liaison.pk))
23-
})
24-
mail = IETFEmailMessage(subject=subject,
20+
body = render_to_string('liaisons/liaison_mail.txt', dict(
21+
liaison=liaison,
22+
url=settings.IDTRACKER_BASE_URL + urlreverse("liaison_detail", kwargs=dict(object_id=liaison.pk)),
23+
referenced_url=settings.IDTRACKER_BASE_URL + urlreverse("liaison_detail", kwargs=dict(object_id=liaison.related_to.pk)) if liaison.related_to else None,
24+
))
25+
if fake:
26+
# rather than this fake stuff, it's probably better to start a
27+
# debug SMTP server as explained in the Django docs
28+
from ietf.liaisons.mail import IETFEmailMessage
29+
mail = IETFEmailMessage(subject=subject,
2530
to=to_email,
2631
from_email=from_email,
2732
cc = cc,
2833
bcc = bcc,
2934
body = body)
30-
# rather than this fake stuff, it's probably better to start a
31-
# debug SMTP server as explained in the Django docs
32-
if not fake:
33-
mail.send()
34-
return mail
35+
return mail
3536

36-
def notify_pending_by_email(liaison, fake):
37+
send_mail_text(request, to_email, from_email, subject, body, cc=", ".join(cc), bcc=", ".join(bcc))
38+
39+
def notify_pending_by_email(request, liaison, fake):
3740
from ietf.liaisons.utils import IETFHM
3841

3942
from_entity = IETFHM.get_entity_by_key(liaison.from_raw_code)
@@ -44,16 +47,16 @@ def notify_pending_by_email(liaison, fake):
4447
to_email.append('%s <%s>' % person.email())
4548
subject = u'New Liaison Statement, "%s" needs your approval' % (liaison.title)
4649
from_email = settings.LIAISON_UNIVERSAL_FROM
47-
body = render_to_string('liaisons/pending_liaison_mail.txt',
48-
{'liaison': liaison,
49-
'url': settings.IDTRACKER_BASE_URL + urlreverse("liaison_detail", kwargs=dict(object_id=liaison.pk)),
50-
'approve_url': settings.IDTRACKER_BASE_URL + urlreverse("liaison_approval_detail", kwargs=dict(object_id=liaison.pk))
51-
})
52-
mail = IETFEmailMessage(subject=subject,
53-
to=to_email,
54-
from_email=from_email,
55-
body = body)
56-
if not fake:
57-
mail.send()
58-
return mail
50+
body = render_to_string('liaisons/pending_liaison_mail.txt', dict(
51+
liaison=liaison,
52+
url=settings.IDTRACKER_BASE_URL + urlreverse("liaison_approval_detail", kwargs=dict(object_id=liaison.pk)),
53+
referenced_url=settings.IDTRACKER_BASE_URL + urlreverse("liaison_detail", kwargs=dict(object_id=liaison.related_to.pk)) if liaison.related_to else None,
54+
))
55+
if fake:
56+
mail = IETFEmailMessage(subject=subject,
57+
to=to_email,
58+
from_email=from_email,
59+
body = body)
60+
return mail
61+
send_mail_text(request, to_email, from_email, subject, body)
5962

ietf/liaisons/models.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,11 @@ def notify_pending_by_email(self, fake):
142142
to_email.append('%s <%s>' % person.email())
143143
subject = 'New Liaison Statement, "%s" needs your approval' % (self.title)
144144
from_email = settings.LIAISON_UNIVERSAL_FROM
145-
body = render_to_string('liaisons/pending_liaison_mail.txt',
146-
{'liaison': self,
147-
'url': settings.IDTRACKER_BASE_URL + urlreverse("liaison_detail", kwargs=dict(object_id=liaison.pk))
148-
})
145+
body = render_to_string('liaisons/pending_liaison_mail.txt', {
146+
'liaison': self,
147+
'url': settings.IDTRACKER_BASE_URL + urlreverse("liaison_approval_detail", kwargs=dict(object_id=self.pk)),
148+
'referenced_url': settings.IDTRACKER_BASE_URL + urlreverse("liaison_detail", kwargs=dict(object_id=self.related_to.pk)) if self.related_to else None,
149+
})
149150
mail = IETFEmailMessage(subject=subject,
150151
to=to_email,
151152
from_email=from_email,
@@ -166,11 +167,11 @@ def send_by_email(self, fake=False):
166167
if self.response_contact:
167168
cc += self.response_contact.split(',')
168169
bcc = ['statements@ietf.org']
169-
body = render_to_string('liaisons/liaison_mail.txt',
170-
{'liaison': self,
171-
'url': settings.IDTRACKER_BASE_URL + urlreverse("liaison_detail", kwargs=dict(object_id=liaison.pk)),
172-
'approve_url': settings.IDTRACKER_BASE_URL + urlreverse("liaison_approval_detail", kwargs=dict(object_id=liaison.pk))
173-
})
170+
body = render_to_string('liaisons/liaison_mail.txt', {
171+
'liaison': self,
172+
'url': settings.IDTRACKER_BASE_URL + urlreverse("liaison_detail", kwargs=dict(object_id=self.pk)),
173+
'referenced_url': settings.IDTRACKER_BASE_URL + urlreverse("liaison_detail", kwargs=dict(object_id=self.related_to.pk)) if self.related_to else None,
174+
})
174175
mail = IETFEmailMessage(subject=subject,
175176
to=to_email,
176177
from_email=from_email,

ietf/liaisons/proxy.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ class Meta:
145145
def send_by_email(self, fake=False):
146146
# grab this from module instead of stuffing in on the model
147147
from ietf.liaisons.mails import send_liaison_by_email
148-
return send_liaison_by_email(self, fake)
148+
# we don't have a request so just pass None for the time being
149+
return send_liaison_by_email(None, self, fake)
149150

150151
def is_pending(self):
151152
return not self.approved

ietf/liaisons/tests.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,8 @@ def test_approval(self):
138138

139139
liaison = LiaisonStatement.objects.get(id=liaison.id)
140140
self.assertTrue(liaison.approved)
141-
from django.core import mail
142-
self.assertEqual(len(mail.outbox), 1)
143-
self.assertTrue("Liaison Statement" in mail.outbox[-1].subject)
144-
#self.assertEquals(len(mail_outbox), mailbox_before + 1)
145-
#self.assertTrue("Liaison Statement" in mail_outbox[-1]["Subject"])
141+
self.assertEquals(len(mail_outbox), mailbox_before + 1)
142+
self.assertTrue("Liaison Statement" in mail_outbox[-1]["Subject"])
146143

147144
def test_edit_liaison(self):
148145
make_test_data()
@@ -217,6 +214,7 @@ def test_add_incoming_liaison(self):
217214
self.assertEquals(len(q('form textarea[name=body]')), 1)
218215

219216
# add new
217+
mailbox_before = len(mail_outbox)
220218
test_file = StringIO("hello world")
221219
test_file.name = "unnamed"
222220
from_group = Group.objects.filter(type="sdo")[0]
@@ -240,6 +238,7 @@ def test_add_incoming_liaison(self):
240238
body="body",
241239
attach_file_1=test_file,
242240
attach_title_1="attachment",
241+
send="1",
243242
))
244243
self.assertEquals(r.status_code, 302)
245244

@@ -267,6 +266,9 @@ def test_add_incoming_liaison(self):
267266

268267
test_file.seek(0)
269268
self.assertEquals(written_content, test_file.read())
269+
270+
self.assertEquals(len(mail_outbox), mailbox_before + 1)
271+
self.assertTrue("Liaison Statement" in mail_outbox[-1]["Subject"])
270272

271273
def test_add_outgoing_liaison(self):
272274
make_test_data()
@@ -282,6 +284,7 @@ def test_add_outgoing_liaison(self):
282284
self.assertEquals(len(q('form textarea[name=body]')), 1)
283285

284286
# add new
287+
mailbox_before = len(mail_outbox)
285288
test_file = StringIO("hello world")
286289
test_file.name = "unnamed"
287290
from_group = Group.objects.get(acronym="mars")
@@ -308,6 +311,7 @@ def test_add_outgoing_liaison(self):
308311
body="body",
309312
attach_file_1=test_file,
310313
attach_title_1="attachment",
314+
send="1",
311315
))
312316
self.assertEquals(r.status_code, 302)
313317

@@ -337,6 +341,9 @@ def test_add_outgoing_liaison(self):
337341
test_file.seek(0)
338342
self.assertEquals(written_content, test_file.read())
339343

344+
self.assertEquals(len(mail_outbox), mailbox_before + 1)
345+
self.assertTrue("Liaison Statement" in mail_outbox[-1]["Subject"])
346+
340347
# try adding statement to non-predefined organization
341348
r = self.client.post(url,
342349
dict(from_field="%s_%s" % (from_group.type_id, from_group.pk),
@@ -362,7 +369,6 @@ def test_add_outgoing_liaison(self):
362369
self.assertEquals(l.to_group, None)
363370
self.assertEquals(l.to_name, "Mars Institute")
364371

365-
366372
if not settings.USE_DB_REDESIGN_PROXY_CLASSES:
367373
# the above tests only work with the new schema
368374
del LiaisonManagementTestCase
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% autoescape off %}Title: {{ liaison.title }}
1+
{% load ietf_filters %}{% autoescape off %}Title: {{ liaison.title|clean_whitespace }}
22
Submission Date: {{ liaison.submitted_date }}
33
URL of the IETF Web page: {{ url }}
44
{% if liaison.deadline_date %}Please reply by {{ liaison.deadline_date }}{% endif %}
@@ -8,12 +8,12 @@ Cc: {{ liaison.cc1 }}
88
Reponse Contact: {{ liaison.response_contact }}
99
Technical Contact: {{ liaison.technical_contact }}
1010
Purpose: {% if liaison.purpose_text %}{{ liaison.purpose_text }}{% else %}{{ liaison.purpose }}{% endif %}
11-
{% if liaison.related_to %}Referenced liaison: {% if liaison.related_to.title %}{{ liaison.related_to.title }}{% else %}Liaison #{{ liaison.related_to.pk }}{% endif %} ({% url liaison_detail object_id=liaison.related_to.pk %}){% endif %}
11+
{% if liaison.related_to %}Referenced liaison: {% if liaison.related_to.title %}{{ liaison.related_to.title }}{% else %}Liaison #{{ liaison.related_to.pk }}{% endif %} ({{ referenced_url }}){% endif %}
1212
Body: {{ liaison.body }}
1313
Attachments:
1414
{% for file in liaison.uploads_set.all %}
15-
{{ file.file_title }} https://datatracker.ietf.org/documents/LIAISON/{{ file.filename }}
15+
{{ file.file_title }}
16+
https://datatracker.ietf.org/documents/LIAISON/{{ file.filename }}
1617
{% empty %}
1718
No document has been attached
18-
{% endfor %}
19-
{% endautoescape %}
19+
{% endfor %}{% endautoescape %}
Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,5 @@
11
The following liaison statement will remain pending (and not public available) in the system until you approve it:
2-
{% load ietf_filters %}{% autoescape off %}
3-
Title: {{ liaison.title|clean_whitespace }}
4-
Submission Date: {{ liaison.submitted_date }}
5-
URL of the IETF Web page: {{ url }}
6-
{% if liaison.deadline_date %}Please reply by {{ liaison.deadline_date }}{% endif %}
7-
From: {{ liaison.from_body }} ({{ liaison.person }} <{{ liaison.replyto|default:liaison.from_email }}>)
8-
To: {{ liaison.to_body }} ({{ liaison.to_poc }})
9-
Cc: {{ liaison.cc1 }}
10-
Reponse Contact: {{ liaison.response_contact }}
11-
Technical Contact: {{ liaison.technical_contact }}
12-
Purpose: {% if liaison.purpose_text %}{{ liaison.purpose_text }}{% else %}{{ liaison.purpose }}{% endif %}
13-
{% if liaison.related_to %}Referenced liaison: {% if liaison.related_to.title %}{{ liaison.related_to.title }}{% else %}Liaison #{{ liaison.related_to.pk }}{% endif %} ({% url liaison_detail object_id=liaison.related_to.pk %}){% endif %}
14-
Body: {{ liaison.body }}
15-
Attachments:
16-
{% for file in liaison.uploads_set.all %}
17-
{{ file.file_title }} https://datatracker.ietf.org/documents/LIAISON/{{ file.filename }}
18-
{% empty %}
19-
No document has been attached
20-
{% endfor %}
21-
{% endautoescape %}
222

23-
Please visit {{ approve_url }} in order to approve the liaison statement.
3+
{% include "liaisons/liaison_mail.txt" %}
4+
5+
Please visit {{ url }} in order to approve the liaison statement.

0 commit comments

Comments
 (0)