From 079f24bb909bbf5a76f0e2132c030567042681ba Mon Sep 17 00:00:00 2001 From: Benn Oshrin Date: Wed, 12 Nov 2025 10:17:21 -0500 Subject: [PATCH] Fix rendering of API json responses (CFM-483) and misc other cleanup --- .../src/Controller/MatchCallbackApiV1Controller.php | 2 +- app/src/Command/UpgradeCommand.php | 2 +- app/src/Controller/Component/RegistryAuthComponent.php | 2 +- app/src/Controller/StandardApiController.php | 6 ++++++ app/src/Controller/StandardController.php | 8 +++++--- app/src/Lib/Traits/AutoViewVarsTrait.php | 6 +++--- app/src/Lib/Util/StringUtilities.php | 2 +- app/src/Lib/Util/TableUtilities.php | 2 +- app/src/Model/Table/GroupsTable.php | 6 +++--- app/src/Model/Table/MetaTable.php | 2 +- app/src/Model/Table/ProvisioningTargetsTable.php | 2 +- 11 files changed, 24 insertions(+), 16 deletions(-) diff --git a/app/plugins/CoreApi/src/Controller/MatchCallbackApiV1Controller.php b/app/plugins/CoreApi/src/Controller/MatchCallbackApiV1Controller.php index 32b103946..06f396ef7 100644 --- a/app/plugins/CoreApi/src/Controller/MatchCallbackApiV1Controller.php +++ b/app/plugins/CoreApi/src/Controller/MatchCallbackApiV1Controller.php @@ -29,7 +29,7 @@ namespace CoreApi\Controller; -use \Cake\ORM\TableRegistry; +use Cake\ORM\TableRegistry; use \App\Controller\StandardApiController; use \App\Lib\Enum\SyncModeEnum; diff --git a/app/src/Command/UpgradeCommand.php b/app/src/Command/UpgradeCommand.php index df7365f09..c341f5e6d 100644 --- a/app/src/Command/UpgradeCommand.php +++ b/app/src/Command/UpgradeCommand.php @@ -434,7 +434,7 @@ protected function checkGroupNames() { * @param int $couId COU ID */ - protected function createDefaultGroups(int $coId, int $couId=null) { + protected function createDefaultGroups(int $coId, ?int $couId=null) { $GroupsTable = $this->getTableLocator()->get('Groups'); // Technically this will try to add all the default Groups, which is fine since diff --git a/app/src/Controller/Component/RegistryAuthComponent.php b/app/src/Controller/Component/RegistryAuthComponent.php index 7fbf54e9b..6e3241c76 100644 --- a/app/src/Controller/Component/RegistryAuthComponent.php +++ b/app/src/Controller/Component/RegistryAuthComponent.php @@ -655,7 +655,7 @@ public function getApplicationUserRoles(?int $coId): array { * Obtain the identifier of the currently authenticated user. * * @since COmanage Registry v5.0.0 - * @return string The authenticated user identifier or false if no authenticated user + * @return string The authenticated user identifier or null if no authenticated user */ public function getAuthenticatedUser(): ?string { diff --git a/app/src/Controller/StandardApiController.php b/app/src/Controller/StandardApiController.php index 49dd9fb10..be615572e 100644 --- a/app/src/Controller/StandardApiController.php +++ b/app/src/Controller/StandardApiController.php @@ -46,6 +46,12 @@ public function initialize(): void { // We want API auth, not Web Auth $this->RegistryAuth->setConfig('apiUser', true); + + // Tell cake to automatically negotiate JSON, which will have the + // most visible side effect of causing stack traces to render as + // JSON instead of HTML, and also tell the View handler to look in + // the "json" subdirectory of the appropriate template directory. + $this->addViewClasses([\Cake\View\JsonView::class]); } /** diff --git a/app/src/Controller/StandardController.php b/app/src/Controller/StandardController.php index c7e6475cd..2a30f174a 100644 --- a/app/src/Controller/StandardController.php +++ b/app/src/Controller/StandardController.php @@ -252,9 +252,11 @@ public function delete($id) { try { $obj = $table->findById($id)->firstOrFail(); - // By default, a delete is a soft delete. The exceptions are when - // deleting a CO (AR-CO-1) or when an expunge flag is passed and - // expunge is enabled within the CO (XXX not yet implemented). + // By default, a delete is a soft delete. The exceptions is when + // deleting a CO (AR-CO-1). In v4, we permitted a controller level + // flag to be set, but the only controller this really applies to + // is CO right now, so we'll skip implementing a flag until we have + // another use case. $useHardDelete = ($modelsName == "Cos"); diff --git a/app/src/Lib/Traits/AutoViewVarsTrait.php b/app/src/Lib/Traits/AutoViewVarsTrait.php index b9d94948d..686c412d3 100644 --- a/app/src/Lib/Traits/AutoViewVarsTrait.php +++ b/app/src/Lib/Traits/AutoViewVarsTrait.php @@ -71,9 +71,9 @@ public function setAutoViewVars($vars): void { */ public function calculateAutoViewVars( - int|null $coId, - Object $obj = null, - string $action = null + ?int $coId, + ?Object $obj = null, + ?string $action = null ): \Generator { /** var Cake\ORM\Table $table */ $table = $this; diff --git a/app/src/Lib/Util/StringUtilities.php b/app/src/Lib/Util/StringUtilities.php index 43bb5c661..0fda489e5 100644 --- a/app/src/Lib/Util/StringUtilities.php +++ b/app/src/Lib/Util/StringUtilities.php @@ -102,7 +102,7 @@ public static function classNameToForeignKey(string $className): string { public static function columnKey( string $modelsName, string $c, - \DateTimeZone $tz=null, + ?\DateTimeZone $tz=null, bool $useCustomClMdlLabel=false ): string { if(strpos($c, '_id', strlen($c)-3)) { diff --git a/app/src/Lib/Util/TableUtilities.php b/app/src/Lib/Util/TableUtilities.php index a38cb6299..63e0a4f52 100644 --- a/app/src/Lib/Util/TableUtilities.php +++ b/app/src/Lib/Util/TableUtilities.php @@ -150,7 +150,7 @@ public static function treeTraversalFromPrimaryLink( string $primaryLinkKey, int $primaryLinkValue, array &$results, - string $primaryLinkClassName = null + ?string $primaryLinkClassName = null ): void { $db = ConnectionManager::get('default'); diff --git a/app/src/Model/Table/GroupsTable.php b/app/src/Model/Table/GroupsTable.php index b8b268f7d..bba1cd34f 100644 --- a/app/src/Model/Table/GroupsTable.php +++ b/app/src/Model/Table/GroupsTable.php @@ -274,7 +274,7 @@ public function initialize(array $config): void { * @throws PersistenceFailedException */ - public function addDefaults(int $coId, int $couId=null, bool $rename=false): bool { + public function addDefaults(int $coId, ?int $couId=null, bool $rename=false): bool { // Pull the name of the CO/COU $Cos = TableRegistry::getTableLocator()->get('Cos'); @@ -715,7 +715,7 @@ public function getApproversGroupId(?int $coId=null, ?int $couId=null): int { public function getMembers( int $id, - int $groupNestingId=null, + ?int $groupNestingId=null, bool $valid=true, bool $active=true, bool $activeGroup=true @@ -948,7 +948,7 @@ public function marshalProvisioningData(int $id): array { public function potentialParents( int $coId, - int $id=null, + ?int $id=null, bool $hierarchy=false, array $where=[] ): array { diff --git a/app/src/Model/Table/MetaTable.php b/app/src/Model/Table/MetaTable.php index 5b7e6ddd2..9592194f6 100644 --- a/app/src/Model/Table/MetaTable.php +++ b/app/src/Model/Table/MetaTable.php @@ -72,7 +72,7 @@ public function getUpgradeVersion(): ?string { * @return bool true on success */ - public function setUpgradeVersion(string $version=null): bool { + public function setUpgradeVersion(?string $version=null): bool { $sql = null; $currentVersion = $this->getUpgradeVersion(); diff --git a/app/src/Model/Table/ProvisioningTargetsTable.php b/app/src/Model/Table/ProvisioningTargetsTable.php index c1ba4b9c1..e1075a8e6 100644 --- a/app/src/Model/Table/ProvisioningTargetsTable.php +++ b/app/src/Model/Table/ProvisioningTargetsTable.php @@ -254,7 +254,7 @@ public function provision( * @param int $personId Person ID */ - public function status(int $coId, int $groupId=null, int $personId=null): array { + public function status(int $coId, ?int $groupId=null, ?int $personId=null): array { $ret = []; // Start by pulling the set of active provisioning targets