Commit 86f8ca67 authored by Lars Rustand's avatar Lars Rustand
Browse files

Send notification once packages has enough signoffs

parent b1eee27f
...@@ -4,10 +4,12 @@ ...@@ -4,10 +4,12 @@
from django import forms from django import forms
from django.contrib.auth.decorators import permission_required from django.contrib.auth.decorators import permission_required
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.core.mail import EmailMessage
from django.core.serializers.json import DjangoJSONEncoder from django.core.serializers.json import DjangoJSONEncoder
from django.db import transaction from django.db import transaction
from django.http import HttpResponse, Http404 from django.http import HttpResponse, Http404
from django.shortcuts import get_list_or_404, redirect, render from django.shortcuts import get_list_or_404, redirect, render
from django.template import loader
from django.utils.timezone import now from django.utils.timezone import now
from django.views.decorators.cache import never_cache from django.views.decorators.cache import never_cache
...@@ -53,6 +55,30 @@ def signoff_package(request, name, repo, arch, revoke=False): ...@@ -53,6 +55,30 @@ def signoff_package(request, name, repo, arch, revoke=False):
return render(request, '403.html', status=403) return render(request, '403.html', status=403)
signoff, created = Signoff.objects.get_or_create_from_package( signoff, created = Signoff.objects.get_or_create_from_package(
package, request.user) package, request.user)
signoffs = Signoff.objects.for_package(package).filter(
revoked__isnull=True)
if signoffs.count() >= spec.required:
packager = package.packager
# TODO: Handle notification when packager does not exist
if packager:
toemail = [packager.email]
subject = f'{package.repo.name} package ' + \
f'[{package.pkgname} {package.full_version}] approved'
# send notification email to the maintainers
tmpl = loader.get_template('packages/approved.txt')
ctx = {
'signoffs': signoffs,
'pkg': package,
}
msg = EmailMessage(subject,
tmpl.render(ctx),
'Arch Website Notification <nobody@archlinux.org>',
toemail,
)
msg.send(fail_silently=True)
all_signoffs = Signoff.objects.for_package(package) all_signoffs = Signoff.objects.for_package(package)
......
{% autoescape off %} The {{ pkg.repo.name }} package {{ pkg.pkgname }} {{ pkg.full_version }} has received the required number of signoffs.
The package was signed off by the following users:{% for s in signoffs %}
- {{ s.user.username }}{% endfor %}{% endautoescape %}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment