Commit b6df3c3c authored by J08nY's avatar J08nY

Add pubkey view for downloading list pubkey.

parent 7b05d231
......@@ -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
......@@ -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():
......
......@@ -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 %}
......
{% 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 %}
......@@ -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))
]
......@@ -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
Markdown is supported
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