Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RCIAM-307_Non_environmental_default_values_are_not_honored_during_Enrollment #63

Open
wants to merge 1 commit into
base: rciam-3.1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 28 additions & 16 deletions app/Model/CoEnrollmentAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ public function enrollmentFlowAttributes($coef, $defaultValues=array(), $archive
$attr['attribute'] = $efAttr['CoEnrollmentAttribute']['attribute'];

// Track if the mvpa itself is required
$attr['mvpa_required'] = $efAttr['CoEnrollmentAttribute']['required'];
$attr['mvpa_required'] = (bool)$efAttr['CoEnrollmentAttribute']['required'];

// For certain MVPAs, check if this field is even permitted (currently only names)
// XXX this is kind of clunky -- rewrite if this expands to more attributes
Expand Down Expand Up @@ -628,12 +628,12 @@ public function enrollmentFlowAttributes($coef, $defaultValues=array(), $archive
&& $efAttr['CoEnrollmentAttribute']['ignore_authoritative']);

// We hide language, primary_name, type, status, and verified
$attr['hidden'] = ($k == 'language'
|| $k == 'login'
|| $k == 'primary_name'
|| $k == 'type'
|| $k == 'status'
|| $k == 'verified' ? 1 : 0);
$attr['hidden'] = ($k === 'language'
|| $k === 'login'
|| $k === 'primary_name'
|| $k === 'type'
|| $k === 'status'
|| $k === 'verified' ? true : false);

if($attr['hidden']) {
// Populate a default value.
Expand Down Expand Up @@ -769,7 +769,7 @@ public function enrollmentFlowAttributes($coef, $defaultValues=array(), $archive
$optin = (!empty($attr['default'])
&& !$attr['modifiable']
&& !$attr['hidden']
&& $attr['required'] == RequiredEnum::Optional);
&& $attr['required'] === RequiredEnum::Optional);

// Inject hidden attributes to specify membership

Expand Down Expand Up @@ -893,7 +893,7 @@ public function mapEnvAttributes($enrollmentAttributes, $envValues) {
if(!empty($envValues)) {
$eaMap = array();

for($i = 0;$i < count($enrollmentAttributes);$i++) {
for($i = 0, $iMax = count($enrollmentAttributes); $i < $iMax; $i++) {
$model = explode('.', $enrollmentAttributes[$i]['model'], 2);

// Only track org identity attributes
Expand Down Expand Up @@ -945,15 +945,16 @@ public function mapEnvAttributes($enrollmentAttributes, $envValues) {

// Make sure the modifiable value is set. If a value was found, we will
// make it not-modifiable.

$enrollmentAttributes[$i]['modifiable'] = !(boolean)$enrollmentAttributes[$i]['default'];

$enrollmentAttributes[$i]['modifiable'] = $enrollmentAttributes[$i]['modifiable'] ||
(empty($enrollmentAttributes[$i]['default']) && (bool)$enrollmentAttributes[$i]['required']);
}
}
}

// Check for default values from env variables.

for($i = 0;$i < count($enrollmentAttributes);$i++) {
for($i = 0, $iMax = count($enrollmentAttributes); $i < $iMax; $i++) {
// Skip anything that's hidden. This will prevent us from setting a
// default value for metadata attributes, and will also prevent using
// default values in hidden attributes (which is probably a feature, not
Expand All @@ -972,11 +973,22 @@ public function mapEnvAttributes($enrollmentAttributes, $envValues) {
} else {
$envVar = $enrollmentAttributes[$i]['CoEnrollmentAttribute']['default_env'];
}

$enrollmentAttributes[$i]['default'] = getenv($envVar);

// The default value is either the default envVar or the default hardcoded value if the envVar is not present
// in the session. For example community Identity Providers might not provide affiliation attributes.
$enrollmentAttributes[$i]['default'] = !empty(getenv($envVar)) ? getenv($envVar)
: ( !empty($enrollmentAttributes[$i]['default']) ? $enrollmentAttributes[$i]['default'] : '');

$enrollmentAttributes[$i]['modifiable'] = (!isset($enrollmentAttributes[$i]['modifiable'])) ? true :
$enrollmentAttributes[$i]['modifiable'];
// XXX Should we define default value for each env_var in case of complex attributes, e.g. given name
// We use allowEmpty to check, which is more accurate than $validate->required.
// Required is true if the attribute is required by the enrollment flow configuration,
// AND if the MVPA's element is also required/allowEmpty (eg: Email requires mail to be set).
// In the new style, these are defaults, not canonical values
$enrollmentAttributes[$i]['modifiable'] = true;
if( empty($enrollmentAttributes[$i]['default'])
&& $enrollmentAttributes[$i]['required']) {
$enrollmentAttributes[$i]['modifiable'] = true;
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion app/View/CoPetitions/petition-attributes.inc
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@
if($ea['hidden']) {
$fieldName = $ea['model'] . '.' . $ea['field'];
}

if(!isset($ea['default'])) {
$ea['default'] = '';
}
print $this->Form->hidden($fieldName, array('default' => $ea['default'])) . "\n";
}

Expand Down