diff --git a/app/Controller/CoEnrollmentAttributesController.php b/app/Controller/CoEnrollmentAttributesController.php index 31b51c047..311b8a122 100644 --- a/app/Controller/CoEnrollmentAttributesController.php +++ b/app/Controller/CoEnrollmentAttributesController.php @@ -279,93 +279,7 @@ protected function calculateImpliedCoId($data = null) { // Or try the default behavior return parent::calculateImpliedCoId(); } - - /** - * Perform any followups following a write operation. Note that if this - * method fails, it must return a warning or REST response, but that the - * overall transaction is still considered a success (add/edit is not - * rolled back). - * - * @since COmanage Registry v0.8.1 - * @param Array Request data - * @param Array Current data - * @param Array Original request data (unmodified by callbacks) - * @return boolean true if dependency checks succeed, false otherwise. - */ - - function checkWriteFollowups($reqdata, $curdata = null, $origdata = null) { - // Perform a quick check to see if the attribute can no longer have a default attribute. - // Currently, only types 'g', 'o', 'r', and 'x' can. - - if(!empty($curdata['CoEnrollmentAttributeDefault'][0]['id'])) { - // There is an existing default - - $attrinfo = explode(':', $reqdata['CoEnrollmentAttribute']['attribute']); - - // This list is also in clearUnassociatedRequestData() - if($attrinfo[0] != 'g' && $attrinfo[0] != 'o' && $attrinfo[0] != 'r' && $attrinfo[0] != 'x') { - // Ignore return code - $this->CoEnrollmentAttribute->CoEnrollmentAttributeDefault->delete($curdata['CoEnrollmentAttributeDefault'][0]['id'], - false); - } - } - - return true; - } - - /** - * Clear unnecessary data from a form submission. - * - postcondition: $this->request->data updated - * - * @since COmanage Registry v2.0.0 - */ - - protected function clearUnassociatedRequestData() { - // Because of the mechanics of how the the form is set up, we may - // get potentially unrelated data (values used for form rendering), - // AttributeDefaults even when the object doesn't support attribute - // defaults, etc. We clear out unrelated objects to avoid problems - // with checkWriteFollowups trying to delete already deleted (ie: empty) - // records. - - // It's easier to rebuild than to remove keys we don't want - $requestData = array(); - - // Always copy the core attribute - $requestData['CoEnrollmentAttribute'] = $this->request->data['CoEnrollmentAttribute']; - - // If the attribute is of the right type, copy the attribute default - $attrinfo = explode(':', $this->request->data['CoEnrollmentAttribute']['attribute']); - - // This list is also in checkWriteFollowups? - if($attrinfo[0] == 'g' || $attrinfo[0] == 'o' || $attrinfo[0] == 'r' || $attrinfo[0] == 'x') { - $requestData['CoEnrollmentAttributeDefault'] = $this->request->data['CoEnrollmentAttributeDefault']; - } - - $this->request->data = $requestData; - } - - /** - * Update an Enrollment Attribute. - * - precondition: Model specific attributes in $this->request->data (optional) - * - precondition: must exist - * - postcondition: On GET, $s set (HTML) - * - postcondition: On POST success, object updated - * - postcondition: On POST, session flash message updated (HTML) or HTTP status returned (REST) - * - postcondition: On POST error, $invalid_fields set (REST) - * - * @since COmanage Registry v2.0.0 - * @param integer Object identifier (eg: cm_co_groups:id) representing object to be retrieved - */ - - function edit($id) { - if(!empty($this->request->data)) { - $this->clearUnassociatedRequestData(); - } - - parent::edit($id); - } - + /** * Authorization for this Controller, called by Auth component * - precondition: Session.Auth holds data used for authz decisions diff --git a/app/Model/CoEnrollmentAttribute.php b/app/Model/CoEnrollmentAttribute.php index fb2024b2e..10f4b4363 100644 --- a/app/Model/CoEnrollmentAttribute.php +++ b/app/Model/CoEnrollmentAttribute.php @@ -350,13 +350,8 @@ public function enrollmentFlowAttributes($coef, $defaultValues=array(), $archive // Description $attr['description'] = $efAttr['CoEnrollmentAttribute']['description']; - // Single value attributes are never hidden, unless there is a non-modifable - // default value - $attr['hidden'] = - (isset($efAttr['CoEnrollmentAttribute']['hidden']) - && $efAttr['CoEnrollmentAttribute']['hidden'] - && isset($efAttr['CoEnrollmentAttributeDefault'][0]['modifiable']) - && !$efAttr['CoEnrollmentAttributeDefault'][0]['modifiable']); + // If configured as hidden, hide it + $attr['hidden'] = (isset($efAttr['CoEnrollmentAttribute']['hidden']) && $efAttr['CoEnrollmentAttribute']['hidden']); // Org attributes can ignore authoritative values $attr['ignore_authoritative'] = @@ -382,10 +377,8 @@ public function enrollmentFlowAttributes($coef, $defaultValues=array(), $archive if(isset($defaultValues[ $attr['model'] ][ $attr['field'] ])) { // These are default values created by the Controller, eg for prepopulating Name. - // Currently, they are always modifiable. $attr['default'] = $defaultValues[ $attr['model'] ][ $attr['field'] ]; - $attr['modifiable'] = true; - } elseif(!empty($efAttr['CoEnrollmentAttributeDefault'][0]['value'])) { + } else if(!empty($efAttr['CoEnrollmentAttributeDefault'][0]['value'])) { // These are the default values configured per-enrollment flow attribute if(($attrCode == 'r' @@ -425,10 +418,11 @@ public function enrollmentFlowAttributes($coef, $defaultValues=array(), $archive } else { $attr['default'] = $efAttr['CoEnrollmentAttributeDefault'][0]['value']; } - - $attr['modifiable'] = $efAttr['CoEnrollmentAttributeDefault'][0]['modifiable']; } - + $attr['modifiable'] = (isset($efAttr['CoEnrollmentAttributeDefault'][0]['modifiable']) + ? $efAttr['CoEnrollmentAttributeDefault'][0]['modifiable'] + : true); + // Attach the validation rules so the form knows how to render the field. if($attrCode == 'o') { $attr['validate'] = $attrModel->validate[$attrName]; @@ -554,7 +548,6 @@ public function enrollmentFlowAttributes($coef, $defaultValues=array(), $archive $attr['field'] = "co_enrollment_attribute_id"; $attrs[] = $attr; - // Loop through the fields in the model. foreach(array_keys($attrModel->validate) as $k) { @@ -617,14 +610,16 @@ public function enrollmentFlowAttributes($coef, $defaultValues=array(), $archive && isset($efAttr['CoEnrollmentAttribute']['ignore_authoritative']) && $efAttr['CoEnrollmentAttribute']['ignore_authoritative']); + // if configured hidden, hide it + $attr['hidden'] = (isset($efAttr['CoEnrollmentAttribute']['hidden']) && $efAttr['CoEnrollmentAttribute']['hidden']); + // 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); - + || $k == 'verified' ? true : $attr['hidden']); if($attr['hidden']) { // Populate a default value. @@ -661,6 +656,8 @@ public function enrollmentFlowAttributes($coef, $defaultValues=array(), $archive // Verified defaults to false $attr['default'] = 0; break; + default: + $attr['default'] = isset($efAttr['CoEnrollmentAttributeDefault'][0]['value']) ? $efAttr['CoEnrollmentAttributeDefault'][0]['value'] : null; } } else { // Label @@ -697,7 +694,12 @@ public function enrollmentFlowAttributes($coef, $defaultValues=array(), $archive // If this is a select field, get the set of options $attr['select'] = $attrModel->validEnumsForSelect($attrName); } - + + // copy modifiable settings + $attr['modifiable'] = (isset($efAttr['CoEnrollmentAttributeDefault'][0]['modifiable']) + ? $efAttr['CoEnrollmentAttributeDefault'][0]['modifiable'] + : true); + $attrs[] = $attr; } } @@ -735,7 +737,7 @@ public function enrollmentFlowAttributes($coef, $defaultValues=array(), $archive } $attr['modifiable'] = (isset($efAttr['CoEnrollmentAttributeDefault'][0]['modifiable']) ? $efAttr['CoEnrollmentAttributeDefault'][0]['modifiable'] - : false); + : true); $attr['validate']['content']['rule'][0] = 'inList'; // Pull the set of groups for the select @@ -940,19 +942,11 @@ public function mapEnvAttributes($enrollmentAttributes, $envValues) { } } } - + // Check for default values from env variables. - + for($i = 0;$i < count($enrollmentAttributes);$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 - // a bug). - - if($enrollmentAttributes[$i]['hidden']) { - continue; - } - + if(!empty($enrollmentAttributes[$i]['CoEnrollmentAttribute']['default_env'])) { if(strstr($enrollmentAttributes[$i]['attribute'], ':name:')) { // Handle name specially @@ -964,15 +958,12 @@ public function mapEnvAttributes($enrollmentAttributes, $envValues) { } $enrollmentAttributes[$i]['default'] = getenv($envVar); - - // In the new style, these are defaults, not canonical values - $enrollmentAttributes[$i]['modifiable'] = true; } + } - return $enrollmentAttributes; } - + /** * Check if a given extended type is in use by any Enrollment Attribute. * diff --git a/app/Model/CoPetition.php b/app/Model/CoPetition.php index 0970e7a9f..f35c9fd24 100644 --- a/app/Model/CoPetition.php +++ b/app/Model/CoPetition.php @@ -303,7 +303,7 @@ public function attributeOptionalAndEmpty($efAttrID, $data, $efAttrs) { continue; } - if($efAttr['hidden'] && !$efAttr['default']) { + if($efAttr['hidden'] && empty($efAttr['default'])) { // Skip hidden fields because they aren't user-editable, unless they are default attributes continue; } diff --git a/app/View/CoEnrollmentAttributes/fields.inc b/app/View/CoEnrollmentAttributes/fields.inc index 9f1d0b258..11de6a40f 100644 --- a/app/View/CoEnrollmentAttributes/fields.inc +++ b/app/View/CoEnrollmentAttributes/fields.inc @@ -86,91 +86,82 @@ } function toggle_attr_def_div() { - // For now, only CO Person Role attributes (type 'r'), Organizational Identity - // attributes (type 'o'), or Extended Attributes (type 'x') can have default values. - var curattr = document.getElementById('CoEnrollmentAttributeAttribute').value; var attrtype = curattr[0]; - if(attrtype == "r" || attrtype == "o" || attrtype == "x" || attrtype == "g") { - $("#attr_def_div").show("fade", { "direction" : "up" }); - - // Adjust the gadgets shown + // Adjust the gadgets shown - $("#attr_def_val_div").hide(); - $("#attr_def_val_affil_div").hide(); - $("#attr_def_val_cou_div").hide(); - $("#attr_def_val_date_div").hide(); - $("#attr_def_val_enum_div").hide(); - $("#attr_def_val_group_div").hide(); - $("#attr_def_val_sponsor_div").hide(); + $("#attr_def_val_div").hide(); + $("#attr_def_val_affil_div").hide(); + $("#attr_def_val_cou_div").hide(); + $("#attr_def_val_date_div").hide(); + $("#attr_def_val_enum_div").hide(); + $("#attr_def_val_group_div").hide(); + $("#attr_def_val_sponsor_div").hide(); - var curval = document.getElementById('CoEnrollmentAttributeDefault0Value').value; + var curval = document.getElementById('CoEnrollmentAttributeDefault0Value').value; - var curattrarr = curattr.split(":"); - var curattrcode = curattrarr[0]; - var curattrname = curattrarr[1]; + var curattrarr = curattr.split(":"); + var curattrcode = curattrarr[0]; + var curattrname = curattrarr[1]; - // if x:foo then pull foo and lookup in $vv_ext_attr_types to find type - // (write javascript array based on $vv_ext contents?) + // if x:foo then pull foo and lookup in $vv_ext_attr_types to find type + // (write javascript array based on $vv_ext contents?) - var enums = enum_for_attr(curattr); + var enums = enum_for_attr(curattr); - if(enums != undefined) { - // Enumerations are defined for the attribute, so generate an appropriate select - var options = ""; - for(var i=0;i < enums.length;i++) { - options += ""; - } - $("#def_enum_val").find('option').remove().end().append($(options)); - - document.getElementById('def_enum_val').value = curval; - $("#attr_def_val_enum_div").show("fade"); - } else if((curattrcode == "o" || curattrcode == "r") - && curattrname == "affiliation") { - // Set current value before showing - document.getElementById('def_affil_val').value = curval; - $("#attr_def_val_affil_div").show("fade"); - } else if(curattrcode == "r" && curattrname == "cou_id") { - // Set current value before showing - document.getElementById('def_cou_val').value = curval; - $("#attr_def_val_cou_div").show("fade"); - } else if(curattrcode == "r" && curattrname == "sponsor_co_person_id") { - // Set current value before showing - document.getElementById('def_sponsor_val').value = curval; - $("#attr_def_val_sponsor_div").show("fade"); - } else if((curattrcode == "r" - && (curattrname == "valid_from" || curattrname == "valid_through")) - || - (curattrcode == "x" - && ext_attr_type(curattrname) == "")) { - // Set current value before showing - var fixedre = /^[0-9]{4}\-[0-2][0-9]\-[0-9]{2}$/; // YYYY-MM-DD - var nextre = /^[0-2][0-9]\-[0-9]{2}$/; // MM-DD - var offsetre = /^\+[0-9]+$/; // +DD + if(enums != undefined) { + // Enumerations are defined for the attribute, so generate an appropriate select + var options = ""; + for(var i=0;i < enums.length;i++) { + options += ""; + } + $("#def_enum_val").find('option').remove().end().append($(options)); - if(fixedre.test(curval)) { - document.getElementById('def_date_val_fixed').value = curval; - set_attr_def_date_radio('fixed'); - } else if(nextre.test(curval)) { - document.getElementById('def_date_val_next').value = curval; - set_attr_def_date_radio('next'); - } else if(offsetre.test(curval)) { - // Trim the leading plus (it will get added back to curval by set_attr_def_date_radio) - document.getElementById('def_date_val_offset').value = curval.replace("+", ""); - set_attr_def_date_radio('offset'); - } + document.getElementById('def_enum_val').value = curval; + $("#attr_def_val_enum_div").show("fade"); + } else if((curattrcode == "o" || curattrcode == "r") + && curattrname == "affiliation") { + // Set current value before showing + document.getElementById('def_affil_val').value = curval; + $("#attr_def_val_affil_div").show("fade"); + } else if(curattrcode == "r" && curattrname == "cou_id") { + // Set current value before showing + document.getElementById('def_cou_val').value = curval; + $("#attr_def_val_cou_div").show("fade"); + } else if(curattrcode == "r" && curattrname == "sponsor_co_person_id") { + // Set current value before showing + document.getElementById('def_sponsor_val').value = curval; + $("#attr_def_val_sponsor_div").show("fade"); + } else if((curattrcode == "r" + && (curattrname == "valid_from" || curattrname == "valid_through")) + || + (curattrcode == "x" + && ext_attr_type(curattrname) == "")) { + // Set current value before showing + var fixedre = /^[0-9]{4}\-[0-2][0-9]\-[0-9]{2}$/; // YYYY-MM-DD + var nextre = /^[0-2][0-9]\-[0-9]{2}$/; // MM-DD + var offsetre = /^\+[0-9]+$/; // +DD - $("#attr_def_val_date_div").show("fade"); - } else if(curattrcode == "g") { - // Set current value before showing - document.getElementById('def_group_val').value = curval; - $("#attr_def_val_group_div").show("fade"); - } else { - $("#attr_def_val_div").show(); + if(fixedre.test(curval)) { + document.getElementById('def_date_val_fixed').value = curval; + set_attr_def_date_radio('fixed'); + } else if(nextre.test(curval)) { + document.getElementById('def_date_val_next').value = curval; + set_attr_def_date_radio('next'); + } else if(offsetre.test(curval)) { + // Trim the leading plus (it will get added back to curval by set_attr_def_date_radio) + document.getElementById('def_date_val_offset').value = curval.replace("+", ""); + set_attr_def_date_radio('offset'); } + + $("#attr_def_val_date_div").show("fade"); + } else if(curattrcode == "g") { + // Set current value before showing + document.getElementById('def_group_val').value = curval; + $("#attr_def_val_group_div").show("fade"); } else { - $("#attr_def_div").hide("fade", { "direction" : "up" }); + $("#attr_def_val_div").show(); } } @@ -494,7 +485,7 @@ - +
diff --git a/app/View/CoPetitions/petition-attributes.inc b/app/View/CoPetitions/petition-attributes.inc index c942bccb3..49ce448cc 100644 --- a/app/View/CoPetitions/petition-attributes.inc +++ b/app/View/CoPetitions/petition-attributes.inc @@ -177,7 +177,7 @@ $fieldName = $ea['model'] . '.' . $ea['field']; } - print $this->Form->hidden($fieldName, array('default' => $ea['default'])) . "\n"; + print $this->Form->hidden($fieldName, array('default' => isset($ea['default'])? $ea['default']:'')) . "\n"; } // Print the ones not hidden