Re: [layerindex-web][patch v3 1/1] Send email notification on publication


Paul Eggleton
 

On Wednesday, 25 October 2017 10:49:42 AM NZDT Amanda Brindle wrote:
When publishing a layer, send an email notification to all of that
layer's maintainers.

Fixes [YOCTO #11208]

Signed-off-by: Amanda Brindle <amanda.r.brindle@...>
---
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

diff --git a/layerindex/views.py b/layerindex/views.py
index bcf6671..095f428 100644
--- a/layerindex/views.py
+++ b/layerindex/views.py
@@ -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
Just to follow up here, I've merged this with a change to the above lines to
only include staff/superusers.

Cheers,
Paul

--

Paul Eggleton
Intel Open Source Technology Centre

Join yocto@lists.yoctoproject.org to automatically receive all group messages.