|
3 | 3 |
|
4 | 4 | import datetime |
5 | 5 | import email.utils |
6 | | -import json |
7 | 6 | import jsonfield |
8 | 7 | import os |
9 | 8 | import re |
10 | | -import requests |
11 | 9 |
|
12 | | -from jwcrypto import jwk, jws |
13 | | -from jwcrypto.common import json_encode |
14 | 10 | from urlparse import urljoin |
15 | 11 |
|
16 | 12 | from django.conf import settings |
|
26 | 22 | from ietf.group.colors import fg_group_colors, bg_group_colors |
27 | 23 | from ietf.name.models import GroupStateName, GroupTypeName, DocTagName, GroupMilestoneStateName, RoleName, AgendaTypeName |
28 | 24 | from ietf.person.models import Email, Person |
29 | | -from ietf.utils.mail import formataddr |
| 25 | +from ietf.utils.mail import formataddr, send_mail_text |
30 | 26 | from ietf.utils import log |
31 | 27 | from ietf.utils.models import ForeignKey, OneToOneField |
32 | 28 |
|
@@ -367,31 +363,50 @@ def notify_rfceditor_of_group_name_change(sender, instance=None, **kwargs): |
367 | 363 | current = Group.objects.get(pk=instance.pk) |
368 | 364 | except Group.DoesNotExist: |
369 | 365 | return |
370 | | - url = settings.RFC_EDITOR_GROUP_NOTIFICATION_URL |
371 | | - if url and instance.name != current.name: |
372 | | - data = { |
373 | | - 'acronym': current.acronym, |
374 | | - 'old_name': current.name, |
375 | | - 'name': instance.name, |
376 | | - } |
377 | | - # Build signed data |
378 | | - key = jwk.JWK() |
379 | | - key.import_from_pem(settings.API_PRIVATE_KEY_PEM) |
380 | | - payload = json.dumps(data) |
381 | | - jwstoken = jws.JWS(payload.encode('utf-8')) |
382 | | - jwstoken.add_signature(key, None, |
383 | | - json_encode({"alg": settings.API_KEY_TYPE}), |
384 | | - json_encode({"kid": key.thumbprint()})) |
385 | | - sig = jwstoken.serialize() |
386 | | - # Send signed data |
387 | | - response = requests.post(url, data = { 'jws': sig, }) |
388 | | - log.log("Sent notify: %s: '%s' --> '%s' to %s, result code %s" % |
389 | | - (current.acronym, current.name, instance.name, url, response.status_code)) |
390 | | - # Verify locally, to make sure we've got things right |
391 | | - key = jwk.JWK() |
392 | | - key.import_from_pem(settings.API_PUBLIC_KEY_PEM) |
393 | | - jwstoken = jws.JWS() |
394 | | - jwstoken.deserialize(sig) |
395 | | - jwstoken.verify(key) |
396 | | - log.assertion('payload == jwstoken.payload') |
| 366 | + addr = settings.RFC_EDITOR_GROUP_NOTIFICATION_EMAIL |
| 367 | + if addr and instance.name != current.name: |
| 368 | + msg = """ |
| 369 | +This is an automated notification of a group name change: |
| 370 | +
|
| 371 | + acronym: %s |
| 372 | + old name: %s |
| 373 | + new name: %s |
| 374 | +
|
| 375 | + Regards, |
| 376 | +
|
| 377 | + The datatracker |
| 378 | +""" % (current.acronym, current.name, instance.name, ) |
| 379 | + send_mail_text(None, to=addr, frm=None, subject="Group '%s' name change"%instance.acronym, txt=msg) |
| 380 | + log.log("Sent notification email: %s: '%s' --> '%s' to %s" % (current.acronym, current.name, instance.name, addr)) |
| 381 | + |
| 382 | + |
| 383 | +## Keep this code as a worked and tested example of sending signed notifies |
| 384 | +## by HTTP POST. (superseded for this use case by email notification) |
| 385 | +# url = settings.RFC_EDITOR_GROUP_NOTIFICATION_URL |
| 386 | +# if url and instance.name != current.name: |
| 387 | +# data = { |
| 388 | +# 'acronym': current.acronym, |
| 389 | +# 'old_name': current.name, |
| 390 | +# 'name': instance.name, |
| 391 | +# } |
| 392 | +# # Build signed data |
| 393 | +# key = jwk.JWK() |
| 394 | +# key.import_from_pem(settings.API_PRIVATE_KEY_PEM) |
| 395 | +# payload = json.dumps(data) |
| 396 | +# jwstoken = jws.JWS(payload.encode('utf-8')) |
| 397 | +# jwstoken.add_signature(key, None, |
| 398 | +# json_encode({"alg": settings.API_KEY_TYPE}), |
| 399 | +# json_encode({"kid": key.thumbprint()})) |
| 400 | +# sig = jwstoken.serialize() |
| 401 | +# # Send signed data |
| 402 | +# response = requests.post(url, data = { 'jws': sig, }) |
| 403 | +# log.log("Sent notify: %s: '%s' --> '%s' to %s, result code %s" % |
| 404 | +# (current.acronym, current.name, instance.name, url, response.status_code)) |
| 405 | +# # Verify locally, to make sure we've got things right |
| 406 | +# key = jwk.JWK() |
| 407 | +# key.import_from_pem(settings.API_PUBLIC_KEY_PEM) |
| 408 | +# jwstoken = jws.JWS() |
| 409 | +# jwstoken.deserialize(sig) |
| 410 | +# jwstoken.verify(key) |
| 411 | +# log.assertion('payload == jwstoken.payload') |
397 | 412 |
|
0 commit comments