Skip to content
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
1 change: 1 addition & 0 deletions app/Config/Schema/schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1425,6 +1425,7 @@
<field name="affiliation" type="C" size="32" />
<field name="value" type="C" size="80" />
<field name="modifiable" type="L" />
<field name="org_identity" type="L" />
<field name="created" type="T" />
<field name="modified" type="T" />
<field name="co_enrollment_attribute_default_id" type="I">
Expand Down
4 changes: 2 additions & 2 deletions app/Controller/CoPetitionsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -469,11 +469,11 @@ function beforeRender() {
}
}
}

$enrollmentAttributes = $this->CoPetition
->CoEnrollmentFlow
->CoEnrollmentAttribute
->mapEnvAttributes($enrollmentAttributes, array());
->mapEnvAttributes($enrollmentAttributes, array(), $this->parseCoPetitionId());
}

$this->set('co_enrollment_attributes', $enrollmentAttributes);
Expand Down
2 changes: 2 additions & 0 deletions app/Lib/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -1134,6 +1134,8 @@
'fd.ed.default' => 'Default Value',
'fd.ed.modify' => 'Modifiable',
'fd.ed.modify.desc' => 'If false, the Petitioner cannot change the default value placed into the Petition',
'fd.ed.default_oi' => 'Take default from OrgIdentitySource',
'fd.ed.default_oi.desc' => 'If checked, try to find a default value on any attached OrgIdentitySource record for this petitioner if no default was found through environment values.',
'fd.ef.aea' => 'Require Authentication For Administrator Enrollment',
'fd.ef.aea.desc' => 'If administrator enrollment is enabled, require enrollees to authenticate to the platform in order to complete their enrollment',
'fd.ef.aee' => 'Require Email Confirmation For Administrator Enrollment',
Expand Down
122 changes: 118 additions & 4 deletions app/Model/CoEnrollmentAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,13 @@ public function enrollmentFlowAttributes($coef, $defaultValues=array(), $archive
}

$attr['modifiable'] = $efAttr['CoEnrollmentAttributeDefault'][0]['modifiable'];
} else {
$attr['modifiable'] = true;
}

$attr['org_identity'] = (isset($efAttr['CoEnrollmentAttributeDefault'][0]['org_identity'])
? $efAttr['CoEnrollmentAttributeDefault'][0]['org_identity']
: false);

// Attach the validation rules so the form knows how to render the field.
if($attrCode == 'o') {
$attr['validate'] = $attrModel->validate[$attrName];
Expand Down Expand Up @@ -698,6 +703,11 @@ public function enrollmentFlowAttributes($coef, $defaultValues=array(), $archive
$attr['select'] = $attrModel->validEnumsForSelect($attrName);
}

// copy org_identity setting
$attr['org_identity'] = (isset($efAttr['CoEnrollmentAttributeDefault'][0]['org_identity'])
? $efAttr['CoEnrollmentAttributeDefault'][0]['org_identity']
: false);

$attrs[] = $attr;
}
}
Expand Down Expand Up @@ -737,6 +747,9 @@ public function enrollmentFlowAttributes($coef, $defaultValues=array(), $archive
? $efAttr['CoEnrollmentAttributeDefault'][0]['modifiable']
: false);
$attr['validate']['content']['rule'][0] = 'inList';
$attr['org_identity'] = (isset($efAttr['CoEnrollmentAttributeDefault'][0]['org_identity'])
? $efAttr['CoEnrollmentAttributeDefault'][0]['org_identity']
: false);

