Skip to content

Commit

Permalink
Manually set the current CO ID for models with dynamic validation rul…
Browse files Browse the repository at this point in the history
…es for ExternalIdentitySource plugins (#140)
  • Loading branch information
Ioannis authored Jan 26, 2024
1 parent 847bbbf commit 585af46
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions app/src/Controller/ExternalIdentitySourcesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,32 @@
use Cake\ORM\TableRegistry;

class ExternalIdentitySourcesController extends StandardPluggableController {
/**
* Perform Cake Controller initialization.
*
* @since COmanage Registry v5.0.0
*/

public function initialize(): void {
parent::initialize();

// We need to manually set the Current CO ID for models with dynamic
// validation rules. This is ordinarily done by AppController, but
// AppController doesn't know how to figure out what CO an API request
// maps to. Plugins can implement calculateRequestedCOID() to tell
// AppController what the current CO is, we then pass that information
// manually here.

// It's not ideal to have a hardcoded list of models, but we don't have
// a better solution at the moment.

foreach(['Addresses', 'Names', 'TelephoneNumbers'] as $m) {
$Table = TableRegistry::getTableLocator()->get($m);

$Table->setCurCoId($this->getCOID());
}
}

public $paginate = [
'order' => [
'ExternalIdentitySources.description' => 'asc'
Expand Down

0 comments on commit 585af46

Please sign in to comment.