After feedback from the RFC-Editor staff, changed the URL POST notification of Group name changes to an Email notification.
- Legacy-Id: 16210
This commit is contained in:
parent
b34b51cab9
commit
a62e029932
|
@ -3,14 +3,10 @@
|
|||
|
||||
import datetime
|
||||
import email.utils
|
||||
import json
|
||||
import jsonfield
|
||||
import os
|
||||
import re
|
||||
import requests
|
||||
|
||||
from jwcrypto import jwk, jws
|
||||
from jwcrypto.common import json_encode
|
||||
from urlparse import urljoin
|
||||
|
||||
from django.conf import settings
|
||||
|
@ -26,7 +22,7 @@ import debug # pyflakes:ignore
|
|||
from ietf.group.colors import fg_group_colors, bg_group_colors
|
||||
from ietf.name.models import GroupStateName, GroupTypeName, DocTagName, GroupMilestoneStateName, RoleName, AgendaTypeName
|
||||
from ietf.person.models import Email, Person
|
||||
from ietf.utils.mail import formataddr
|
||||
from ietf.utils.mail import formataddr, send_mail_text
|
||||
from ietf.utils import log
|
||||
from ietf.utils.models import ForeignKey, OneToOneField
|
||||
|
||||
|
@ -367,31 +363,50 @@ def notify_rfceditor_of_group_name_change(sender, instance=None, **kwargs):
|
|||
current = Group.objects.get(pk=instance.pk)
|
||||
except Group.DoesNotExist:
|
||||
return
|
||||
url = settings.RFC_EDITOR_GROUP_NOTIFICATION_URL
|
||||
if url and instance.name != current.name:
|
||||
data = {
|
||||
'acronym': current.acronym,
|
||||
'old_name': current.name,
|
||||
'name': instance.name,
|
||||
}
|
||||
# Build signed data
|
||||
key = jwk.JWK()
|
||||
key.import_from_pem(settings.API_PRIVATE_KEY_PEM)
|
||||
payload = json.dumps(data)
|
||||
jwstoken = jws.JWS(payload.encode('utf-8'))
|
||||
jwstoken.add_signature(key, None,
|
||||
json_encode({"alg": settings.API_KEY_TYPE}),
|
||||
json_encode({"kid": key.thumbprint()}))
|
||||
sig = jwstoken.serialize()
|
||||
# Send signed data
|
||||
response = requests.post(url, data = { 'jws': sig, })
|
||||
log.log("Sent notify: %s: '%s' --> '%s' to %s, result code %s" %
|
||||
(current.acronym, current.name, instance.name, url, response.status_code))
|
||||
# Verify locally, to make sure we've got things right
|
||||
key = jwk.JWK()
|
||||
key.import_from_pem(settings.API_PUBLIC_KEY_PEM)
|
||||
jwstoken = jws.JWS()
|
||||
jwstoken.deserialize(sig)
|
||||
jwstoken.verify(key)
|
||||
log.assertion('payload == jwstoken.payload')
|
||||
addr = settings.RFC_EDITOR_GROUP_NOTIFICATION_EMAIL
|
||||
if addr and instance.name != current.name:
|
||||
msg = """
|
||||
This is an automated notification of a group name change:
|
||||
|
||||
acronym: %s
|
||||
old name: %s
|
||||
new name: %s
|
||||
|
||||
Regards,
|
||||
|
||||
The datatracker
|
||||
""" % (current.acronym, current.name, instance.name, )
|
||||
send_mail_text(None, to=addr, frm=None, subject="Group '%s' name change"%instance.acronym, txt=msg)
|
||||
log.log("Sent notification email: %s: '%s' --> '%s' to %s" % (current.acronym, current.name, instance.name, addr))
|
||||
|
||||
|
||||
## Keep this code as a worked and tested example of sending signed notifies
|
||||
## by HTTP POST. (superseded for this use case by email notification)
|
||||
# url = settings.RFC_EDITOR_GROUP_NOTIFICATION_URL
|
||||
# if url and instance.name != current.name:
|
||||
# data = {
|
||||
# 'acronym': current.acronym,
|
||||
# 'old_name': current.name,
|
||||
# 'name': instance.name,
|
||||
# }
|
||||
# # Build signed data
|
||||
# key = jwk.JWK()
|
||||
# key.import_from_pem(settings.API_PRIVATE_KEY_PEM)
|
||||
# payload = json.dumps(data)
|
||||
# jwstoken = jws.JWS(payload.encode('utf-8'))
|
||||
# jwstoken.add_signature(key, None,
|
||||
# json_encode({"alg": settings.API_KEY_TYPE}),
|
||||
# json_encode({"kid": key.thumbprint()}))
|
||||
# sig = jwstoken.serialize()
|
||||
# # Send signed data
|
||||
# response = requests.post(url, data = { 'jws': sig, })
|
||||
# log.log("Sent notify: %s: '%s' --> '%s' to %s, result code %s" %
|
||||
# (current.acronym, current.name, instance.name, url, response.status_code))
|
||||
# # Verify locally, to make sure we've got things right
|
||||
# key = jwk.JWK()
|
||||
# key.import_from_pem(settings.API_PUBLIC_KEY_PEM)
|
||||
# jwstoken = jws.JWS()
|
||||
# jwstoken.deserialize(sig)
|
||||
# jwstoken.verify(key)
|
||||
# log.assertion('payload == jwstoken.payload')
|
||||
|
||||
|
|
|
@ -618,7 +618,7 @@ class GroupEditTests(TestCase):
|
|||
self.assertEqual(group.groupurl_set.all()[0].url, "http://mars.mars")
|
||||
self.assertEqual(group.groupurl_set.all()[0].name, "MARS site")
|
||||
self.assertTrue(os.path.exists(os.path.join(self.charter_dir, "%s-%s.txt" % (group.charter.canonical_name(), group.charter.rev))))
|
||||
self.assertEqual(len(outbox), 1)
|
||||
self.assertEqual(len(outbox), 2)
|
||||
self.assertTrue('Personnel change' in outbox[0]['Subject'])
|
||||
for prefix in ['ad1','ad2','aread','marschairman','marsdelegate']:
|
||||
self.assertTrue(prefix+'@' in outbox[0]['To'])
|
||||
|
|
|
@ -704,7 +704,8 @@ RFC_TEXT_RSYNC_SOURCE="ftp.rfc-editor.org::rfcs-text-only"
|
|||
|
||||
RFC_EDITOR_SYNC_PASSWORD="secret"
|
||||
RFC_EDITOR_SYNC_NOTIFICATION_URL = "https://www.rfc-editor.org/parser/parser.php"
|
||||
RFC_EDITOR_GROUP_NOTIFICATION_URL = "https://www.rfc-editor.org/notification/group.php"
|
||||
RFC_EDITOR_GROUP_NOTIFICATION_EMAIL = "webmaster@rfc-editor.org"
|
||||
#RFC_EDITOR_GROUP_NOTIFICATION_URL = "https://www.rfc-editor.org/notification/group.php"
|
||||
RFC_EDITOR_QUEUE_URL = "https://www.rfc-editor.org/queue2.xml"
|
||||
RFC_EDITOR_INDEX_URL = "https://www.rfc-editor.org/rfc/rfc-index.xml"
|
||||
RFC_EDITOR_ERRATA_URL = "https://www.rfc-editor.org/errata_search.php?rfc={rfc_number}&rec_status=0"
|
||||
|
|
Loading…
Reference in a new issue