From e463b3daba0e5e981667ce23ff79abbe06d93be1 Mon Sep 17 00:00:00 2001 From: Samuel Paccoud - DINUM Date: Thu, 7 Aug 2025 18:08:43 +0200 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F(schema)=20stop=20forcing=20u?= =?UTF-8?q?sers=20to=20be=20uuid=20(represented=20by=20a=20sub)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The list of users allowed to access a document is a sub and is not guaranteed to be a UUID. --- src/backend/core/factories.py | 4 ++-- src/backend/core/schemas.py | 2 +- src/backend/core/tests/test_api_documents_index_bulk.py | 9 +++------ .../core/tests/test_api_documents_index_single.py | 9 +++------ 4 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/backend/core/factories.py b/src/backend/core/factories.py index f1e701d..fb0f7c0 100644 --- a/src/backend/core/factories.py +++ b/src/backend/core/factories.py @@ -19,7 +19,7 @@ class DocumentSchemaFactory(factory.DictFactory): indexation for testing and development purposes. """ - id = factory.LazyFunction(uuid4) + id = factory.LazyFunction(lambda: str(uuid4())) title = factory.Sequence(lambda n: f"Test title {n!s}") path = factory.Sequence(lambda n: f"000{n}") content = factory.Sequence(lambda n: f"Test content {n!s}") @@ -27,7 +27,7 @@ class DocumentSchemaFactory(factory.DictFactory): lambda: fake.date_time_this_decade(tzinfo=timezone.get_current_timezone()) ) size = factory.LazyFunction(lambda: fake.random_int(min=0, max=1024**2)) - users = factory.LazyFunction(lambda: [uuid4() for _ in range(3)]) + users = factory.LazyFunction(lambda: [str(uuid4()) for _ in range(3)]) groups = factory.LazyFunction(lambda: [slugify(fake.word()) for _ in range(3)]) reach = factory.Iterator(list(enums.ReachEnum)) depth = 1 diff --git a/src/backend/core/schemas.py b/src/backend/core/schemas.py index 9ed4374..1db6d1a 100644 --- a/src/backend/core/schemas.py +++ b/src/backend/core/schemas.py @@ -31,7 +31,7 @@ class DocumentSchema(BaseModel): created_at: AwareDatetime updated_at: AwareDatetime size: Annotated[int, Field(ge=0, le=100 * 1024**3)] # File size limited to 100GB - users: List[UUID4] = Field(default_factory=list) + users: List[Annotated[str, Field(max_length=50)]] = Field(default_factory=list) groups: List[Annotated[str, Field(pattern=r"^[a-z0-9]+(?:-[a-z0-9]+)*$")]] = Field( default_factory=list ) diff --git a/src/backend/core/tests/test_api_documents_index_bulk.py b/src/backend/core/tests/test_api_documents_index_bulk.py index f57e742..13ad656 100644 --- a/src/backend/core/tests/test_api_documents_index_bulk.py +++ b/src/backend/core/tests/test_api_documents_index_bulk.py @@ -140,12 +140,9 @@ def test_api_documents_index_bulk_success(): ), ( "users", - ["33052c8b-3181-4420-aede-f8396fc0f9az"], # invalid UUID b/c contains a z - "uuid_parsing", - ( - "Input should be a valid UUID, invalid character: expected an optional " - "prefix of `urn:uuid:` followed by [0-9a-fA-F-], found `z` at 36" - ), + ["a" * 51], + "string_too_long", + "String should have at most 50 characters", ), ( "groups", diff --git a/src/backend/core/tests/test_api_documents_index_single.py b/src/backend/core/tests/test_api_documents_index_single.py index eed0a04..67a5405 100644 --- a/src/backend/core/tests/test_api_documents_index_single.py +++ b/src/backend/core/tests/test_api_documents_index_single.py @@ -137,12 +137,9 @@ def test_api_documents_index_single_success(): ), ( "users", - ["33052c8b-3181-4420-aede-f8396fc0f9az"], # invalid UUID b/c contains a z* - "uuid_parsing", - ( - "Input should be a valid UUID, invalid character: expected an optional " - "prefix of `urn:uuid:` followed by [0-9a-fA-F-], found `z` at 36" - ), + ["a" * 51], + "string_too_long", + "String should have at most 50 characters", ), ( "groups",