Skip to content

Commit

Permalink
Fix rendering of API json responses (CFM-483) and misc other cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Benn Oshrin committed Nov 12, 2025
1 parent c2529e1 commit 079f24b
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

namespace CoreApi\Controller;

use \Cake\ORM\TableRegistry;
use Cake\ORM\TableRegistry;
use \App\Controller\StandardApiController;
use \App\Lib\Enum\SyncModeEnum;

Expand Down
2 changes: 1 addition & 1 deletion app/src/Command/UpgradeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/src/Controller/Component/RegistryAuthComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions app/src/Controller/StandardApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}

/**
Expand Down
8 changes: 5 additions & 3 deletions app/src/Controller/StandardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
6 changes: 3 additions & 3 deletions app/src/Lib/Traits/AutoViewVarsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion app/src/Lib/Util/StringUtilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/Lib/Util/TableUtilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
6 changes: 3 additions & 3 deletions app/src/Model/Table/GroupsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion app/src/Model/Table/MetaTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion app/src/Model/Table/ProvisioningTargetsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 079f24b

Please sign in to comment.