From 8a4a90e15c4d1ad29319e320240fdf3244cfd688 Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Fri, 5 Jan 2024 14:57:56 +0200 Subject: [PATCH] correctly recalculate multivalue email attributes for both visible and hidden form fields --- app/View/CoPetitions/petition-attributes.inc | 31 +++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/app/View/CoPetitions/petition-attributes.inc b/app/View/CoPetitions/petition-attributes.inc index 2da0cddbf..c25722c17 100644 --- a/app/View/CoPetitions/petition-attributes.inc +++ b/app/View/CoPetitions/petition-attributes.inc @@ -177,6 +177,8 @@ } } + $co_person_id = $co_person_id ?? $userInfo['co_person_id'] ?? null; + // Sort attributes by model for printing $coea_model = array(); $misc_attr = array(); @@ -345,8 +347,28 @@ $hfieldName = $ea['model'] . '.' . $ea['field']; $fieldName = $hfieldName . "-disabled"; + $default_val = null; + + if(strpos($hfieldName, 'EnrolleeCoPerson.EmailAddress') !== false + || strpos($hfieldName, 'EnrolleeOrgIdentity.EmailAddress') !== false) { + $email_list = $ea['default']; + if(!empty($email_list) && !empty($vv_envsource_delimiter)) { + $delimiter = ""; + if($vv_envsource_delimiter == AuthProviderEnum::Shibboleth) { + $delimiter = ";"; + } elseif($vv_envsource_delimiter == AuthProviderEnum::Simplesamlphp) { + $delimiter =","; + } + + $emails = explode($delimiter, $email_list); + if(is_array($emails) && count($emails) > 1) { + // XXX We are only keeping the first email + $default_val = $emails[0]; + } + } + } - print $this->Form->hidden($hfieldName, array('default' => $ea['default'])) . PHP_EOL; + print $this->Form->hidden($hfieldName, array('default' => ($default_val ?? $ea['default']) )) . PHP_EOL; } // XXX need to retrieve current values for edit and view @@ -566,7 +588,7 @@ array( // We don't support two sponsors, but if we did this id would break 'id' => 'EnrolleeCoPersonRoleSponsorCoPersonId', - 'default' => (isset($ea['default']) ? $ea['default'] : null) + 'default' => ($ea['default'] ?? null) )) . '
@@ -630,7 +652,7 @@ array( // We don't support two managers, but if we did this id would break 'id' => 'EnrolleeCoPersonRoleManagerCoPersonId', - 'default' => (isset($ea['default']) ? $ea['default'] : null) + 'default' => ($ea['default'] ?? null) )) . '
@@ -650,7 +672,8 @@ $args['value'] = generateCn($vv_default_sponsor['PrimaryName']); } elseif($fieldName == 'EnrolleeCoPersonRole.manager_co_person_id-disabled') { $args['value'] = generateCn($vv_default_manager['PrimaryName']); - } elseif(strpos($fieldName, 'EnrolleeCoPerson.EmailAddress') !== false) { + } elseif(strpos($fieldName, 'EnrolleeCoPerson.EmailAddress') !== false + || strpos($fieldName, 'EnrolleeOrgIdentity.EmailAddress') !== false) { $email_list = $args['default']; if(!empty($email_list) && !empty($vv_envsource_delimiter)) { $delimiter = "";