# -*- 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 . 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_sig = 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.') )