Skip to contentSkip to conversation

Send email notification on publication

PATCH In review Amanda Brindle 2 participants 4 messages Oct 24, 2017 – Oct 30, 2017

lore
Share & tools
lore
#0 lore raw

v3 cover Send email notification on publication

Changed the publishemail template to use django conditional statements in creating the list of maintainer names, as well as checking whether there is more than one maintainer.

The following changes since commit ad1aac4ea5d4f2b327f7bd9611aed13f7c31ff7e:

Show note if layer branch hasn't been indexed (2017-10-04 13:49:00 +1300)

are available in the git repository at:

git://git.yoctoproject.org/layerindex-web abrindle/email_notification_publication
http://git.yoctoproject.org/cgit.cgi/layerindex-web/log/?h=abrindle/email_notification_publication

Amanda Brindle (1):
Send email notification on publication

 layerindex/views.py                          | 34 +++++++++++++++++++++++++++-
 templates/layerindex/publishemail.txt        |  9 ++++++++
 templates/layerindex/publishemailsubject.txt |  1 +
 3 files changed, 43 insertions(+), 1 deletion(-)
 create mode 100644 templates/layerindex/publishemail.txt
 create mode 100644 templates/layerindex/publishemailsubject.txt
Signature · 1 line
2.7.4
#1 lore raw

PATCH v3 1/1 Send email notification on publication

When publishing a layer, send an email notification to all of that layer's maintainers.