// Pull the set of groups for the select
$args = array();
Expand Down Expand Up @@ -870,10 +883,11 @@ public function findCoForRecord($id) {
* @since COmanage Registry v0.8.2
* @param Array Array of CO enrollment attributes, as returned by enrollmentFlowAttributes()
* @param Array Array of CMP enrollment attributes, as returned by CmpEnrollmentConfiguration::enrollmentAttributesFromEnv()
* @param Integer ID of the current petition
* @return Array Array of CO enrollment attributes
*/

public function mapEnvAttributes($enrollmentAttributes, $envValues) {
public function mapEnvAttributes($enrollmentAttributes, $envValues, $petition_id) {
// First, map the enrollment attributes by model+field, but only for those
// that we might actually populate (ie: org attributes). We partly have to
// do this because CO Enrollment Attributes and CMP Enrollment Attributes
Expand Down Expand Up @@ -940,7 +954,30 @@ public function mapEnvAttributes($enrollmentAttributes, $envValues) {
}
}
}


$org_identities=array();
if(!empty($petition_id)) {

// create a list of OrgIdentities we can use to take defaults from
// get all possible fields for default values as well
// We do not take the EnrolleeOrgIdentity, because that is the destination
// identity we might want to copy values to
$args = array();
$args['conditions']['CoPetition.id'] = intval($petition_id);
$args['contain'] = array(
'OrgIdentitySourceRecord' => array(
'OrgIdentity' => array ('PrimaryName','Address','EmailAddress','Identifier','Name','TelephoneNumber'))
);

$petition = $this->CoEnrollmentFlow->CoPetition->find('first', $args);

if(!empty($petition) && isset($petition['OrgIdentitySourceRecord'])) {
foreach($petition['OrgIdentitySourceRecord'] as $ois) {
$org_identities[]=$ois['OrgIdentity'];
}
}
}

// Check for default values from env variables.

for($i = 0;$i < count($enrollmentAttributes);$i++) {
Expand Down Expand Up @@ -968,11 +1005,88 @@ public function mapEnvAttributes($enrollmentAttributes, $envValues) {
// In the new style, these are defaults, not canonical values
$enrollmentAttributes[$i]['modifiable'] = true;
}

if( empty($enrollmentAttributes[$i]['default']) && $enrollmentAttributes[$i]['org_identity']) {
CakeLog::write('debug','getting org identity default');
// if we have an OrgIdentity attached to this EF, try to pick a default from that
// This solves the use case where we have an OIS plugin in authenticate mode that
// reads a source for us and allows us to prepopulate the petitioner attributes
//
// We match in two loops: one for a very specific match (home address => home address only)
// and one for a loose match (email address => any email address)

foreach($org_identities as $oi) {
$enrollmentAttributes[$i]['default'] = $this->mapOrgIdentityToDefault($enrollmentAttributes[$i], $oi, true);
if(!empty($enrollmentAttributes[$i]['default'])) {
break;
}
}

if(empty($enrollmentAttributes[$i]['default'])) {
foreach($org_identities as $oi) {
$enrollmentAttributes[$i]['default'] = $this->mapOrgIdentityToDefault($enrollmentAttributes[$i], $oi, false);
if(!empty($enrollmentAttributes[$i]['default'])) {
break;
}
}
}
}
}

return $enrollmentAttributes;
}


/**
* Try to match an enrollment attribute to a field on one of the attached OrgIdentities
*
* @since COmanage Registry vTODO
* @param Array ea enrollment attribute definition
* @param Array oi OrgIdentity object
* @param Bool strict_match if true, only match exact address/emailaddress/name types
* @return String default value, empty if none found
*/
private function mapOrgIdentityToDefault($ea, $oi, $strict_match) {
$retval = "";

$a = explode(':', $ea['attribute'], 4);

// See availableAttributes() for the various codes
$attrCode = array_shift($a);

// attribute name (as per availableAttributes)
$attrName = array_shift($a);
$attrModelName = Inflector::camelize($attrName);

// optional constraining type, for multi-valued attributes
$attrType = array_shift($a);

switch($attrCode) {
case 'r': // CoPersonRole related fields
case 'o': // OrgIdentity related fields
if(!empty($oi[$attrName])) {
$retval = $oi[$attrName];
}
break;
case 'p': // CoPerson related fields
case 'm': // multi-valued CoPersonRole related fields
case 'i': // multi-valued OrgIdentity related fields
if(isset($oi[$attrModelName])) {
$field = $ea['field'];
foreach($oi[$attrModelName] as $data) {
// if it is set and of the same type, or we do not check types
if(isset($data[$field]) && (!$strict_match || $data["type"]==$attrType)) {
$retval = $data[$field];
}
}
}
break;
default:
break;
}

return $retval;
}

/**
* Check if a given extended type is in use by any Enrollment Attribute.
*
Expand Down
13 changes: 13 additions & 0 deletions app/View/CoEnrollmentAttributes/fields.inc
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,19 @@
? _txt('fd.yes') : _txt('fd.no'))); ?>
</td>
</tr>
<tr class="line<?php print ($l % 2); $l++; ?>">
<td>
<b><?php print _txt('fd.ed.default_oi'); ?></b><br />
<span class="descr"><?php print _txt('fd.ed.default_oi.desc'); ?></span>
</td>
<td>
<?php print ($e
? $this->Form->input('CoEnrollmentAttributeDefault.0.org_identity',
array('default' => true))
: ($co_enrollment_attributes[0]['CoEnrollmentAttributeDefault'][0]['org_identity']
? _txt('fd.yes') : _txt('fd.no'))); ?>
</td>
</tr>
</tbody>
<tfoot>
<tr>
Expand Down