*: Adjust forms to only show respective types of Flows and PropertyMappings

This commit is contained in:
Jens Langhammer 2020-08-01 20:00:20 +02:00
parent fcf70a3cd4
commit d4a5269bf1
6 changed files with 41 additions and 28 deletions

View File

@ -10,8 +10,10 @@ from passbook.providers.oauth.models import OAuth2Provider
class OAuth2ProviderForm(forms.ModelForm): class OAuth2ProviderForm(forms.ModelForm):
"""OAuth2 Provider form""" """OAuth2 Provider form"""
authorization_flow = forms.ModelChoiceField( def __init__(self, *args, **kwargs):
queryset=Flow.objects.filter(designation=FlowDesignation.AUTHORIZATION) super().__init__(*args, **kwargs)
self.fields["authorization_flow"].queryset = Flow.objects.filter(
designation=FlowDesignation.AUTHORIZATION
) )
class Meta: class Meta:

View File

@ -1,6 +1,7 @@
"""passbook OIDC IDP Forms""" """passbook OIDC IDP Forms"""
from django import forms from django import forms
from django.utils.translation import gettext as _
from oauth2_provider.generators import generate_client_id, generate_client_secret from oauth2_provider.generators import generate_client_id, generate_client_secret
from oidc_provider.models import Client from oidc_provider.models import Client
@ -12,7 +13,8 @@ class OIDCProviderForm(forms.ModelForm):
"""OpenID Client form""" """OpenID Client form"""
authorization_flow = forms.ModelChoiceField( authorization_flow = forms.ModelChoiceField(
queryset=Flow.objects.filter(designation=FlowDesignation.AUTHORIZATION) queryset=Flow.objects.filter(designation=FlowDesignation.AUTHORIZATION),
help_text=_("Flow used when authorizing this provider."),
) )
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):

View File

@ -14,9 +14,12 @@ from passbook.providers.saml.models import SAMLPropertyMapping, SAMLProvider
class SAMLProviderForm(forms.ModelForm): class SAMLProviderForm(forms.ModelForm):
"""SAML Provider form""" """SAML Provider form"""
authorization_flow = forms.ModelChoiceField( def __init__(self, *args, **kwargs):
queryset=Flow.objects.filter(designation=FlowDesignation.AUTHORIZATION) super().__init__(*args, **kwargs)
self.fields["authorization_flow"].queryset = Flow.objects.filter(
designation=FlowDesignation.AUTHORIZATION
) )
self.fields["property_mappings"].queryset = SAMLPropertyMapping.objects.all()
class Meta: class Meta:

View File

@ -5,7 +5,6 @@ from django.contrib.admin.widgets import FilteredSelectMultiple
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from passbook.admin.fields import CodeMirrorWidget from passbook.admin.fields import CodeMirrorWidget
from passbook.admin.forms.source import SOURCE_FORM_FIELDS
from passbook.core.expression import PropertyMappingEvaluator from passbook.core.expression import PropertyMappingEvaluator
from passbook.sources.ldap.models import LDAPPropertyMapping, LDAPSource from passbook.sources.ldap.models import LDAPPropertyMapping, LDAPSource
@ -13,10 +12,19 @@ from passbook.sources.ldap.models import LDAPPropertyMapping, LDAPSource
class LDAPSourceForm(forms.ModelForm): class LDAPSourceForm(forms.ModelForm):
"""LDAPSource Form""" """LDAPSource Form"""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["property_mappings"].queryset = LDAPPropertyMapping.objects.all()
class Meta: class Meta:
model = LDAPSource model = LDAPSource
fields = SOURCE_FORM_FIELDS + [ fields = [
# we don't use all common fields, as we don't use flows for this
"name",
"slug",
"enabled",
# -- start of our custom fields
"server_uri", "server_uri",
"bind_cn", "bind_cn",
"bind_password", "bind_password",

View File

@ -11,15 +11,14 @@ from passbook.sources.oauth.types.manager import MANAGER
class OAuthSourceForm(forms.ModelForm): class OAuthSourceForm(forms.ModelForm):
"""OAuthSource Form""" """OAuthSource Form"""
authentication_flow = forms.ModelChoiceField(
queryset=Flow.objects.filter(designation=FlowDesignation.AUTHENTICATION)
)
enrollment_flow = forms.ModelChoiceField(
queryset=Flow.objects.filter(designation=FlowDesignation.ENROLLMENT)
)
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.fields["authentication_flow"].queryset = Flow.objects.filter(
designation=FlowDesignation.AUTHENTICATION
)
self.fields["enrollment_flow"].queryset = Flow.objects.filter(
designation=FlowDesignation.ENROLLMENT
)
if hasattr(self.Meta, "overrides"): if hasattr(self.Meta, "overrides"):
for overide_field, overide_value in getattr(self.Meta, "overrides").items(): for overide_field, overide_value in getattr(self.Meta, "overrides").items():
self.fields[overide_field].initial = overide_value self.fields[overide_field].initial = overide_value

View File

@ -1,7 +1,6 @@
"""passbook SAML SP Forms""" """passbook SAML SP Forms"""
from django import forms from django import forms
from django.utils.translation import gettext as _
from passbook.admin.forms.source import SOURCE_FORM_FIELDS from passbook.admin.forms.source import SOURCE_FORM_FIELDS
from passbook.crypto.models import CertificateKeyPair from passbook.crypto.models import CertificateKeyPair
@ -12,17 +11,17 @@ from passbook.sources.saml.models import SAMLSource
class SAMLSourceForm(forms.ModelForm): class SAMLSourceForm(forms.ModelForm):
"""SAML Provider form""" """SAML Provider form"""
authentication_flow = forms.ModelChoiceField( def __init__(self, *args, **kwargs):
queryset=Flow.objects.filter(designation=FlowDesignation.AUTHENTICATION) super().__init__(*args, **kwargs)
self.fields["authentication_flow"].queryset = Flow.objects.filter(
designation=FlowDesignation.AUTHENTICATION
) )
enrollment_flow = forms.ModelChoiceField( self.fields["enrollment_flow"].queryset = Flow.objects.filter(
queryset=Flow.objects.filter(designation=FlowDesignation.ENROLLMENT) designation=FlowDesignation.ENROLLMENT
) )
signing_kp = forms.ModelChoiceField( self.fields["signing_kp"].queryset = CertificateKeyPair.objects.filter(
queryset=CertificateKeyPair.objects.filter(
certificate_data__isnull=False, key_data__isnull=False, certificate_data__isnull=False, key_data__isnull=False,
),
help_text=_("Certificate used to sign Requests."),
) )
class Meta: class Meta: