diff --git a/lib/Controller/GebruikController.php b/lib/Controller/GebruikController.php index 901b31c3..d4e6923d 100644 --- a/lib/Controller/GebruikController.php +++ b/lib/Controller/GebruikController.php @@ -70,6 +70,11 @@ public function getGebruiken(): JSONResponse { $user = $this->userSession->getUser(); + // Return empty results for non-logged-in users to prevent unnecessary errors. + if ($user === null) { + return new JSONResponse($this->getEmptyResult()); + } + $groups = $this->groupManager->getUserGroups(user: $user); $groupNames = array_map(function (IGroup $group) { return $group->getGID(); @@ -85,17 +90,17 @@ public function getGebruiken(): JSONResponse $applicatieIds = $this->gebruikService->getApplicationIds(options: $applicatieOptions); if ($applicatieIds === []) { - return new JSONResponse(data: ['error' => 'no access'], statusCode: 403); + return new JSONResponse($this->getEmptyResult()); } if (isset($options['module']) === true && in_array($options['module'], $applicatieIds) === false) { - return new JSONResponse(data: ['error' => 'no access'], statusCode: 403); + return new JSONResponse($this->getEmptyResult()); } else if (isset($options['module']) === false) { $options['module'] = $applicatieIds; } } else { - return new JSONResponse(data: ['error' => 'no access'], statusCode: 403); + return new JSONResponse($this->getEmptyResult()); } try { @@ -116,6 +121,12 @@ public function getGebruiken(): JSONResponse public function getGebruikenForDeelnemer(): JSONResponse { $user = $this->userSession->getUser(); + + // Return empty results for non-logged-in users to prevent unnecessary errors. + if ($user === null) { + return new JSONResponse($this->getEmptyResult()); + } + $orgUuid = $this->config->getUserValue(userId: $user->getUID(), appName: 'core', key: 'organisation'); $options = $this->request->getParams(); @@ -128,6 +139,32 @@ public function getGebruikenForDeelnemer(): JSONResponse } } + /** + * Returns an empty result set with the standard paginated response structure. + * + * @return array The empty result structure. + */ + private function getEmptyResult(): array + { + return [ + 'results' => [], + 'total' => 0, + 'page' => 1, + 'pages' => 0, + 'limit' => 1000, + 'offset' => 0, + 'facets' => [], + '@self' => [ + 'source' => 'database', + 'query' => [], + 'rbac' => false, + 'multi' => false, + 'published' => false, + 'deleted' => false, + ], + ]; + } + } diff --git a/lib/Service/GebruikService.php b/lib/Service/GebruikService.php index 9918e8b3..58daa190 100644 --- a/lib/Service/GebruikService.php +++ b/lib/Service/GebruikService.php @@ -104,6 +104,17 @@ public function getGebruiken(array $options): array 'schema' => $gebruiksConfig['gebruikSchema'], ]; + // Normalize _extend parameter to array format. + // Supports both 'extend' and '_extend' parameter names. + $extend = $options['extend'] ?? $options['_extend'] ?? []; + if (is_string($extend) === true) { + $extend = array_map('trim', explode(',', $extend)); + } else if (is_array($extend) === false) { + $extend = [$extend]; + } + $options['_extend'] = $extend; + unset($options['extend']); + $searchResult = $objectService->searchObjectsPaginated(query: $options, _rbac: false, _multitenancy: false); $searchResult['results'] = array_map(function($object) { diff --git a/lib/Service/ModuleComplianceService.php b/lib/Service/ModuleComplianceService.php index b8d67d99..f2674aeb 100644 --- a/lib/Service/ModuleComplianceService.php +++ b/lib/Service/ModuleComplianceService.php @@ -114,7 +114,7 @@ public function handleModuleComplianceUpdate(object $moduleObject): void ]); // Get current standaarden from module - $currentStandaarden = $moduleData['standaarden'] ?? []; + $currentStandaarden = $moduleData['standaardVersies'] ?? []; // Ensure currentStandaarden is an array if (!is_array($currentStandaarden)) { @@ -360,13 +360,13 @@ private function updateModuleStandaarden(object $moduleObject, array $standaardv $moduleData = $moduleObject->getObject(); // Update standaarden property - $moduleData['standaarden'] = $standaardversieUuids; + $moduleData['standaardVersies'] = $standaardversieUuids; // Get register ID from module object $registerId = $moduleObject->getRegister(); // Save the updated module - $objectService->saveObject( + $savedObject = $objectService->saveObject( object: $moduleData, extend: [], register: $registerId, @@ -586,7 +586,7 @@ public function bulkSyncModuleStandards(): array } // Get current standaarden from module - $currentStandaarden = $moduleData['standaarden'] ?? []; + $currentStandaarden = $moduleData['standaardVersies'] ?? []; // Ensure currentStandaarden is an array if (!is_array($currentStandaarden)) { diff --git a/lib/Settings/Settings/softwarecatalogus_register.json b/lib/Settings/Settings/softwarecatalogus_register.json index 74777d93..c8bd78bd 100644 --- a/lib/Settings/Settings/softwarecatalogus_register.json +++ b/lib/Settings/Settings/softwarecatalogus_register.json @@ -5418,6 +5418,23 @@ "type": "string" } }, + "standaardVersies": { + "description": "De standaardversies die deze applicatie implementeert", + "type": "array", + "visible": true, + "order": 26, + "facetable": true, + "title": "Standaard Versies", + "hideOnForm": true, + "items": { + "type": "object", + "objectConfiguration": { + "handling": "related-object", + "queryParams": "gemmaType=standaardversie" + }, + "$ref": "#/components/schemas/element" + } + }, "moduleVersies": { "description": "De versies van deze applicatie", "type": "array", diff --git a/lib/Settings/softwarecatalogus_register.json b/lib/Settings/softwarecatalogus_register.json index 504fa851..4421273f 100644 --- a/lib/Settings/softwarecatalogus_register.json +++ b/lib/Settings/softwarecatalogus_register.json @@ -5724,6 +5724,23 @@ "type": "string" } }, + "standaardVersies": { + "description": "De standaardversies die deze applicatie implementeert", + "type": "array", + "visible": true, + "order": 26, + "facetable": true, + "title": "Standaard Versies", + "hideOnForm": true, + "items": { + "type": "object", + "objectConfiguration": { + "handling": "related-object", + "queryParams": "gemmaType=standaardversie" + }, + "$ref": "#/components/schemas/element" + } + }, "moduleVersies": { "description": "De versies van deze applicatie", "type": "array",