Skip to content

Commit

Permalink
Fix incorrect ApiSourceEndpoint foreign key (CFM-472)
Browse files Browse the repository at this point in the history
  • Loading branch information
Benn Oshrin committed Sep 20, 2025
1 parent 4fb20aa commit 26c23a5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
4 changes: 2 additions & 2 deletions app/availableplugins/ApiConnector/config/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
"columns": {
"id": {},
"api_id": {},
"api_source_id": { "type": "integer", "foreignkey": { "table": "api_sources", "column": "id" } }
"external_identity_source_id": {}
},
"indexes": {
"api_source_endpoints_i1": { "columns": [ "api_id" ] },
"api_source_endpoints_i2": { "columns": [ "api_source_id" ] }
"api_source_endpoints_i2": { "columns": [ "external_identity_source_id" ] }
}
},
"api_source_records": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,17 @@ class ApiSourceEndpointsController extends StandardPluginController {
public function beforeRender(\Cake\Event\EventInterface $event) {
$vv_obj = $this->viewBuilder()->getVar('vv_obj');

if(!empty($vv_obj->api_source_id)) {
$apiSource = $this->ApiSourceEndpoints->ApiSources->get(
$vv_obj->api_source_id,
contain: 'ExternalIdentitySources'
);
if(!empty($vv_obj->external_identity_source->api_source->id)) {
// For consistency with other plugins, the data model points to the External Identity Source
// but the API points to Api Source.

$this->set(
'vv_push_endpoint',
Router::url(
url: '/api/apisource/' . $apiSource->id . '/v2/sorPeople/' . $apiSource->external_identity_source->sor_label,
url: '/api/apisource/'
. $vv_obj->external_identity_source->api_source->id
. '/v2/sorPeople/'
. $vv_obj->external_identity_source->sor_label,
full: true
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class ApiSourceEndpointsTable extends Table {
use \App\Lib\Traits\CoLinkTrait;
use \App\Lib\Traits\PermissionsTrait;
use \App\Lib\Traits\PrimaryLinkTrait;
use \App\Lib\Traits\QueryModificationTrait;
use \App\Lib\Traits\TableMetaTrait;
use \App\Lib\Traits\ValidationTrait;

Expand All @@ -58,8 +59,7 @@ public function initialize(array $config): void {
$this->setTableType(\App\Lib\Enum\TableTypeEnum::Configuration);

// Define associations
$this->belongsTo('ApiConnector.ApiSources');
// $this->belongsTo('ApiUsers');
$this->belongsTo('ExternalIdentitySources');
$this->belongsTo('Apis');

$this->setDisplayField('api_id');
Expand All @@ -68,8 +68,13 @@ public function initialize(array $config): void {
$this->setRequiresCO(true);
$this->setRedirectGoal('self');

$this->setEditContains([
'ExternalIdentitySources' => ['ApiSources']
]);


$this->setAutoViewVars([
'apiSources' => [
'externalIdentitySources' => [
'type' => 'plugin',
'model' => 'ApiConnector.ApiSources'
]
Expand Down Expand Up @@ -108,10 +113,10 @@ public function validationDefault(Validator $validator): Validator {
]);
$validator->notEmptyString('api_id');

$validator->add('api_source_id', [
$validator->add('external_identity_source_id', [
'content' => ['rule' => 'isInteger']
]);
$validator->notEmptyString('api_source_id');
$validator->notEmptyString('external_identity_source_id');

return $validator;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ if($vv_action == 'edit') {

print $this->element('form/listItem', [
'arguments' => [
'fieldName' => 'api_source_id',
'fieldName' => 'external_identity_source_id',
]
]);
}

0 comments on commit 26c23a5

Please sign in to comment.