From d739d25fbbcbbbc970ea99cabc1961859eb1a60a Mon Sep 17 00:00:00 2001 From: Benn Oshrin Date: Thu, 28 Aug 2025 07:02:14 -0400 Subject: [PATCH] Various fixes to Pluggable Model handling (CFM-445) --- app/src/Lib/Traits/AutoViewVarsTrait.php | 40 +++++++++---------- .../Model/Table/EnrollmentFlowStepsTable.php | 2 +- app/src/Model/Table/TrafficDetoursTable.php | 2 +- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/app/src/Lib/Traits/AutoViewVarsTrait.php b/app/src/Lib/Traits/AutoViewVarsTrait.php index 49ecbf123..f477b590d 100644 --- a/app/src/Lib/Traits/AutoViewVarsTrait.php +++ b/app/src/Lib/Traits/AutoViewVarsTrait.php @@ -21,7 +21,7 @@ * * @link https://www.internet2.edu/comanage COmanage Project * @package registry - * @since COmanage Registry v5.0.0 + * @since COmanage Registry v5.1.0 * @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0) */ @@ -64,14 +64,13 @@ public function setAutoViewVars($vars): void { /** * Calculate the AutoView Vars * - * @param int|null $coId - * @param Object|null $obj Current object (eg: from edit), if set - * + * @since COmanage Registry v5.1.0 + * @param int|null $coId + * @param Object|null $obj Current object (eg: from edit), if set * @return \Generator - * @since COmanage Registry v5.0.0 */ - public function calculateAutoViewVars(int|null $coId, Object $obj = null): \Generator - { + + public function calculateAutoViewVars(int|null $coId, Object $obj = null): \Generator { // $table = the actual table object $table = $this; @@ -225,30 +224,31 @@ public function calculateAutoViewVars(int|null $coId, Object $obj = null): \Gene $PluggableTable = TableRegistry::getTableLocator()->get(StringUtilities::foreignKeyToClassName($l)); if(method_exists($PluggableTable, "getPluggableModelType")) { - // This is the correct primary link. Note we don't necessarily know how to - // filter inactive records since the only column PluggableTrait requires is - // "plugin". + // This is the correct primary link. - // The entity field holding the related model - $modelKey = StringUtilities::pluginToEntityField($avv['model']); - - // For now we don't filter on status because not all Pluggable models - // use it consistency. (Specifically, EISs use SyncModeEnum instead.) + // This isn't really an Application Rule, but per the documentation at + // https://spaces.at.internet2.edu/display/COmanage/Adding+a+Pluggable+Model + // we require all Pluggable Models to have a status field, and define "S" as the + // value that will remove values from this list. (The recommendation is to use "X" + // to disable but allow the value to still appear.) $generatedValue = $PluggableTable->find('list', [ - 'keyField' => $modelKey.'.id', + 'keyField' => 'id', 'valueField' => 'description' ]) - ->where(['plugin' => $avv['model']]) - ->contain(StringUtilities::pluginModel($avv['model'])) + // We assume Pluggable tables always FK to co_id which + // is currently true but might not always be true + ->where([ + 'plugin' => $avv['model'], + 'co_id' => $coId, + 'status IS NOT' => "S" + ]) ->all(); - break; } } } break; default: -// XXX I18n? and in match? throw new \LogicException(__d('error', 'auto.viewvar.type.unknown', [$avv['type']])); } diff --git a/app/src/Model/Table/EnrollmentFlowStepsTable.php b/app/src/Model/Table/EnrollmentFlowStepsTable.php index 295b8e2d9..8fce44cc8 100644 --- a/app/src/Model/Table/EnrollmentFlowStepsTable.php +++ b/app/src/Model/Table/EnrollmentFlowStepsTable.php @@ -116,7 +116,7 @@ public function initialize(array $config): void { ], 'plugins' => [ 'type' => 'plugin', - 'pluginType' => 'enroller' + 'pluginType' => 'enrollment_flow_step' ], 'statuses' => [ 'type' => 'enum', diff --git a/app/src/Model/Table/TrafficDetoursTable.php b/app/src/Model/Table/TrafficDetoursTable.php index 596680a11..7a36f36c5 100644 --- a/app/src/Model/Table/TrafficDetoursTable.php +++ b/app/src/Model/Table/TrafficDetoursTable.php @@ -70,7 +70,7 @@ public function initialize(array $config): void { $this->setAutoViewVars([ 'plugins' => [ 'type' => 'plugin', - 'pluginType' => 'traffic' + 'pluginType' => 'traffic_detour' ], 'statuses' => [ 'type' => 'enum',