Commit bfc7f14b authored by J08nY's avatar J08nY

Add basic user address index.

parent 9d23d95c
Pipeline #11021885 failed with stage
in 3 minutes and 5 seconds
......@@ -21,14 +21,14 @@ from django.http import Http404
from six import wraps
from six.moves.urllib_error import HTTPError
from django_pgpmailman.plugin import get_pgp_plugin
from django_pgpmailman.plugin import get_plugin, get_client
def list_view(fn):
def wrapper(request, *args, **kwargs):
pgp_list = get_pgp_plugin().get_list(kwargs.pop('list_id'))
pgp_list = get_plugin().get_list(kwargs.pop('list_id'))
except HTTPError:
raise Http404
return fn(request, pgp_list, *args, **kwargs)
......@@ -39,7 +39,7 @@ def list_view(fn):
def list_class_view(fn):
def wrapper(self, request, *args, **kwargs):
self.pgp_list = get_pgp_plugin().get_list(kwargs.pop('list_id'))
self.pgp_list = get_plugin().get_list(kwargs.pop('list_id'))
return fn(self, request, *args, **kwargs)
return wrapper
......@@ -68,3 +68,17 @@ def member_role_required(*roles):
return wrapped
return wrapper
def user_class_view(fn):
def wrapper(self, request, *args, **kwargs):
client = get_client()
user = request.user
self.mm_user = client.get_user(
except HTTPError:
self.mm_user = client.create_user(, user.get_full_name())
return fn(self, request, *args, **kwargs)
return wrapper
......@@ -20,7 +20,8 @@ from __future__ import absolute_import, unicode_literals
from itertools import chain
from mailmanclient._client import MailingList, RESTObject
from mailmanclient import Address, MailingList
from mailmanclient.restbase.base import RESTObject
from pgpy import PGPKey
from pgpy.errors import PGPError
......@@ -32,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 = list(chain(_writable_properties, _read_only_properties))
_properties = tuple(chain(_writable_properties, _read_only_properties))
def mlist(self):
......@@ -68,3 +69,13 @@ class PGPMailingList(RESTObject): + '/pubkey',
class PGPAddress(RESTObject):
_read_only_properties = ('self_link', 'email', 'key_fingerprint',
_properties = _read_only_properties
def address(self):
return Address(self._connection, 'addresses/{}'.format(
......@@ -20,7 +20,7 @@ from operator import itemgetter
from django.conf import settings
from mailmanclient._client import Plugin, Client
from django_pgpmailman.models import PGPMailingList
from django_pgpmailman.models import PGPMailingList, PGPAddress
class PGPPlugin(Plugin):
......@@ -42,16 +42,32 @@ class PGPPlugin(Plugin):
response, content ='lists/%s' % list_identifier)
return PGPMailingList(self._connection, content['self_link'], content)
def addresses(self):
response, content ='addresses')
if 'entries' not in content:
return []
return [PGPAddress(self._connection, entry['self_link'], entry) for
entry in sorted(content['entries'], key=itemgetter('email'))]
def get_address(self, email):
response, content ='addresses/%s' % email)
return PGPAddress(self._connection, content['self_link'], content)
def get_client():
return Client('%s/3.1' %
plugin = None
def get_pgp_plugin():
def get_plugin():
global plugin
if not plugin:
client = Client('%s/3.1' %
client = get_client()
plugin = PGPPlugin(client.get_plugin(settings.MAILMAN_PGP_PLUGIN_NAME))
return plugin
{% extends "django_pgpmailman/base.html" %}
\ No newline at end of file
{% extends "django_pgpmailman/base.html" %}
{% load i18n %}
{% block head_title %}
{% trans 'PGP User settings' %} - {{ block.super }}
{% endblock %}
{% block content %}
{% if addresses|length > 0 %}
<div class="table-responsive">
<table class="table table-bordered table-striped">
<th>{% trans 'Email' %}</th>
<th>{% trans 'Key fingerprint' %}</th>
<th>{% trans 'Key confirmed' %}</th>
{% for address in addresses %}
<td>{{ }}</td>
<td>{{ address.key_fingerprint }}</td>
<td>{{ address.key_confirmed }}</td>
{% endfor %}
{% else %}
<p>{% trans "You currently don't have any PGP enabled addresses. Subscribe to a PGP enabled list to setup one." %}</p>
{% endif %}
{% endblock %}
\ No newline at end of file
......@@ -23,7 +23,7 @@ from django_pgpmailman.views.list import (
pgp_list_index, pgp_list_summary,
ListSignatureSettingsView, ListEncryptionSettingsView,
ListMiscSettingsView, ListKeyManagementView, ListPubkey, ListPrivkey)
from django_pgpmailman.views.user import pgp_user_profile
from django_pgpmailman.views.user import UserSummaryView
list_patterns = [
url(r'^$', pgp_list_summary, name='pgp_list_summary'),
......@@ -44,7 +44,8 @@ list_patterns = [
user_patterns = [
url(r'^$', pgp_user_profile, name='pgp_user_profile')
url(r'^$', UserSummaryView.as_view(),
urlpatterns = [
......@@ -36,12 +36,12 @@ from django_pgpmailman.forms import (ListSignatureSettingsForm,
from django_pgpmailman.plugin import get_pgp_plugin
from django_pgpmailman.plugin import get_plugin
def pgp_list_index(request):
return render(request, 'django_pgpmailman/index.html',
{'lists': get_pgp_plugin().lists})
{'lists': get_plugin().lists})
......@@ -16,9 +16,41 @@
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <>.
from django.contrib.auth.decorators import login_required
from django.shortcuts import render
from django.utils.decorators import method_decorator
from django.views.generic import TemplateView
from six.moves.urllib_error import HTTPError
from django_pgpmailman.decorators import user_class_view
from django_pgpmailman.plugin import get_plugin
def pgp_user_profile(request):
return render(request, 'django_pgpmailman/user/summary.html')
class UserSummaryView(TemplateView):
template_name = 'django_pgpmailman/user/summary.html'
def dispatch(self, request, *args, **kwargs):
return super(UserSummaryView, self).dispatch(request, *args, **kwargs)
def get_context_data(self, **kwargs):
data = super(UserSummaryView, self).get_context_data(**kwargs)
addresses = []
for address in self.mm_user.addresses:
except HTTPError:
data['addresses'] = addresses
return data
# class UserSummaryView(FormView):
# template_name = 'django_pgpmailman/user/summary.html'
# @method_decorator(login_required)
# @user_class_view
# def dispatch(self, request, *args, **kwargs):
# return super(UserSummaryView, self).dispatch(request, *args, **kwargs)
# def get_form_class(self):
# return formset_factory(AddressForm, )
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