Commit bd8dd5fb authored by J08nY's avatar J08nY

Make list settings forms work.

parent 70cf9c14
......@@ -132,3 +132,30 @@ class ListEncryptionSettingsForm(forms.Form):
'done before executing the signature checks. `Defer` '
'lets the message pass-through to signature checks.')
)
key_change_choices = (('pgp-key-change-workflow', _('Default')),
('pgp-key-change-mod-workflow',
_('Default, then moderate')))
member_role_choices = (('member', _('Member')),
('owner', _('Owner')),
('moderator', _('Moderator')),
('nonmember', _('Nonmember')))
class ListMiscSettingsForm(forms.Form):
key_change_workflow = forms.ChoiceField(
widget=forms.Select(),
choices=key_change_choices,
required=False,
label=_('Key change workflow'),
help_text=_('A workflow to use for the key change operation.')
)
key_signing_allowed = forms.MultipleChoiceField(
widget=forms.SelectMultiple(),
choices=member_role_choices,
required=False,
label=_('Key signing allowed'),
help_text=_('A set of member roles that are allowed to sign the '
'lists public key via the `key sign` command.')
)
......@@ -7,9 +7,11 @@
{% endblock %}
{% block content %}
{% with mlist=pgp_list.mlist %}
{% include 'django_pgpmailman/list/nav.html' with nav_tab='encryption_settings' nav_title='Encryption settings' %}
{% include 'django_pgpmailman/list/nav.html' with nav_tab='encryption_settings' nav_title='Encryption settings' %}
<form action="{% url 'pgp_list_encryption_settings' pgp_list.list_id %}"
method="post"
class="form-horizontal">
{% bootstrap_form_horizontal form 3 8 'Save changes' %}
{% endwith %}
</form>
{% endblock content %}
{% extends "django_pgpmailman/base.html" %}
{% load i18n %}
{% load bootstrap_tags %}
{% block head_title %}
{% trans 'PGP List' %} - {{ block.super }}
{% endblock %}
{% block content %}
{% include 'django_pgpmailman/list/nav.html' with nav_tab='misc_settings' nav_title='Miscellaneous settings' %}
<form action="{% url 'pgp_list_misc_settings' pgp_list.list_id %}"
method="post"
class="form-horizontal">
{% bootstrap_form_horizontal form 3 8 'Save changes' %}
</form>
{% endblock content %}
......@@ -17,6 +17,10 @@
class="{% if nav_tab == 'signature_settings' %}active{% endif %}">
<a href="{% url 'pgp_list_signature_settings' mlist.list_id %}">{% trans 'Signature settings' %}</a>
</li>
<li role="presentation"
class="{% if nav_tab == 'misc_settings' %}active{% endif %}">
<a href="{% url 'pgp_list_misc_settings' mlist.list_id %}">{% trans 'Miscellaneous settings' %}</a>
</li>
</ul>
{% else %}
......
......@@ -7,9 +7,10 @@
{% endblock %}
{% block content %}
{% with mlist=pgp_list.mlist %}
{% include 'django_pgpmailman/list/nav.html' with nav_tab='signature_settings' nav_title='Signature settings' %}
{% include 'django_pgpmailman/list/nav.html' with nav_tab='signature_settings' nav_title='Signature settings' %}
<form action="{% url 'pgp_list_signature_settings' pgp_list.list_id %}"
method="post"
class="form-horizontal">
{% bootstrap_form_horizontal form 3 8 'Save changes' %}
{% endwith %}
</form>
{% endblock content %}
......@@ -21,16 +21,22 @@ from django.conf.urls import url, include
from django_pgpmailman.views.list import (
pgp_list_index, pgp_list_summary, pgp_list_pubkey, pgp_list_key_management,
ListSignatureSettingsView, ListEncryptionSettingsView)
ListSignatureSettingsView, ListEncryptionSettingsView,
ListMiscSettingsView)
from django_pgpmailman.views.user import pgp_user_profile
list_patterns = [
url(r'^$', pgp_list_summary, name='pgp_list_summary'),
url(r'^key/$', pgp_list_key_management, name='pgp_list_key_management'),
url(r'^signatures/$', ListSignatureSettingsView.as_view(),
url(r'^signatures/$', ListSignatureSettingsView.as_view(
success_url='pgp_list_signature_settings'),
name='pgp_list_signature_settings'),
url(r'^encryption/$', ListEncryptionSettingsView.as_view(),
url(r'^encryption/$', ListEncryptionSettingsView.as_view(
success_url='pgp_list_encryption_settings'),
name='pgp_list_encryption_settings'),
url(r'^misc/$',
ListMiscSettingsView.as_view(success_url='pgp_list_misc_settings'),
name='pgp_list_misc_settings'),
url(r'^pubkey$', pgp_list_pubkey, name='pgp_list_pubkey')
]
......
......@@ -18,17 +18,21 @@
from __future__ import absolute_import, unicode_literals
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.core.files.base import ContentFile
from django.http import HttpResponse
from django.shortcuts import render
from django.urls import reverse
from django.utils.decorators import method_decorator
from django.utils.translation import ugettext_lazy as _
from django.views.generic import FormView
from six.moves.urllib.error import HTTPError
from django_pgpmailman.decorators import list_view
from django_pgpmailman.forms import (ListSignatureSettingsForm,
ListEncryptionSettingsForm)
ListEncryptionSettingsForm,
ListMiscSettingsForm)
from django_pgpmailman.plugin import get_pgp_plugin
......@@ -66,6 +70,32 @@ class ListSettings(FormView):
self.pgp_list = get_pgp_plugin().get_list(kwargs['list_id'])
return super(ListSettings, self).dispatch(request, *args, **kwargs)
def form_valid(self, form):
if not form.changed_data:
return
for key in form.changed_data:
if form.cleaned_data[key] is not None:
setattr(self.pgp_list, key, form.cleaned_data[key])
try:
self.pgp_list.save()
if form.has_changed():
messages.success(
self.request, _('List settings have been updated.'))
else:
messages.info(self.request, _('List settings did not change.'))
except HTTPError as e:
messages.error(self.request, e.msg)
return super(ListSettings, self).form_valid(form)
def get_success_url(self):
return reverse(self.success_url,
kwargs=dict(list_id=self.pgp_list.list_id))
class ListSignatureSettingsView(ListSettings):
form_class = ListSignatureSettingsForm
......@@ -75,40 +105,28 @@ class ListSignatureSettingsView(ListSettings):
'revoked_sig_action', 'invalid_sig_action',
'duplicate_sig_action')
def form_valid(self, form):
try:
pass
except HTTPError as e:
pass
class ListEncryptionSettingsView(ListSettings):
form_class = ListEncryptionSettingsForm
template_name = 'django_pgpmailman/list/encryption_settings.html'
properties = ('nonencrypted_msg_action', 'encrypt_outgoing')
def form_valid(self, form):
try:
pass
except HTTPError as e:
pass
class ListMiscSettingsView(ListSettings):
form_class = ListMiscSettingsForm
template_name = 'django_pgpmailman/list/misc_settings.html'
properties = ('key_change_workflow', 'key_signing_allowed')
# TODO: proper list owner auth
@login_required
@list_view
def pgp_list_key_management(request, pgp_list):
return render(request, 'django_pgpmailman/list/key_management.html',
{'pgp_list': pgp_list})
class ListKeyManagementView(ListSettings):
pass
# TODO: proper list owner auth
@login_required
@list_view
def pgp_list_signature_settings(request, pgp_list):
return render(request, 'django_pgpmailman/list/signature_settings.html',
def pgp_list_key_management(request, pgp_list):
return render(request, 'django_pgpmailman/list/key_management.html',
{'pgp_list': pgp_list})
......
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