From bc1ac73f3b3936fd7ade372b34989994c89ae88a Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Sun, 14 Jan 2024 19:33:09 +0200 Subject: [PATCH] Manually set the current CO ID for models with dynamic validation rules for ExternalIdentitySource plugins --- .../ExternalIdentitySourcesController.php | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/app/src/Controller/ExternalIdentitySourcesController.php b/app/src/Controller/ExternalIdentitySourcesController.php index 53ab3bcc9..708916c6f 100644 --- a/app/src/Controller/ExternalIdentitySourcesController.php +++ b/app/src/Controller/ExternalIdentitySourcesController.php @@ -34,6 +34,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'