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
88 changes: 1 addition & 87 deletions app/Controller/CoEnrollmentAttributesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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: <id> must exist
* - postcondition: On GET, $<object>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
Expand Down
59 changes: 25 additions & 34 deletions app/Model/CoEnrollmentAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] =
Expand All @@ -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'
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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.
*
Expand Down
2 changes: 1 addition & 1 deletion app/Model/CoPetition.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading