From d4a5269bf13fab25823df98a8cfaf5f1daa4e587 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sat, 1 Aug 2020 20:00:20 +0200 Subject: [PATCH] *: Adjust forms to only show respective types of Flows and PropertyMappings --- passbook/providers/oauth/forms.py | 8 +++++--- passbook/providers/oidc/forms.py | 4 +++- passbook/providers/saml/forms.py | 9 ++++++--- passbook/sources/ldap/forms.py | 12 ++++++++++-- passbook/sources/oauth/forms.py | 13 ++++++------- passbook/sources/saml/forms.py | 23 +++++++++++------------ 6 files changed, 41 insertions(+), 28 deletions(-) diff --git a/passbook/providers/oauth/forms.py b/passbook/providers/oauth/forms.py index 3d3a7517e..8c470ef08 100644 --- a/passbook/providers/oauth/forms.py +++ b/passbook/providers/oauth/forms.py @@ -10,9 +10,11 @@ from passbook.providers.oauth.models import OAuth2Provider class OAuth2ProviderForm(forms.ModelForm): """OAuth2 Provider form""" - authorization_flow = forms.ModelChoiceField( - queryset=Flow.objects.filter(designation=FlowDesignation.AUTHORIZATION) - ) + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.fields["authorization_flow"].queryset = Flow.objects.filter( + designation=FlowDesignation.AUTHORIZATION + ) class Meta: diff --git a/passbook/providers/oidc/forms.py b/passbook/providers/oidc/forms.py index 46e56d16b..3f59611dd 100644 --- a/passbook/providers/oidc/forms.py +++ b/passbook/providers/oidc/forms.py @@ -1,6 +1,7 @@ """passbook OIDC IDP Forms""" from django import forms +from django.utils.translation import gettext as _ from oauth2_provider.generators import generate_client_id, generate_client_secret from oidc_provider.models import Client @@ -12,7 +13,8 @@ class OIDCProviderForm(forms.ModelForm): """OpenID Client form""" 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): diff --git a/passbook/providers/saml/forms.py b/passbook/providers/saml/forms.py index c49979af9..e1247575a 100644 --- a/passbook/providers/saml/forms.py +++ b/passbook/providers/saml/forms.py @@ -14,9 +14,12 @@ from passbook.providers.saml.models import SAMLPropertyMapping, SAMLProvider class SAMLProviderForm(forms.ModelForm): """SAML Provider form""" - authorization_flow = forms.ModelChoiceField( - queryset=Flow.objects.filter(designation=FlowDesignation.AUTHORIZATION) - ) + def __init__(self, *args, **kwargs): + 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: diff --git a/passbook/sources/ldap/forms.py b/passbook/sources/ldap/forms.py index 187a9d5dd..46ddbf27b 100644 --- a/passbook/sources/ldap/forms.py +++ b/passbook/sources/ldap/forms.py @@ -5,7 +5,6 @@ from django.contrib.admin.widgets import FilteredSelectMultiple from django.utils.translation import gettext_lazy as _ from passbook.admin.fields import CodeMirrorWidget -from passbook.admin.forms.source import SOURCE_FORM_FIELDS from passbook.core.expression import PropertyMappingEvaluator from passbook.sources.ldap.models import LDAPPropertyMapping, LDAPSource @@ -13,10 +12,19 @@ from passbook.sources.ldap.models import LDAPPropertyMapping, LDAPSource class LDAPSourceForm(forms.ModelForm): """LDAPSource Form""" + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.fields["property_mappings"].queryset = LDAPPropertyMapping.objects.all() + class Meta: 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", "bind_cn", "bind_password", diff --git a/passbook/sources/oauth/forms.py b/passbook/sources/oauth/forms.py index 5f1e6a65b..d2b020281 100644 --- a/passbook/sources/oauth/forms.py +++ b/passbook/sources/oauth/forms.py @@ -11,15 +11,14 @@ from passbook.sources.oauth.types.manager import MANAGER class OAuthSourceForm(forms.ModelForm): """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): 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"): for overide_field, overide_value in getattr(self.Meta, "overrides").items(): self.fields[overide_field].initial = overide_value diff --git a/passbook/sources/saml/forms.py b/passbook/sources/saml/forms.py index 29f6516b8..13108517e 100644 --- a/passbook/sources/saml/forms.py +++ b/passbook/sources/saml/forms.py @@ -1,7 +1,6 @@ """passbook SAML SP Forms""" from django import forms -from django.utils.translation import gettext as _ from passbook.admin.forms.source import SOURCE_FORM_FIELDS from passbook.crypto.models import CertificateKeyPair @@ -12,18 +11,18 @@ from passbook.sources.saml.models import SAMLSource class SAMLSourceForm(forms.ModelForm): """SAML Provider form""" - authentication_flow = forms.ModelChoiceField( - queryset=Flow.objects.filter(designation=FlowDesignation.AUTHENTICATION) - ) - enrollment_flow = forms.ModelChoiceField( - queryset=Flow.objects.filter(designation=FlowDesignation.ENROLLMENT) - ) - signing_kp = forms.ModelChoiceField( - queryset=CertificateKeyPair.objects.filter( + def __init__(self, *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 + ) + self.fields["signing_kp"].queryset = CertificateKeyPair.objects.filter( certificate_data__isnull=False, key_data__isnull=False, - ), - help_text=_("Certificate used to sign Requests."), - ) + ) class Meta: