From a3212c135705ec22ec171f545f20d6956af80e08 Mon Sep 17 00:00:00 2001 From: Scott Koranda Date: Tue, 15 Jun 2021 16:08:47 -0500 Subject: [PATCH] Add logic to populate username in form with default from environment Add logic to populate the username (usually WordPress ID or wpid) in the form with the value from environment variable if the wedge is so configured. --- Config/Schema/schema.xml | 1 + ...HumanitiesCommonsIdpEnrollerCoPetitionsController.php | 5 +++++ Lib/lang.php | 2 ++ Model/HumanitiesCommonsIdpEnroller.php | 7 ++++++- .../check_eligibility.ctp | 6 +++--- View/HumanitiesCommonsIdpEnrollers/fields.inc | 9 +++++++++ 6 files changed, 26 insertions(+), 4 deletions(-) diff --git a/Config/Schema/schema.xml b/Config/Schema/schema.xml index 83e8ea3..8fa8799 100644 --- a/Config/Schema/schema.xml +++ b/Config/Schema/schema.xml @@ -40,6 +40,7 @@ + diff --git a/Controller/HumanitiesCommonsIdpEnrollerCoPetitionsController.php b/Controller/HumanitiesCommonsIdpEnrollerCoPetitionsController.php index f8cf44f..4f3e4a8 100644 --- a/Controller/HumanitiesCommonsIdpEnrollerCoPetitionsController.php +++ b/Controller/HumanitiesCommonsIdpEnrollerCoPetitionsController.php @@ -223,7 +223,12 @@ protected function execute_plugin_checkEligibility($id, $onFinish) { // GET, fall through to display view ( $debug ? $this->log($logPrefix . "received GET so displaying form to collect username") : null); + $this->set('vv_efwid', $efwid); + + if(!empty($config['HumanitiesCommonsIdpEnroller']['username_env_variable'])) { + $this->set('vv_suggested_username', getenv($config['HumanitiesCommonsIdpEnroller']['username_env_variable'])); + } } /** diff --git a/Lib/lang.php b/Lib/lang.php index 2a187b7..28bbe1d 100644 --- a/Lib/lang.php +++ b/Lib/lang.php @@ -56,6 +56,8 @@ 'pl.humanitiescommonsidpenroller.config.ldap_basedn.desc' => 'Base DN to provision accounts under', 'pl.humanitiescommonsidpenroller.config.hc_idp_scope' => 'Humanities Commons IdP Scope', 'pl.humanitiescommonsidpenroller.config.hc_idp_scope.desc' => 'Scope asserted by the Humanities Commons IdP (hcommons.org)', + 'pl.humanitiescommonsidpenroller.config.username_env_variable' => 'Username Environment Variable Default', + 'pl.humanitiescommonsidpenroller.config.username_env_variable.desc' => 'Environment variable used to set username default in form', 'pl.humanitiescommonsidpenroller.config.debug' => 'Debug', 'pl.humanitiescommonsidpenroller.config.debug.desc' => 'Toggle for debug mode', 'pl.humanitiescommonsidpenroller.config.menu' => 'HC IdP Enroller Configuration', diff --git a/Model/HumanitiesCommonsIdpEnroller.php b/Model/HumanitiesCommonsIdpEnroller.php index 516566d..49bd4dd 100644 --- a/Model/HumanitiesCommonsIdpEnroller.php +++ b/Model/HumanitiesCommonsIdpEnroller.php @@ -74,7 +74,12 @@ class HumanitiesCommonsIdpEnroller extends AppModel { 'rule' => 'notBlank', 'required' => true, 'allowEmpty' => false - ) + ), + 'username_env_variable' => array( + 'rule' => array('validateInput'), + 'required' => false, + 'allowEmpty' => true + ), ); /** diff --git a/View/HumanitiesCommonsIdpEnrollerCoPetitions/check_eligibility.ctp b/View/HumanitiesCommonsIdpEnrollerCoPetitions/check_eligibility.ctp index c9e1527..cac4833 100644 --- a/View/HumanitiesCommonsIdpEnrollerCoPetitions/check_eligibility.ctp +++ b/View/HumanitiesCommonsIdpEnrollerCoPetitions/check_eligibility.ctp @@ -84,9 +84,9 @@ $args['type'] = 'text'; $args['label'] = false; $args['required'] = 'required'; - if( $current_enrollment_flow_cou == 'MSU' ) { - $args['value'] = getenv('netid'); - } + if(!empty($vv_suggested_username)) { + $args['value'] = $vv_suggested_username; + } print $this->Form->input('username', $args); ?> diff --git a/View/HumanitiesCommonsIdpEnrollers/fields.inc b/View/HumanitiesCommonsIdpEnrollers/fields.inc index b9242a7..d5cc76d 100644 --- a/View/HumanitiesCommonsIdpEnrollers/fields.inc +++ b/View/HumanitiesCommonsIdpEnrollers/fields.inc @@ -94,6 +94,15 @@ Form->input('hc_idp_scope', array('size' => 50)) : Sanitize::html($humanities_commons_idp_enrollers[0]['HumanitiesCommonsIdpEnroller']['hc_idp_scope'])); ?> + + +
+ + + + Form->input('username_env_variable', array('size' => 50)) : Sanitize::html($humanities_commons_idp_enrollers[0]['HumanitiesCommonsIdpEnroller']['username_env_variable'])); ?> + + *