From d3a31be412a1d795b95260d0f173f96b2c259302 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 3 Oct 2025 22:31:07 +0200 Subject: [PATCH] Fix re-ordering of StoredObjectVersion in the list of versions As some intermediate versions are remove, this may lead to situation where the indexes are not continous. In that case, the array is not a list, and is rendered as an array with numeric indexes, instead of a list of elements. The HistoryListItem component fails to render. - Ensured proper handling of removed versions by using `array_values` to reindex items. - Added test case to validate the result after removing a version. - Asserted the results are a proper list in the API response. --- .changes/unreleased/Fixed-20251003-224044.yaml | 6 ++++++ .../Controller/StoredObjectVersionApiController.php | 2 +- .../Controller/StoredObjectVersionApiControllerTest.php | 5 +++++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 .changes/unreleased/Fixed-20251003-224044.yaml diff --git a/.changes/unreleased/Fixed-20251003-224044.yaml b/.changes/unreleased/Fixed-20251003-224044.yaml new file mode 100644 index 000000000..c5b3e7304 --- /dev/null +++ b/.changes/unreleased/Fixed-20251003-224044.yaml @@ -0,0 +1,6 @@ +kind: Fixed +body: Fix the rendering of list of StoredObjectVersions, where there are kept version (before converting to pdf) and intermediate versions deleted +time: 2025-10-03T22:40:44.685474863+02:00 +custom: + Issue: "" + SchemaChange: No schema change diff --git a/src/Bundle/ChillDocStoreBundle/Controller/StoredObjectVersionApiController.php b/src/Bundle/ChillDocStoreBundle/Controller/StoredObjectVersionApiController.php index 819eb9f84..1dbcb6159 100644 --- a/src/Bundle/ChillDocStoreBundle/Controller/StoredObjectVersionApiController.php +++ b/src/Bundle/ChillDocStoreBundle/Controller/StoredObjectVersionApiController.php @@ -59,7 +59,7 @@ final readonly class StoredObjectVersionApiController return new JsonResponse( $this->serializer->serialize( - new Collection($items, $paginator), + new Collection(array_values($items->toArray()), $paginator), 'json', [AbstractNormalizer::GROUPS => ['read', StoredObjectVersionNormalizer::WITH_POINT_IN_TIMES_CONTEXT, StoredObjectVersionNormalizer::WITH_RESTORED_CONTEXT]] ), diff --git a/src/Bundle/ChillDocStoreBundle/Tests/Controller/StoredObjectVersionApiControllerTest.php b/src/Bundle/ChillDocStoreBundle/Tests/Controller/StoredObjectVersionApiControllerTest.php index 27154831d..36d225ddf 100644 --- a/src/Bundle/ChillDocStoreBundle/Tests/Controller/StoredObjectVersionApiControllerTest.php +++ b/src/Bundle/ChillDocStoreBundle/Tests/Controller/StoredObjectVersionApiControllerTest.php @@ -40,6 +40,10 @@ class StoredObjectVersionApiControllerTest extends \PHPUnit\Framework\TestCase $storedObject->registerVersion(); } + // remove one version in the history + $v5 = $storedObject->getVersions()->get(5); + $storedObject->removeVersion($v5); + $security = $this->prophesize(Security::class); $security->isGranted(StoredObjectRoleEnum::SEE->value, $storedObject) ->willReturn(true) @@ -53,6 +57,7 @@ class StoredObjectVersionApiControllerTest extends \PHPUnit\Framework\TestCase self::assertEquals($response->getStatusCode(), 200); self::assertIsArray($body); self::assertArrayHasKey('results', $body); + self::assertIsList($body['results']); self::assertCount(10, $body['results']); }