diff options
| author | J08nY | 2017-08-15 00:06:27 +0200 |
|---|---|---|
| committer | J08nY | 2017-08-15 00:06:27 +0200 |
| commit | ba165c597fb7d7407eea609eeaff115c99645c6d (patch) | |
| tree | e3b946472661a7ff395d8485d783b1664e84a4de | |
| parent | 9e33fdaea8eaf5825542254afb55f25c1a63fc6b (diff) | |
| download | django-pgpmailman-ba165c597fb7d7407eea609eeaff115c99645c6d.tar.gz django-pgpmailman-ba165c597fb7d7407eea609eeaff115c99645c6d.tar.zst django-pgpmailman-ba165c597fb7d7407eea609eeaff115c99645c6d.zip | |
| -rw-r--r-- | src/django_pgpmailman/decorators.py | 32 | ||||
| -rw-r--r-- | src/django_pgpmailman/forms.py | 134 | ||||
| -rw-r--r-- | src/django_pgpmailman/models.py | 2 | ||||
| -rw-r--r-- | src/django_pgpmailman/templates/django_pgpmailman/list/signature_settings.html | 2 | ||||
| -rw-r--r-- | src/django_pgpmailman/views/list.py | 45 | ||||
| -rw-r--r-- | src/django_pgpmailman/views/user.py | 2 |
6 files changed, 206 insertions, 11 deletions
diff --git a/src/django_pgpmailman/decorators.py b/src/django_pgpmailman/decorators.py new file mode 100644 index 0000000..41e94da --- /dev/null +++ b/src/django_pgpmailman/decorators.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2012-2017 by the Free Software Foundation, Inc. +# +# This file is part of Postorius. +# +# Postorius is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) +# any later version. +# +# Postorius is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along with +# Postorius. If not, see <http://www.gnu.org/licenses/>. +from django.http import Http404 +from six.moves.urllib_error import HTTPError + +from django_pgpmailman.plugin import get_pgp_plugin + + +def list_view(fn): + def wrapper(request, list_id, *args, **kwargs): + try: + pgp_list = get_pgp_plugin().get_list(list_id) + except HTTPError: + raise Http404 + return fn(request, pgp_list, *args, **kwargs) + + return wrapper diff --git a/src/django_pgpmailman/forms.py b/src/django_pgpmailman/forms.py new file mode 100644 index 0000000..bba8e41 --- /dev/null +++ b/src/django_pgpmailman/forms.py @@ -0,0 +1,134 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2017 Jan Jancar +# +# This file is a part of the Django Mailman PGP plugin. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# 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 django import forms + +from django.utils.translation import ugettext_lazy as _ + + +class NullBooleanRadioSelect(forms.RadioSelect): + def value_from_datadict(self, data, files, name): + value = data.get(name, None) + return {'2': True, + True: True, + 'True': True, + '3': False, + 'False': False, + False: False}.get(value, None) + + +boolean_choices = ((True, _('Yes')), (False, _('No'))) +action_choices = ( + ('hold', _('Hold')), + ('reject', _('Reject')), + ('discard', _('Discard')), + ('accept', _('Accept')), + ('defer', _('Defer')) +) + + +class ListSignatureSettingsForm(forms.Form): + sign_outgoing = forms.NullBooleanField( + widget=NullBooleanRadioSelect(choices=boolean_choices), + required=False, + label=_('Sign outgoing messages'), + help_text=_( + 'Whether to sign the outgoing postings of a mailing list' + 'by the list key.') + ) + strip_original_signature = forms.NullBooleanField( + widget=NullBooleanRadioSelect(choices=boolean_choices), + required=False, + label=_('Strip sender signature'), + help_text=_('Whether to strip the original signature of a message' + '(if any).') + ) + unsigned_msg_action = forms.ChoiceField( + widget=forms.Select(), + choices=action_choices, + required=False, + label=_('Unsigned message action'), + help_text=_( + 'An action to take on an unsigned message. `Defer` lets ' + 'the message pass-through to the next check.') + ) + inline_pgp_action = forms.ChoiceField( + widget=forms.Select(), + choices=action_choices, + required=False, + label=_('Inline PGP action'), + help_text=_( + 'An action to take on a message that is signed using ' + 'inline PGP. `Defer` lets the message pass-through to the ' + 'next check.') + ) + expired_sig_action = forms.ChoiceField( + widget=forms.Select(), + choices=action_choices, + required=False, + label=_('Expired signature action'), + help_text=_('An action to take on a message that has an expired ' + 'signature. `Defer` lets the message pass-through to' + 'the next check.') + ) + revoked_sig_action = forms.ChoiceField( + widget=forms.Select(), + choices=action_choices, + required=False, + label=_('Revoked signature action'), + help_text=_('An action to take on a message that has a revoked ' + 'signature. `Defer` lets the message pass-through to' + 'the next check.') + ) + invalid_sig_action = forms.ChoiceField( + widget=forms.Select(), + choices=action_choices, + required=False, + label=_('Invalid signature action'), + help_text=_('An action to take on a message with an invalid ' + 'signature. `Defer` lets the message pass-through to' + 'the next check.') + ) + duplicate_sig_action = forms.ChoiceField( + widget=forms.Select(), + choices=action_choices, + required=False, + label=_('Duplicate signature action'), + help_text=_('An action to take on a message which contains a ' + 'signature that was already posted to a PGP enabled ' + 'mailing list before. `Defer` lets the message ' + 'pass-through to the rest of the chain.') + ) + + +class ListEncryptionSettingsForm(forms.Form): + encrypt_outgoing = forms.NullBooleanField( + widget=NullBooleanRadioSelect(choices=boolean_choices), + required=False, + label=_('Encrypt outgoing messages'), + help_text=_('Whether to encrypt the outgoing postings of a mailing' + 'list to the subscribers keys.') + ) + nonencrypted_msg_action = forms.ChoiceField( + widget=forms.Select(), + choices=action_choices, + required=False, + label=_('Nonencrypted message action'), + help_text=_('An action to take on a nonencrypted message, is ' + 'done before executing the signature checks. `Defer` ' + 'lets the message pass-through to signature checks.') + ) diff --git a/src/django_pgpmailman/models.py b/src/django_pgpmailman/models.py index 8b8dbdd..406ae76 100644 --- a/src/django_pgpmailman/models.py +++ b/src/django_pgpmailman/models.py @@ -20,7 +20,7 @@ from __future__ import absolute_import, unicode_literals from itertools import chain -from mailmanclient._client import RESTObject, MailingList +from mailmanclient._client import MailingList, RESTObject from pgpy import PGPKey from pgpy.errors import PGPError from six.moves.urllib_error import HTTPError diff --git a/src/django_pgpmailman/templates/django_pgpmailman/list/signature_settings.html b/src/django_pgpmailman/templates/django_pgpmailman/list/signature_settings.html index f71554e..b996327 100644 --- a/src/django_pgpmailman/templates/django_pgpmailman/list/signature_settings.html +++ b/src/django_pgpmailman/templates/django_pgpmailman/list/signature_settings.html @@ -1,5 +1,6 @@ {% extends "django_pgpmailman/base.html" %} {% load i18n %} +{% load bootstrap_tags %} {% block head_title %} {% trans 'PGP List' %} - {{ block.super }} @@ -9,5 +10,6 @@ {% with mlist=pgp_list.mlist %} {% include 'django_pgpmailman/list/nav.html' with nav_tab='signature_settings' nav_title='Signature settings' %} + {% bootstrap_form_horizontal form 3 8 'Save changes' %} {% endwith %} {% endblock content %} diff --git a/src/django_pgpmailman/views/list.py b/src/django_pgpmailman/views/list.py index dfab2f5..680a1e7 100644 --- a/src/django_pgpmailman/views/list.py +++ b/src/django_pgpmailman/views/list.py @@ -18,10 +18,15 @@ from __future__ import absolute_import, unicode_literals +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.utils.decorators import method_decorator +from django.views.generic import FormView +from django_pgpmailman.decorators import list_view +from django_pgpmailman.forms import ListSignatureSettingsForm from django_pgpmailman.plugin import get_pgp_plugin @@ -31,28 +36,48 @@ def pgp_list_index(request): {'lists': get_pgp_plugin().lists}) -def pgp_list_summary(request, list_id): +@list_view +def pgp_list_summary(request, pgp_list): return render(request, 'django_pgpmailman/list/summary.html', - {'pgp_list': get_pgp_plugin().get_list(list_id)}) + {'pgp_list': pgp_list}) -def pgp_list_key_management(request, list_id): +@method_decorator(login_required, name='dispatch') +@method_decorator(list_view, name='dispatch') +class ListSignatureSettingsView(FormView): + form_class = ListSignatureSettingsForm + template_name = 'django_pgpmailman/list/signature_settings.html' + + def form_valid(self, form): + pass + + +# 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': get_pgp_plugin().get_list(list_id)}) + {'pgp_list': pgp_list}) -def pgp_list_encryption_settings(request, list_id): +# TODO: proper list owner auth +@login_required +@list_view +def pgp_list_encryption_settings(request, pgp_list): return render(request, 'django_pgpmailman/list/encryption_settings.html', - {'pgp_list': get_pgp_plugin().get_list(list_id)}) + {'pgp_list': pgp_list}) -def pgp_list_signature_settings(request, list_id): +# 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', - {'pgp_list': get_pgp_plugin().get_list(list_id)}) + {'pgp_list': pgp_list}) -def pgp_list_pubkey(request, list_id): - pgp_list = get_pgp_plugin().get_list(list_id) +@list_view +def pgp_list_pubkey(request, pgp_list): pubkey = pgp_list.pubkey pubkey_file = ContentFile(str(pubkey)) response = HttpResponse(pubkey_file, 'application/pgp-keys') diff --git a/src/django_pgpmailman/views/user.py b/src/django_pgpmailman/views/user.py index efc694d..ecc1b9e 100644 --- a/src/django_pgpmailman/views/user.py +++ b/src/django_pgpmailman/views/user.py @@ -15,8 +15,10 @@ # # 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 django.contrib.auth.decorators import login_required from django.shortcuts import render +@login_required def pgp_user_profile(request): return render(request, 'django_pgpmailman/user/summary.html') |
