diff --git a/app/Config/Schema/schema.xml b/app/Config/Schema/schema.xml
index 94deb54f2..aa9485d81 100644
--- a/app/Config/Schema/schema.xml
+++ b/app/Config/Schema/schema.xml
@@ -1425,6 +1425,7 @@
+
diff --git a/app/Controller/CoPetitionsController.php b/app/Controller/CoPetitionsController.php
index 00bb16be6..8503ffc55 100644
--- a/app/Controller/CoPetitionsController.php
+++ b/app/Controller/CoPetitionsController.php
@@ -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);
diff --git a/app/Lib/lang.php b/app/Lib/lang.php
index 2b871abd4..b77e2c1bf 100644
--- a/app/Lib/lang.php
+++ b/app/Lib/lang.php
@@ -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',
diff --git a/app/Model/CoEnrollmentAttribute.php b/app/Model/CoEnrollmentAttribute.php
index fb2024b2e..a88ffb389 100644
--- a/app/Model/CoEnrollmentAttribute.php
+++ b/app/Model/CoEnrollmentAttribute.php
@@ -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];
@@ -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;
}
}
@@ -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();
@@ -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
@@ -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++) {
@@ -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.
*
diff --git a/app/View/CoEnrollmentAttributes/fields.inc b/app/View/CoEnrollmentAttributes/fields.inc
index 9f1d0b258..39e006137 100644
--- a/app/View/CoEnrollmentAttributes/fields.inc
+++ b/app/View/CoEnrollmentAttributes/fields.inc
@@ -647,6 +647,19 @@
? _txt('fd.yes') : _txt('fd.no'))); ?>
+