Fixes [YOCTO #11208]

---
 layerindex/views.py                          | 34 +++++++++++++++++++++++++++-
 templates/layerindex/publishemail.txt        |  9 ++++++++
 templates/layerindex/publishemailsubject.txt |  1 +
 3 files changed, 43 insertions(+), 1 deletion(-)
 create mode 100644 templates/layerindex/publishemail.txt
 create mode 100644 templates/layerindex/publishemailsubject.txt
layerindex/views.py +33 -1
index bcf6671..095f428 100644
@@ -5,7 +5,7 @@
 # Licensed under the MIT license, see COPYING.MIT for details
 
 import sys
-from django.shortcuts import get_object_or_404, render
+from django.shortcuts import get_object_or_404, get_list_or_404, render
 from django.http import HttpResponse, HttpResponseRedirect, HttpResponseForbidden, Http404
 from django.core.urlresolvers import reverse, reverse_lazy, resolve
 from django.core.exceptions import PermissionDenied
@@ -261,6 +261,38 @@ def _check_url_branch(kwargs):
 def publish(request, name):
     if not (request.user.is_authenticated() and request.user.has_perm('layerindex.publish_layer')):
         raise PermissionDenied
+    layeritem = get_object_or_404(LayerItem, name=name)
+    layerbranch = get_object_or_404(LayerBranch, layer=layeritem)
+    layer_url = request.build_absolute_uri(reverse('layer_item', args=(layerbranch.branch, layeritem.name)))
+    maintainers = get_list_or_404(LayerMaintainer, layerbranch=layerbranch)
+    from_email = settings.SUBMIT_EMAIL_FROM
+    subjecttext = get_template('layerindex/publishemailsubject.txt')
+    bodytext = get_template('layerindex/publishemail.txt')
+    maintainer_names = [m.name for m in maintainers]
+    # find appropriate help contact
+    for user in User.objects.all():
+        if user.username != 'root' and user.is_active:
+            help_contact = user
+            break
+
+    # create subject from subject template
+    d = Context({
+        'layer_name': layeritem.name,
+        'site_name': request.META['HTTP_HOST'],
+    })
+    subject = subjecttext.render(d).rstrip()
+
+    #create body from body template
+    d = Context({
+        'maintainers': maintainer_names,
+        'layer_name': layeritem.name,
+        'layer_url': layer_url,
+        'help_contact': help_contact,
+    })
+    body = bodytext.render(d)
+
+    tasks.send_email.apply_async((subject, body, from_email, [m.email for m in maintainers]))
+
     return _statuschange(request, name, 'P')
 
 def _statuschange(request, name, newstatus):
templates/layerindex/publishemail.txt new file +9 -0
new file mode 100644
index 0000000..5d703d8
@@ -0,0 +1,9 @@
+Hi {{ maintainers|slice:":-1"|join:", "}}{% if maintainers|length > 2 %},{% endif %}{% if maintainers|length > 1 %} and {% endif %}{{ maintainers|last }},
+
+You are listed as the {% if maintainers|length > 1 %}maintainers{% else %}maintainer{% endif %} for the new layer, {{ layer_name }}. This layer has now been published. You can view it at the following URL:
+
+ {{ layer_url }}
+
+If you need to make changes to this layer's entry in the index in the future, create an account (using this email address) if you haven't already, and you should then be able to click on "Edit layer" on the layer's detail page and make the desired changes. If you need any assistance please contact {% if help_contact.first_name and help_contact.last_name %}{{ help_contact.first_name }} {{ help_contact.last_name}}{% else %}{{ help_contact.username }}{% endif %} <{{ help_contact.email }}>.
+
+Thanks!
templates/layerindex/publishemailsubject.txt new file +1 -0
new file mode 100644
index 0000000..1d49ea7
@@ -0,0 +1 @@
+{{site_name}}: {{layer_name }} published
Signature · 1 line
2.7.4
#2 lore raw

Hi Amanda,

Quoted 4 lines · NZDT Amanda Brindle

When publishing a layer, send an email notification to all of that layer's maintainers.

Fixes [YOCTO #11208]

This change looks good to me - I'll wait a day or so for other reviews and merge after that.

Thanks,
Paul

Signature · 2 lines
Paul Eggleton
Intel Open Source Technology Centre
#3 lore raw
In reply to Amanda Brindle
Quoted 8 lines · NZDT Amanda Brindle

When publishing a layer, send an email notification to all of that layer's maintainers.

Fixes [YOCTO #11208]

---
 layerindex/views.py                          | 34 +++++++++++++++++++++++++

++-

Quoted 11 lines
 templates/layerindex/publishemail.txt        |  9 ++++++++
 templates/layerindex/publishemailsubject.txt |  1 +
 3 files changed, 43 insertions(+), 1 deletion(-)
 create mode 100644 templates/layerindex/publishemail.txt
 create mode 100644 templates/layerindex/publishemailsubject.txt
layerindex/views.py +0 -0
index bcf6671..095f428 100644

layerindex/views.py line 9

Quoted 6 lines
layerindex/views.py +1 -1
@@ -5,7 +5,7 @@
 # Licensed under the MIT license, see COPYING.MIT for details
 
 import sys
-from django.shortcuts import get_object_or_404, render
+from django.shortcuts import get_object_or_404, get_list_or_404, render
 from django.http import HttpResponse, HttpResponseRedirect, 

HttpResponseForbidden, Http404

layerindex/views.py def _check_url_branch(kwargs): · line 262

Quoted 5 lines
layerindex/views.py +0 -0
 from django.core.urlresolvers import reverse, reverse_lazy, resolve
 from django.core.exceptions import PermissionDenied
@@ -261,6 +261,38 @@ def _check_url_branch(kwargs):
 def publish(request, name):
     if not (request.user.is_authenticated() and 

request.user.has_perm('layerindex.publish_layer')):

layerindex/views.py def _check_url_branch(kwargs):

Quoted 4 lines
layerindex/views.py +3 -0
         raise PermissionDenied
+    layeritem = get_object_or_404(LayerItem, name=name)
+    layerbranch = get_object_or_404(LayerBranch, layer=layeritem)
+    layer_url = request.build_absolute_uri(reverse('layer_item', 

args=(layerbranch.branch, layeritem.name)))

layerindex/views.py def _check_url_branch(kwargs): · line 276

Quoted 10 lines
layerindex/views.py +10 -0
+    maintainers = get_list_or_404(LayerMaintainer, layerbranch=layerbranch)
+    from_email = settings.SUBMIT_EMAIL_FROM
+    subjecttext = get_template('layerindex/publishemailsubject.txt')
+    bodytext = get_template('layerindex/publishemail.txt')
+    maintainer_names = [m.name for m in maintainers]
+    # find appropriate help contact
+    for user in User.objects.all():
+        if user.username != 'root' and user.is_active:
+            help_contact = user
+            break

Just to follow up here, I've merged this with a change to the above lines to only include staff/superusers.

Cheers,
Paul

Signature · 2 lines
Paul Eggleton
Intel Open Source Technology Centre