Update DocumentVersionSignatureCreateForm
Use FilteredSelectionForm. Improve document signatures tests. Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -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,28 +14,30 @@ 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):
|
||||
|
||||
Reference in New Issue
Block a user