From cf62890fcf96136a969f5e1f006240812810bbb8 Mon Sep 17 00:00:00 2001 From: Matt Scott Date: Mon, 10 Apr 2023 17:28:54 -0400 Subject: [PATCH] Working on implementing the jQuery Validation plugin for the authentication settings editor. --- .../js/app-authentication-settings-editor.js | 121 +++++++++++++++++- .../admin_setting_authentication.html | 24 ++-- 2 files changed, 132 insertions(+), 13 deletions(-) diff --git a/powerdnsadmin/static/custom/js/app-authentication-settings-editor.js b/powerdnsadmin/static/custom/js/app-authentication-settings-editor.js index 72d1542..0fa6aa2 100644 --- a/powerdnsadmin/static/custom/js/app-authentication-settings-editor.js +++ b/powerdnsadmin/static/custom/js/app-authentication-settings-editor.js @@ -267,6 +267,38 @@ let AuthenticationSettingsModel = function (user_data, api_url, csrf_token, sele return self.ldap_enabled() === 1 && self.autoprovisioning() === 1; } + let google_oauth_auto_configure_enabled = function (element) { + return self.google_oauth_enabled() && self.google_oauth_auto_configure(); + } + + let google_oauth_auto_configure_disabled = function (element) { + return self.google_oauth_enabled() && !self.google_oauth_auto_configure(); + } + + let github_oauth_auto_configure_enabled = function (element) { + return self.github_oauth_enabled() && self.github_oauth_auto_configure(); + } + + let github_oauth_auto_configure_disabled = function (element) { + return self.github_oauth_enabled() && !self.github_oauth_auto_configure(); + } + + let azure_oauth_auto_configure_enabled = function (element) { + return self.azure_oauth_enabled() && self.azure_oauth_auto_configure(); + } + + let azure_oauth_auto_configure_disabled = function (element) { + return self.azure_oauth_enabled() && !self.azure_oauth_auto_configure(); + } + + let oidc_oauth_auto_configure_enabled = function (element) { + return self.oidc_oauth_enabled() && self.oidc_oauth_auto_configure(); + } + + let oidc_oauth_auto_configure_disabled = function (element) { + return self.oidc_oauth_enabled() && !self.oidc_oauth_auto_configure(); + } + jQuery.validator.addMethod('auth_enabled', auth_enabled, 'At least one authentication method must be enabled.'); jQuery.validator.addMethod('ldap_exclusive', ldap_exclusive, 'The LDAP group security and role auto-provisioning features are mutually exclusive.'); @@ -275,6 +307,7 @@ let AuthenticationSettingsModel = function (user_data, api_url, csrf_token, sele ]; $(selector).validate({ + ignore: '', errorPlacement: function (error, element) { let useFooter = false; for (let i = 0; i < footerErrorElements.length; i++) { @@ -413,8 +446,94 @@ let AuthenticationSettingsModel = function (user_data, api_url, csrf_token, sele maxlength: 100, }, purge: ldap_enabled, + google_oauth_client_id: { + required: google_oauth_enabled, + minlength: 1, + maxlength: 255, + }, + google_oauth_client_secret: { + required: google_oauth_enabled, + minlength: 1, + maxlength: 255, + }, + google_oauth_scope: { + required: google_oauth_enabled, + minlength: 1, + maxlength: 255, + }, + google_base_url: { + required: google_oauth_enabled, + minlength: 1, + maxlength: 255, + url: true, + }, + google_oauth_metadata_url: { + required: google_oauth_auto_configure_enabled, + minlength: 1, + maxlength: 255, + url: true, + }, + google_token_url: { + required: google_oauth_auto_configure_disabled, + minlength: 1, + maxlength: 255, + url: true, + }, + google_authorize_url: { + required: google_oauth_auto_configure_disabled, + minlength: 1, + maxlength: 255, + url: true, + }, + github_oauth_key: { + required: github_oauth_enabled, + minlength: 1, + maxlength: 255, + }, + github_oauth_secret: { + required: github_oauth_enabled, + minlength: 1, + maxlength: 255, + }, + github_oauth_scope: { + required: github_oauth_enabled, + minlength: 1, + maxlength: 255, + }, + github_oauth_api_url: { + required: github_oauth_enabled, + minlength: 1, + maxlength: 255, + url: true, + }, + github_oauth_metadata_url: { + required: github_oauth_auto_configure_enabled, + minlength: 1, + maxlength: 255, + url: true, + }, + github_oauth_token_url: { + required: github_oauth_auto_configure_disabled, + minlength: 1, + maxlength: 255, + url: true, + }, + github_oauth_authorize_url: { + required: github_oauth_auto_configure_disabled, + minlength: 1, + maxlength: 255, + url: true, + }, + + }, + messages: { + ldap_sg_enabled: { + ldap_exclusive: 'The LDAP group security feature is mutually exclusive with the LDAP role auto-provisioning feature.', + }, + autoprovisioning: { + ldap_exclusive: 'The LDAP role auto-provisioning feature is mutually exclusive with the LDAP group security feature.', + }, }, - messages: {}, }); } diff --git a/powerdnsadmin/templates/admin_setting_authentication.html b/powerdnsadmin/templates/admin_setting_authentication.html index 2729ed7..7c031db 100644 --- a/powerdnsadmin/templates/admin_setting_authentication.html +++ b/powerdnsadmin/templates/admin_setting_authentication.html @@ -89,7 +89,7 @@
-
+
@@ -280,7 +280,7 @@
-
+
{% if error %} @@ -744,7 +744,7 @@
-
@@ -803,7 +803,7 @@ id="google_oauth_auto_configure" name="google_oauth_auto_configure" class="checkbox" - data-bind="checked: google_oauth_auto_configure"> + data-bind="enable: google_oauth_enabled, checked: google_oauth_auto_configure"> @@ -869,7 +869,7 @@
-
@@ -927,7 +927,7 @@ id="github_oauth_auto_configure" name="github_oauth_auto_configure" class="checkbox" - data-bind="checked: github_oauth_auto_configure"> + data-bind="enable: github_oauth_enabled, checked: github_oauth_auto_configure"> @@ -991,7 +991,7 @@
-
+
@@ -1049,7 +1049,7 @@ id="azure_oauth_auto_configure" name="azure_oauth_auto_configure" class="checkbox" - data-bind="checked: azure_oauth_auto_configure"> + data-bind="enable: azure_oauth_enabled, checked: azure_oauth_auto_configure">
@@ -1293,7 +1293,7 @@
-
+
@@ -1349,7 +1349,7 @@ id="oidc_oauth_auto_configure" name="oidc_oauth_auto_configure" class="checkbox" - data-bind="checked: oidc_oauth_auto_configure"> + data-bind="enable: oidc_oauth_enabled, checked: oidc_oauth_auto_configure">
@@ -1509,8 +1509,8 @@ {% endblock %} {% block head_styles %} - {% endblock %}