Skip to content

Commit

Permalink
Fix handling of Pipelined attributes with multiple External Identitie…
Browse files Browse the repository at this point in the history
…s (NOJIRA)
  • Loading branch information
Benn Oshrin committed Jul 15, 2024
1 parent 0754723 commit f326b5c
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 22 deletions.
3 changes: 3 additions & 0 deletions app/resources/locales/en_US/field.po
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,9 @@ msgstr "If true, Global Search will only search Names, Email Addresses, and Iden
msgid "ExternalIdentitySources.hash_source_record"
msgstr "Hash Source Records"

msgid "ExternalIdentitySources.sor_label"
msgstr "System of Record Label"

msgid "ExternalIdentitySources.source_record.empty"
msgstr "The source record is empty. This suggests the record is no longer available from the datasource."

Expand Down
4 changes: 2 additions & 2 deletions app/src/Model/Table/AdHocAttributesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ public function initialize(array $config): void {
$this->belongsTo('PersonRoles');
$this->belongsTo('ExternalIdentities');
$this->belongsTo('ExternalIdentityRoles');
$this->belongsTo('ExtIdentitySourceRecords')
->setClassName('ExtIdentitySourceRecords')
$this->belongsTo('SourceAdHocAttributes')
->setClassName('AdHocAttributes')
->setForeignKey('source_ad_hoc_attribute_id')
->setProperty('source_ad_hoc_attribute');

Expand Down
4 changes: 4 additions & 0 deletions app/src/Model/Table/AddressesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ public function initialize(array $config): void {
$this->belongsTo('ExternalIdentities');
$this->belongsTo('ExternalIdentityRoles');
$this->belongsTo('Types');
$this->belongsTo('SourceAddresses')
->setClassName('Addresses')
->setForeignKey('source_address_id')
->setProperty('source_address');

$this->setDisplayField('street');

Expand Down
4 changes: 2 additions & 2 deletions app/src/Model/Table/EmailAddressesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ public function initialize(array $config): void {
$this->belongsTo('People');
$this->belongsTo('ExternalIdentities');
$this->belongsTo('Types');
$this->belongsTo('ExtIdentitySourceRecords')
->setClassName('ExtIdentitySourceRecords')
$this->belongsTo('SourceEmailAddresses')
->setClassName('EmailAddresses')
->setForeignKey('source_email_address_id')
->setProperty('source_email_address');

Expand Down
4 changes: 2 additions & 2 deletions app/src/Model/Table/IdentifiersTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ public function initialize(array $config): void {
$this->belongsTo('People');
$this->belongsTo('ProvisioningTargets');
$this->belongsTo('Types');
$this->belongsTo('ExtIdentitySourceRecords')
->setClassName('ExtIdentitySourceRecords')
$this->belongsTo('SourceIdentifiers')
->setClassName('Identifiers')
->setForeignKey('source_identifier_id')
->setProperty('source_identifier');

Expand Down
4 changes: 2 additions & 2 deletions app/src/Model/Table/NamesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ public function initialize(array $config): void {
$this->belongsTo('People');
$this->belongsTo('ExternalIdentities');
$this->belongsTo('Types');
$this->belongsTo('ExtIdentitySourceRecords')
->setClassName('ExtIdentitySourceRecords')
$this->belongsTo('SourceNames')
->setClassName('Names')
->setForeignKey('source_name_id')
->setProperty('source_name');

Expand Down
32 changes: 22 additions & 10 deletions app/src/Model/Table/PipelinesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
use \App\Lib\Enum\ProvisioningContextEnum;
use \App\Lib\Enum\StatusEnum;
use \App\Lib\Enum\SuspendableStatusEnum;
use \App\Lib\Util\StringUtilities;

class PipelinesTable extends Table {
use \App\Lib\Traits\AutoViewVarsTrait;
Expand Down Expand Up @@ -1458,6 +1459,10 @@ protected function syncPerson(
$amodel = Inflector::underscore($model);
// sourcefk = eg source_name_id
$sourcefk = $this->Cos->People->$model->sourceForeignKey();
// sourceModel = eg SourceName
$sourceModel = StringUtilities::foreignKeyToClassName($sourcefk);
// sourceEntity = eg source_name
$sourceEntity = "source_" . $amodel;

// Pull the current set of associated records for this model.
// We can filter down to those that came from _any_ source (ie
Expand All @@ -1471,6 +1476,7 @@ protected function syncPerson(
$model.'.person_id' => $person->id,
$model.'.'.$sourcefk." IS NOT" => null
])
->contain([$sourceModel])
->all();

// Track which IDs we've seen to facilitate deletes.
Expand Down Expand Up @@ -1555,20 +1561,26 @@ protected function syncPerson(
// Now walk through the Person entities, and delete any that we didn't see.
// In theory we could make Cake do this automatically via a HasOne
// relation, but it's a bit tricky to make Cake handle relations within
// the same object correctly to cascade the delete.
// the same object correctly to cascade the delete. Also, we need to
// filter entities that aren't associated with this EIS.

if(!empty($curentities)) {
foreach($curentities as $aentity) {
// $aentity is an entity attached to the Person, we search through the
// source attributes for one with a corresponding source key ID
$found = Hash::extract($externalIdentity[$amodel], '{n}[id='.$aentity->$sourcefk.']');
if(!empty($aentity->$sourceEntity->external_identity_id)
&& $aentity->$sourceEntity->external_identity_id == $externalIdentityId) {
// $aentity is an entity attached to the Person and was sourced from
// an attribute associated with the current External Identity (as opposed
// to another EI associated with the Person); we search through the
// source attributes for one with a corresponding source key ID
$found = Hash::extract($externalIdentity[$amodel], '{n}[id='.$aentity->$sourcefk.']');

if(!$found) {
if(isset($aentity->frozen) && $aentity->frozen) {
$this->llog('trace', "Refusing to delete frozen $model " . $aentity->id . " on Person from External Identity " . $externalIdentity->id);
} else {
$this->llog('trace', "Deleted $model " . $aentity->id . " for Person " . $person->id);
$this->Cos->People->$model->deleteOrFail($aentity);
if(!$found) {
if(isset($aentity->frozen) && $aentity->frozen) {
$this->llog('trace', "Refusing to delete frozen $model " . $aentity->id . " on Person from External Identity " . $externalIdentity->id);
} else {
$this->llog('trace', "Deleted $model " . $aentity->id . " for Person " . $person->id);
$this->Cos->People->$model->deleteOrFail($aentity);
}
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions app/src/Model/Table/PronounsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ public function initialize(array $config): void {
$this->belongsTo('People');
$this->belongsTo('ExternalIdentities');
$this->belongsTo('Types');
$this->belongsTo('SourcePronouns')
->setClassName('Pronouns')
->setForeignKey('source_pronoun_id')
->setProperty('source_pronoun');

$this->setDisplayField('pronouns');

Expand Down
4 changes: 2 additions & 2 deletions app/src/Model/Table/TelephoneNumbersTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ public function initialize(array $config): void {
$this->belongsTo('ExternalIdentities');
$this->belongsTo('ExternalIdentityRoles');
$this->belongsTo('Types');
$this->belongsTo('ExtIdentitySourceRecords')
->setClassName('ExtIdentitySourceRecords')
$this->belongsTo('SourceTelephoneNumbers')
->setClassName('TelephoneNumbers')
->setForeignKey('source_telephone_number_id')
->setProperty('source_telephone_number');

Expand Down
4 changes: 4 additions & 0 deletions app/src/Model/Table/UrlsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ public function initialize(array $config): void {
$this->belongsTo('People');
$this->belongsTo('ExternalIdentities');
$this->belongsTo('Types');
$this->belongsTo('SourceUrls')
->setClassName('Urls')
->setForeignKey('source_url_id')
->setProperty('source_url');

$this->setDisplayField('url');

Expand Down
3 changes: 1 addition & 2 deletions app/templates/ExternalIdentitySources/fields.inc
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ if($vv_action == 'add' || $vv_action == 'edit') {
'status',
'plugin',
'pipeline_id',
// Not yet implemented
// 'sor_label',
'sor_label',
'hash_source_record',
'suppress_noop_logs'
] as $field) {
Expand Down

0 comments on commit f326b5c

Please sign in to comment.