From b6df3c3cdcb4ca25b48cc316502ec39482afe20e Mon Sep 17 00:00:00 2001 From: J08nY Date: Fri, 11 Aug 2017 20:29:28 +0200 Subject: Add pubkey view for downloading list pubkey. --- src/django_pgpmailman/models.py | 9 ++-- src/django_pgpmailman/plugin.py | 2 +- .../templates/django_pgpmailman/index.html | 48 +++++++++++++--------- .../templates/django_pgpmailman/summary.html | 14 +++++++ src/django_pgpmailman/urls.py | 13 ++++-- src/django_pgpmailman/views/list.py | 18 ++++++++ 6 files changed, 77 insertions(+), 27 deletions(-) create mode 100644 src/django_pgpmailman/templates/django_pgpmailman/summary.html diff --git a/src/django_pgpmailman/models.py b/src/django_pgpmailman/models.py index f396e73..8b8dbdd 100644 --- a/src/django_pgpmailman/models.py +++ b/src/django_pgpmailman/models.py @@ -15,6 +15,9 @@ # # You should have received a copy of the GNU General Public License along with # this program. If not, see . + +from __future__ import absolute_import, unicode_literals + from itertools import chain from mailmanclient._client import RESTObject, MailingList @@ -30,7 +33,7 @@ class PGPMailingList(RESTObject): 'strip_original_sig', 'sign_outgoing', 'nonencrypted_msg_action', 'encrypt_outgoing', 'key_change_workflow', 'key_signing_allowed') _read_only_properties = ('self_link', 'list_id') - _properties = chain(_writable_properties, _read_only_properties) + _properties = list(chain(_writable_properties, _read_only_properties)) @property def mlist(self): @@ -40,7 +43,7 @@ class PGPMailingList(RESTObject): def key(self): try: response, content = self._connection.call(self._url + '/key') - key, _ = PGPKey.from_blob(response['key']) + key, _ = PGPKey.from_blob(content['key']) return key except PGPError: return None @@ -58,7 +61,7 @@ class PGPMailingList(RESTObject): def pubkey(self): try: response, content = self._connection.call(self._url + '/pubkey') - key, _ = PGPKey.from_blob(response['key']) + key, _ = PGPKey.from_blob(content['public_key']) return key except PGPError: return None diff --git a/src/django_pgpmailman/plugin.py b/src/django_pgpmailman/plugin.py index 61c2c38..9cbcc77 100644 --- a/src/django_pgpmailman/plugin.py +++ b/src/django_pgpmailman/plugin.py @@ -40,7 +40,7 @@ class PGPPlugin(Plugin): def get_list(self, list_identifier): response, content = self.call('lists/%s' % list_identifier) - return PGPMailingList(self._connection, content['self_link', content]) + return PGPMailingList(self._connection, content['self_link'], content) def get_pgp_plugin(): diff --git a/src/django_pgpmailman/templates/django_pgpmailman/index.html b/src/django_pgpmailman/templates/django_pgpmailman/index.html index b33b668..cbe309f 100644 --- a/src/django_pgpmailman/templates/django_pgpmailman/index.html +++ b/src/django_pgpmailman/templates/django_pgpmailman/index.html @@ -3,7 +3,7 @@ {% load pagination %} {% block head_title %} -{% trans 'PGP List Index' %} - {{ block.super }} + {% trans 'PGP List Index' %} - {{ block.super }} {% endblock %} {% block content %} @@ -16,31 +16,39 @@
- - - - - + + + + + + - {% for pgp_list in lists %} - {% with pgp_list.mlist as mlist %} - - - - - - - {% endwith %} - {% endfor %} + {% for pgp_list in lists %} + {% with mlist=pgp_list.mlist %} + {% if user.is_superuser or mlist.settings.advertised %} + + + + + + + {% endif %} + {% endwith %} + {% endfor %}
{% trans 'List name' %}{% trans 'Post address' %}{% trans 'Description' %}
{% trans 'List name' %}{% trans 'Post address' %}{% trans 'Key fingerprint' %}{% trans 'Description' %}
- {{ mlist.display_name }} - {% if user.is_superuser and not mlist.settings.advertised %} ({% trans 'unadvertised' %}*){% endif %} - {{ mlist.fqdn_listname }}{{ pgp_list.key.fingerprint }}{{ mlist.settings.description }}
+ {{ mlist.display_name }} + {% if user.is_superuser and not mlist.settings.advertised %} + ({% trans 'unadvertised' %} + *){% endif %} + {{ mlist.fqdn_listname }} + {{ pgp_list.pubkey.fingerprint }} + {{ mlist.settings.description }}
{% if user.is_superuser %} - * {% trans 'Only admins see unadvertised lists in the list index.' %} + + * {% trans 'Only admins see unadvertised lists in the list index.' %} {% endif %} {% paginator lists %} {% else %} diff --git a/src/django_pgpmailman/templates/django_pgpmailman/summary.html b/src/django_pgpmailman/templates/django_pgpmailman/summary.html new file mode 100644 index 0000000..5b5a60d --- /dev/null +++ b/src/django_pgpmailman/templates/django_pgpmailman/summary.html @@ -0,0 +1,14 @@ +{% extends "django_pgpmailman/base.html" %} +{% load i18n %} + +{% block head_title %} +{% trans 'PGP List' %} - {{ block.super }} +{% endblock %} + +{% block content %} + + + +{% endblock content %} diff --git a/src/django_pgpmailman/urls.py b/src/django_pgpmailman/urls.py index 0a90cb5..d10fa1c 100644 --- a/src/django_pgpmailman/urls.py +++ b/src/django_pgpmailman/urls.py @@ -17,10 +17,17 @@ # this program. If not, see . from __future__ import absolute_import, unicode_literals -from django.conf.urls import url +from django.conf.urls import url, include -from django_pgpmailman.views.list import pgp_list_index +from django_pgpmailman.views.list import (pgp_list_index, pgp_list_summary, + pgp_list_pubkey) + +list_patterns = [ + url(r'^$', pgp_list_summary, name='pgp_list_summary'), + url(r'^pubkey$', pgp_list_pubkey, name='pgp_list_pubkey') +] urlpatterns = [ - url(r'^$', pgp_list_index, name='pgp_list_index') + url(r'^$', pgp_list_index, name='pgp_list_index'), + url(r'^lists/(?P[^/]+)/', include(list_patterns)) ] diff --git a/src/django_pgpmailman/views/list.py b/src/django_pgpmailman/views/list.py index 0c0f367..b99e332 100644 --- a/src/django_pgpmailman/views/list.py +++ b/src/django_pgpmailman/views/list.py @@ -18,6 +18,8 @@ from __future__ import absolute_import, unicode_literals +from django.core.files.base import ContentFile +from django.http import HttpResponse from django.shortcuts import render from django_pgpmailman.plugin import get_pgp_plugin @@ -26,3 +28,19 @@ from django_pgpmailman.plugin import get_pgp_plugin def pgp_list_index(request): return render(request, 'django_pgpmailman/index.html', {'lists': get_pgp_plugin().lists}) + + +def pgp_list_summary(request, list_id): + return render(request, 'django_pgpmailman/summary.html', + {'pgp_list': get_pgp_plugin().get_list(list_id)}) + + +def pgp_list_pubkey(request, list_id): + pgp_list = get_pgp_plugin().get_list(list_id) + pubkey = pgp_list.pubkey + pubkey_file = ContentFile(str(pubkey)) + response = HttpResponse(pubkey_file, 'application/pgp-keys') + response['Content-Length'] = pubkey_file.size + response[ + 'Content-Disposition'] = 'attachment; filename="%s.asc"' % pgp_list.list_id + return response -- cgit v1.2.3-70-g09d2