From 7a3fe8b194e2b1595370e09fd48a38b97b889cc5 Mon Sep 17 00:00:00 2001 From: Timur Sufiev Date: Thu, 12 Sep 2013 15:12:03 +0400 Subject: [PATCH] Make field validation to be conditional. Introduce new field attribute 'enabled' - true by default, but if it is false, then the field won't be validated, only coerced to Python type. This actually solves the issue with hidden (and disabled) fields which don't validate and prevent proceeding to next step. Change-Id: Ie57fa4731792ed1e44e9f61fa5cb6a16ddaf3109 Fixes: bug MRN-883 --- muranodashboard/panel/services/fields.py | 9 ++++++++- muranodashboard/panel/services/forms.py | 3 ++- muranodashboard/services/MsSqlClusterServer.yaml | 10 +++++----- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/muranodashboard/panel/services/fields.py b/muranodashboard/panel/services/fields.py index 8e4c79e4d..862cc3939 100644 --- a/muranodashboard/panel/services/fields.py +++ b/muranodashboard/panel/services/fields.py @@ -38,7 +38,14 @@ def with_request(func): return update -class CustomPropertiesField(object): +class CustomPropertiesField(forms.Field): + def clean(self, value): + """Skip all validators if field is disabled.""" + if getattr(self, 'enabled', True): + return super(CustomPropertiesField, self).clean(value) + else: + return super(CustomPropertiesField, self).to_python(value) + @classmethod def push_properties(cls, kwargs): props = {} diff --git a/muranodashboard/panel/services/forms.py b/muranodashboard/panel/services/forms.py index a018812b1..2f41aea37 100644 --- a/muranodashboard/panel/services/forms.py +++ b/muranodashboard/panel/services/forms.py @@ -253,7 +253,8 @@ class ServiceConfigurationForm(UpdatableFieldsForm): raise forms.ValidationError(error_messages) for name, field in self.fields.iteritems(): - if isinstance(field, fields.PasswordField): + if (isinstance(field, fields.PasswordField) and + getattr(field, 'enabled', True)): field.compare(name, cleaned_data) if hasattr(field, 'postclean'): diff --git a/muranodashboard/services/MsSqlClusterServer.yaml b/muranodashboard/services/MsSqlClusterServer.yaml index 5e4d2c56b..eecb6aa18 100644 --- a/muranodashboard/services/MsSqlClusterServer.yaml +++ b/muranodashboard/services/MsSqlClusterServer.yaml @@ -58,18 +58,18 @@ forms: - name: domainAdminUserName type: string label: Active Directory User - required: {YAQL: $.serviceConfiguration.externalAD} + enabled: {YAQL: $.serviceConfiguration.externalAD} regexpValidator: '^[-\w]+$' errorMessages: - invalid: 'Just letters, numbers, underscores and hyphens are allowed.' + invalid: Just letters, numbers, underscores and hyphens are allowed. - name: domainAdminPassword type: password label: Active Directory Password - required: {YAQL: $.serviceConfiguration.externalAD} + enabled: {YAQL: $.serviceConfiguration.externalAD} - name: domain type: domain label: Domain - required: {YAQL: not $.serviceConfiguration.externalAD} + enabled: {YAQL: not $.serviceConfiguration.externalAD} description: >- Service can be joined to the Active Directory domain. If you want to create an AD domain create the AD Service first. @@ -89,7 +89,7 @@ forms: label: SA Password description: Set system administrator password for the MS SQL Server. helpText: SQL server System Administrator account - required: {YAQL: $.serviceConfiguration.mixedModeAuth} + enabled: {YAQL: $.serviceConfiguration.mixedModeAuth} - clusterConfiguration: fields: - name: clusterIP