Skip to content

Commit

Permalink
conditional enable/disable modifiable status of Enrollment attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
ioigoume committed Sep 7, 2020
1 parent f8fff10 commit 24ddb56
Showing 1 changed file with 27 additions and 16 deletions.
43 changes: 27 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,15 @@ 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'] = empty($enrollmentAttributes[$i]['default']) && $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 +972,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

0 comments on commit 24ddb56

Please sign in to comment.