Update document signatures app

Add keyword arguments.

Remove source column functions and move their code to the model.

Use the FilteredSelectionForm for the key selection in the
document version signing view.

Update the field definition of the DetailForm subclasses
to use the new internface.

Update URL parameters to use the "_id" form.

Update views filtering to comply with MERC 6.

Move repeated test code to its own test mixin.

Update links to work with the new Link class interface.

Modernize tests.

Signed-off-by: Roberto Rosario <Roberto.Rosario@mayan-edms.com>
This commit is contained in:
Roberto Rosario
2019-01-25 01:32:05 -04:00
parent 890f872681
commit 4937d8b776
12 changed files with 450 additions and 641 deletions
+48 -46
View File
@@ -5,8 +5,7 @@ import logging
from django import forms
from django.utils.translation import ugettext_lazy as _
from mayan.apps.acls.models import AccessControlList
from mayan.apps.common.forms import DetailForm
from mayan.apps.common.forms import DetailForm, FilteredSelectionForm
from mayan.apps.django_gpg.models import Key
from mayan.apps.django_gpg.permissions import permission_key_sign
@@ -15,44 +14,39 @@ from .models import SignatureBaseModel
logger = logging.getLogger(__name__)
class DocumentVersionSignatureCreateForm(forms.Form):
class DocumentVersionSignatureCreateForm(FilteredSelectionForm):
key = forms.ModelChoiceField(
label=_('Key'), queryset=Key.objects.none()
)
passphrase = forms.CharField(
label=_('Passphrase'), required=False,
help_text=_(
'The passphrase to unlock the key and allow it to be used to '
'sign the document version.'
), label=_('Passphrase'), required=False,
widget=forms.widgets.PasswordInput
)
def __init__(self, *args, **kwargs):
user = kwargs.pop('user', None)
logger.debug('user: %s', user)
super(
DocumentVersionSignatureCreateForm, self
).__init__(*args, **kwargs)
queryset = AccessControlList.objects.filter_by_access(
permission_key_sign, user, queryset=Key.objects.private_keys()
class Meta:
allow_multiple = False
field_name = 'key'
label = _('Key')
help_text = _(
'Private key that will be used to sign this document version.'
)
self.fields['key'].queryset = queryset
permission = permission_key_sign
queryset = Key.objects.private_keys()
required = True
widget_attributes = {'class': 'select2'}
class DocumentVersionSignatureDetailForm(DetailForm):
def __init__(self, *args, **kwargs):
extra_fields = (
{'label': _('Signature is embedded?'), 'field': 'is_embedded'},
{
'label': _('Signature date'), 'field': 'date',
'widget': forms.widgets.DateInput
},
{'label': _('Signature key ID'), 'field': 'key_id'},
{
'label': _('Signature key present?'),
'field': lambda x: x.public_key_fingerprint is not None
},
)
super(
DocumentVersionSignatureDetailForm, self
).__init__(*args, **kwargs)
extra_fields = self.Meta.extra_fields
if kwargs['instance'].public_key_fingerprint:
key = Key.objects.get(
@@ -60,44 +54,52 @@ class DocumentVersionSignatureDetailForm(DetailForm):
)
extra_fields += (
{'label': _('Signature ID'), 'field': 'signature_id'},
{'field': 'signature_id'},
{
'label': _('Key fingerprint'),
'field': lambda x: key.fingerprint
'field': 'fingerprint',
'object': key
},
{
'label': _('Key creation date'),
'field': lambda x: key.creation_date,
'field': 'creation_date',
'object': key,
'widget': forms.widgets.DateInput
},
{
'label': _('Key expiration date'),
'field': lambda x: key.expiration_date or _('None'),
'field': 'get_expiration_date_display',
'object': key,
'widget': forms.widgets.DateInput
},
{
'label': _('Key length'),
'field': lambda x: key.length
'field': 'length',
'object': key
},
{
'label': _('Key algorithm'),
'field': lambda x: key.algorithm
'field': 'algorithm',
'object': key
},
{
'label': _('Key user ID'),
'field': lambda x: key.user_id
'field': 'get_escaped_user_id',
'object': key
},
{
'label': _('Key type'),
'field': lambda x: key.get_key_type_display()
'field': 'get_key_type_display',
'object': key
},
)
kwargs['extra_fields'] = extra_fields
super(
DocumentVersionSignatureDetailForm, self
).__init__(*args, **kwargs)
self.Meta.extra_fields = extra_fields
class Meta:
extra_fields = (
{'field': 'get_signature_type_display'},
{
'field': 'date',
'widget': forms.widgets.DateInput
},
{'field': 'key_id'},
{
'field': 'get_key_available_display'
},
)
fields = ()
model = SignatureBaseModel