Skip to content

Commit

Permalink
Do not normalize(mixCase) attributes synced to CoPersonRole from OIS
Browse files Browse the repository at this point in the history
  • Loading branch information
ioigoume committed Nov 13, 2021
1 parent 770aeb4 commit 7aab4fa
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 11 deletions.
13 changes: 9 additions & 4 deletions app/Model/AppModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -1541,22 +1541,27 @@ public function validateEnumeration($coId, $attribute, $value) {
* @param integer $coId CO ID
* @param string $attribute Attribute, in Model.attribute form
* @param string $value Value to normalize
* @param array $options Save options
* @return string The normalized value
*/

public function normalizeEnumeration($coId, $attribute, $value) {
public function normalizeEnumeration($coId, $attribute, $value, $options = array()) {
// First, see if there is an enumeration defined for $coId + $attribute.

$args = array();
$args['joins'][0]['table'] = 'dictionaries';
$args['joins'][0]['alias'] = 'Dictionary';
$args['joins'][0]['type'] = 'INNER';
$args['joins'][0]['conditions'][0] = 'AttributeEnumeration.dictionary_id=Dictionary.id';
$args['conditions']['AttributeEnumeration.co_id'] = $coId;
$args['conditions']['AttributeEnumeration.attribute'] = $attribute;
$args['conditions']['AttributeEnumeration.status'] = SuspendableStatusEnum::Active;
$args['contain'] = false;

$AttributeEnumeration = ClassRegistry::init('AttributeEnumeration');
$attrEnum = $AttributeEnumeration->find('first', $args);
$has_dictionary = (boolean)$AttributeEnumeration->find('count', $args);

if(empty($attrEnum['AttributeEnumeration']['dictionary_id'])) {
if(!$has_dictionary) {
// If there is no dictionary attached to the Attribute Enumeration
// configuration then load the normalizer
$this->Behaviors->load('Normalization');
Expand All @@ -1566,7 +1571,7 @@ public function normalizeEnumeration($coId, $attribute, $value) {

$a = explode('.', $attribute, 2);
$data[ $a[0] ][ $a[1] ] = $value;
$newdata = $this->normalize($data, $coId);
$newdata = $this->normalize($data, $coId, $options);

$this->Behaviors->unload('Normalization');

Expand Down
17 changes: 13 additions & 4 deletions app/Model/Behavior/NormalizationBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class NormalizationBehavior extends ModelBehavior {
*/

public function beforeSave(Model $model, $options = array()) {
$model->data = $this->normalize($model, $model->data);
$model->data = $this->normalize($model, $model->data, false, $options);

return true;
}
Expand All @@ -48,13 +48,22 @@ public function beforeSave(Model $model, $options = array()) {
* @param Model $model Model instance
* @param Array $data Data to normalize in usual format; need not belong to $model
* @param Integer $coId CO ID data belongs to, or null for Org Identity data, or false to determine from $data ($data must then belong to $model)
* @param array List of Save options
* @return boolean true on success
* @throws RuntimeException
*/

public function normalize(Model $model, $data, $coId = false) {
public function normalize(Model $model, $data, $coId = false, $options = array()) {
$mname = $model->alias;


// Are there any types of normalization that we need to skip
$normalization_dis = array();
if(isset($options['mixCase']) && !$options['mixCase']) {
$normalization_dis[] = 'mixCase';
}
if(isset($options['trimWhitespace']) && !$options['trimWhitespace']) {
$normalization_dis[] = 'trimWhitespace';
}
// If $coId is false, look for a CO ID. If we don't find one or if $coId is null,
// we're dealing with org identity data, which normalizations don't currently support.

Expand Down Expand Up @@ -113,7 +122,7 @@ public function normalize(Model $model, $data, $coId = false) {

if($pluginModel->isPlugin('normalizer')) {
try {
$data = $pluginModel->normalize($data);
$data = $pluginModel->normalize($data, $normalization_dis);
}
catch(Exception $e) {
throw new RuntimeException($e->getMessage());
Expand Down
3 changes: 2 additions & 1 deletion app/Model/CoPersonRole.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,8 @@ public function beforeSave($options = array()) {
// Normalize Enumeration
$this->data[$this->alias][$a] = $this->normalizeEnumeration($coId,
'CoPersonRole.'.$a,
$this->data[$this->alias][$a]);
$this->data[$this->alias][$a],
$options);
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion app/Model/CoPipeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,9 @@ protected function syncOrgIdentityToCoPerson($coPipeline,
// We need to inject the CO so extended types can be saved
$this->Co->CoPerson->CoPersonRole->validate['affiliation']['content']['rule'][1]['coid'] = $orgIdentity['OrgIdentity']['co_id'];

if(!$this->Co->CoPerson->CoPersonRole->save($newCoPersonRole, array("provision" => false, "safeties" => $safeties))) {
if(!$this->Co->CoPerson->CoPersonRole->save($newCoPersonRole, array("provision" => false,
"safeties" => $safeties,
"mixCase" => false))) {
throw new RuntimeException(_txt('er.db.save-a', array('CoPersonRole')));
}

Expand Down Expand Up @@ -1172,6 +1174,7 @@ protected function syncOrgIdentityToCoPerson($coPipeline,
if(!$model->save($nr, array("provision" => false,
"safeties" => $safeties,
"skipAvailability" => true,
"mixCase" => !in_array($model, array('CoPersonRole', 'EnrolleeCoPersonRole')),
"trustVerified" => $trustVerified))) {

throw new RuntimeException(_txt('er.db.save-a',
Expand Down
7 changes: 6 additions & 1 deletion app/Plugin/DefaultNormalizer/Model/DefaultNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ public function cmPluginMenus() {
*
* @since COmanage Registry v0.9.2
* @param Array Data to be saved, in typical Cake format
* @param Array Type of normalizations that we will skip
* @return Array Data in the same format
*/

public function normalize($data) {
public function normalize($data, $normalization_dis = array()) {
$ret = $data;

$normalizations = array(
Expand Down Expand Up @@ -142,6 +143,10 @@ public function normalize($data) {
// Run the appropriate normalizations for each field within the model

foreach(array_keys($normalizations[$model]) as $normalization) {
// Skip a normalization if found in the exception list
if(in_array($normalization, $normalization_dis)) {
continue;
}
foreach($normalizations[$model][$normalization] as $field) {
if(!empty($ret[$model][$field])) {
$ret[$model][$field] = $this->$normalization($ret[$model][$field], $field);
Expand Down

0 comments on commit 7aab4fa

Please sign in to comment.