diff options
| -rw-r--r-- | src/django_pgpmailman/models.py | 9 | ||||
| -rw-r--r-- | src/django_pgpmailman/plugin.py | 2 | ||||
| -rw-r--r-- | src/django_pgpmailman/templates/django_pgpmailman/index.html | 48 | ||||
| -rw-r--r-- | src/django_pgpmailman/templates/django_pgpmailman/summary.html | 14 | ||||
| -rw-r--r-- | src/django_pgpmailman/urls.py | 13 | ||||
| -rw-r--r-- | src/django_pgpmailman/views/list.py | 18 |
6 files changed, 77 insertions, 27 deletions
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 <http://www.gnu.org/licenses/>. + +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 @@ <div class="table-responsive"> <table class="table table-bordered table-striped"> <thead> - <tr> - <th>{% trans 'List name' %}</th> - <th>{% trans 'Post address' %}</th> - <th>{% trans 'Description' %}</th> - </tr> + <tr> + <th>{% trans 'List name' %}</th> + <th>{% trans 'Post address' %}</th> + <th>{% trans 'Key fingerprint' %}</th> + <th>{% trans 'Description' %}</th> + </tr> </thead> <tbody> - {% for pgp_list in lists %} - {% with pgp_list.mlist as mlist %} - <tr> - <td> - <a href="{% url 'pgp_list_summary' list_id=mlist.list_id %}">{{ mlist.display_name }}</a> - {% if user.is_superuser and not mlist.settings.advertised %} ({% trans 'unadvertised' %}*){% endif %} - </td> - <td>{{ mlist.fqdn_listname }}</td> - <td>{{ pgp_list.key.fingerprint }}</td> - <td>{{ mlist.settings.description }}</td> - </tr> - {% endwith %} - {% endfor %} + {% for pgp_list in lists %} + {% with mlist=pgp_list.mlist %} + {% if user.is_superuser or mlist.settings.advertised %} + <tr> + <td> + <a href="{% url 'pgp_list_summary' list_id=pgp_list.list_id %}">{{ mlist.display_name }}</a> + {% if user.is_superuser and not mlist.settings.advertised %} + ({% trans 'unadvertised' %} + *){% endif %} + </td> + <td>{{ mlist.fqdn_listname }}</td> + <td> + <a href="{% url 'pgp_list_pubkey' list_id=pgp_list.list_id %}">{{ pgp_list.pubkey.fingerprint }}</a> + </td> + <td>{{ mlist.settings.description }}</td> + </tr> + {% endif %} + {% endwith %} + {% endfor %} </tbody> </table> </div> {% if user.is_superuser %} - <small>* {% trans 'Only admins see unadvertised lists in the list index.' %}</small> + <small> + * {% trans 'Only admins see unadvertised lists in the list index.' %}</small> {% 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 %} + + <div class="page-header"> + <h1>{% trans 'PGP enabled Mailing List' %}</h1> + </div> + +{% 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 <http://www.gnu.org/licenses/>. 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<list_id>[^/]+)/', 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 |
