✨(backend) add creator id field in Item serializer

Added the creator id field to ListItemSerializer and ItemSerializer to
enhance data representation and facilitate access to the creator's
identifier in the serialized output.
This commit is contained in:
Nathan Panchout
2025-09-02 09:41:26 +02:00
committed by Manuel Raynaud
parent 214a912383
commit 027c60214c
9 changed files with 52 additions and 3 deletions
+2 -2
View File
@@ -27,8 +27,8 @@ class UserLiteSerializer(UserSerializer):
class Meta:
model = models.User
fields = ["full_name", "short_name"]
read_only_fields = ["full_name", "short_name"]
fields = ["id", "full_name", "short_name"]
read_only_fields = ["id", "full_name", "short_name"]
class BaseAccessSerializer(serializers.ModelSerializer):
+4 -1
View File
@@ -95,7 +95,10 @@ class ItemUploadStateChoices(models.TextChoices):
PENDING = "pending", _("Pending")
ANALYZING = "analyzing", _("Analyzing")
SUSPICIOUS = "suspicious", _("Suspicious")
FILE_TOO_LARGE_TO_ANALYZE = "file_too_large_to_analyze", _("File too large to analyze")
FILE_TOO_LARGE_TO_ANALYZE = (
"file_too_large_to_analyze",
_("File too large to analyze"),
)
READY = "ready", _("Ready")
@@ -36,6 +36,7 @@ def test_api_items_children_list_anonymous_public_standalone():
"abilities": child1.get_abilities(AnonymousUser()),
"created_at": child1.created_at.isoformat().replace("+00:00", "Z"),
"creator": {
"id": str(child1.creator.id),
"full_name": child1.creator.full_name,
"short_name": child1.creator.short_name,
},
@@ -68,6 +69,7 @@ def test_api_items_children_list_anonymous_public_standalone():
"abilities": child2.get_abilities(AnonymousUser()),
"created_at": child2.created_at.isoformat().replace("+00:00", "Z"),
"creator": {
"id": str(child2.creator.id),
"full_name": child2.creator.full_name,
"short_name": child2.creator.short_name,
},
@@ -139,6 +141,7 @@ def test_api_items_children_list_anonymous_public_parent():
"abilities": child1.get_abilities(AnonymousUser()),
"created_at": child1.created_at.isoformat().replace("+00:00", "Z"),
"creator": {
"id": str(child1.creator.id),
"full_name": child1.creator.full_name,
"short_name": child1.creator.short_name,
},
@@ -169,6 +172,7 @@ def test_api_items_children_list_anonymous_public_parent():
"abilities": child2.get_abilities(AnonymousUser()),
"created_at": child2.created_at.isoformat().replace("+00:00", "Z"),
"creator": {
"id": str(child2.creator.id),
"full_name": child2.creator.full_name,
"short_name": child2.creator.short_name,
},
@@ -251,6 +255,7 @@ def test_api_items_children_list_authenticated_unrelated_public_or_authenticated
"abilities": child1.get_abilities(user),
"created_at": child1.created_at.isoformat().replace("+00:00", "Z"),
"creator": {
"id": str(child1.creator.id),
"full_name": child1.creator.full_name,
"short_name": child1.creator.short_name,
},
@@ -283,6 +288,7 @@ def test_api_items_children_list_authenticated_unrelated_public_or_authenticated
"abilities": child2.get_abilities(user),
"created_at": child2.created_at.isoformat().replace("+00:00", "Z"),
"creator": {
"id": str(child2.creator.id),
"full_name": child2.creator.full_name,
"short_name": child2.creator.short_name,
},
@@ -352,6 +358,7 @@ def test_api_items_children_list_authenticated_public_or_authenticated_parent(
"abilities": child1.get_abilities(user),
"created_at": child1.created_at.isoformat().replace("+00:00", "Z"),
"creator": {
"id": str(child1.creator.id),
"full_name": child1.creator.full_name,
"short_name": child1.creator.short_name,
},
@@ -384,6 +391,7 @@ def test_api_items_children_list_authenticated_public_or_authenticated_parent(
"abilities": child2.get_abilities(user),
"created_at": child2.created_at.isoformat().replace("+00:00", "Z"),
"creator": {
"id": str(child2.creator.id),
"full_name": child2.creator.full_name,
"short_name": child2.creator.short_name,
},
@@ -478,6 +486,7 @@ def test_api_items_children_list_authenticated_related_direct():
"abilities": child1.get_abilities(user),
"created_at": child1.created_at.isoformat().replace("+00:00", "Z"),
"creator": {
"id": str(child1.creator.id),
"full_name": child1.creator.full_name,
"short_name": child1.creator.short_name,
},
@@ -510,6 +519,7 @@ def test_api_items_children_list_authenticated_related_direct():
"abilities": child2.get_abilities(user),
"created_at": child2.created_at.isoformat().replace("+00:00", "Z"),
"creator": {
"id": str(child2.creator.id),
"full_name": child2.creator.full_name,
"short_name": child2.creator.short_name,
},
@@ -580,6 +590,7 @@ def test_api_items_children_list_authenticated_related_parent():
"abilities": child1.get_abilities(user),
"created_at": child1.created_at.isoformat().replace("+00:00", "Z"),
"creator": {
"id": str(child1.creator.id),
"full_name": child1.creator.full_name,
"short_name": child1.creator.short_name,
},
@@ -612,6 +623,7 @@ def test_api_items_children_list_authenticated_related_parent():
"abilities": child2.get_abilities(user),
"created_at": child2.created_at.isoformat().replace("+00:00", "Z"),
"creator": {
"id": str(child2.creator.id),
"full_name": child2.creator.full_name,
"short_name": child2.creator.short_name,
},
@@ -745,6 +757,7 @@ def test_api_items_children_list_authenticated_related_team_members(
"abilities": child1.get_abilities(user),
"created_at": child1.created_at.isoformat().replace("+00:00", "Z"),
"creator": {
"id": str(child1.creator.id),
"full_name": child1.creator.full_name,
"short_name": child1.creator.short_name,
},
@@ -777,6 +790,7 @@ def test_api_items_children_list_authenticated_related_team_members(
"abilities": child2.get_abilities(user),
"created_at": child2.created_at.isoformat().replace("+00:00", "Z"),
"creator": {
"id": str(child2.creator.id),
"full_name": child2.creator.full_name,
"short_name": child2.creator.short_name,
},
@@ -843,6 +857,7 @@ def test_api_items_children_list_filter_type():
"abilities": child1.get_abilities(user),
"created_at": child1.created_at.isoformat().replace("+00:00", "Z"),
"creator": {
"id": str(child1.creator.id),
"full_name": child1.creator.full_name,
"short_name": child1.creator.short_name,
},
@@ -888,6 +903,7 @@ def test_api_items_children_list_filter_type():
"abilities": child2.get_abilities(user),
"created_at": child2.created_at.isoformat().replace("+00:00", "Z"),
"creator": {
"id": str(child2.creator.id),
"full_name": child2.creator.full_name,
"short_name": child2.creator.short_name,
},
@@ -69,6 +69,7 @@ def test_api_item_favorite_list_authenticated_with_favorite():
"abilities": item.get_abilities(user),
"created_at": item.created_at.isoformat().replace("+00:00", "Z"),
"creator": {
"id": str(item.creator.id),
"full_name": item.creator.full_name,
"short_name": item.creator.short_name,
},
@@ -88,6 +88,7 @@ def test_api_items_list_format():
"abilities": item2.get_abilities(user),
"created_at": item2.created_at.isoformat().replace("+00:00", "Z"),
"creator": {
"id": str(item2.creator.id),
"full_name": item2.creator.full_name,
"short_name": item2.creator.short_name,
},
@@ -118,6 +119,7 @@ def test_api_items_list_format():
"abilities": item.get_abilities(user),
"created_at": item.created_at.isoformat().replace("+00:00", "Z"),
"creator": {
"id": str(item.creator.id),
"full_name": item.creator.full_name,
"short_name": item.creator.short_name,
},
@@ -148,6 +150,7 @@ def test_api_items_list_format():
"abilities": item3.get_abilities(user),
"created_at": item3.created_at.isoformat().replace("+00:00", "Z"),
"creator": {
"id": str(item3.creator.id),
"full_name": item3.creator.full_name,
"short_name": item3.creator.short_name,
},
@@ -220,6 +220,7 @@ def test_api_items_list_filter_is_creator_me_true():
# Ensure all results are created by the current user
for result in results:
assert result["creator"] == {
"id": str(user.id),
"full_name": user.full_name,
"short_name": user.short_name,
}
@@ -245,6 +246,7 @@ def test_api_items_list_filter_is_creator_me_false():
# Ensure all results are created by other users
for result in results:
assert result["creator"] != {
"id": str(user.id),
"full_name": user.full_name,
"short_name": user.short_name,
}
@@ -29,6 +29,7 @@ def test_api_items_retrieve_anonymous_public_standalone():
"abilities": item.get_abilities(AnonymousUser()),
"created_at": item.created_at.isoformat().replace("+00:00", "Z"),
"creator": {
"id": str(item.creator.id),
"full_name": item.creator.full_name,
"short_name": item.creator.short_name,
},
@@ -80,6 +81,7 @@ def test_api_items_retrieve_anonymous_public_parent():
"abilities": item.get_abilities(AnonymousUser()),
"created_at": item.created_at.isoformat().replace("+00:00", "Z"),
"creator": {
"id": str(item.creator.id),
"full_name": item.creator.full_name,
"short_name": item.creator.short_name,
},
@@ -176,6 +178,7 @@ def test_api_items_retrieve_authenticated_unrelated_public_or_authenticated(reac
"abilities": item.get_abilities(user),
"created_at": item.created_at.isoformat().replace("+00:00", "Z"),
"creator": {
"id": str(item.creator.id),
"full_name": item.creator.full_name,
"short_name": item.creator.short_name,
},
@@ -233,6 +236,7 @@ def test_api_items_retrieve_authenticated_public_or_authenticated_parent(reach):
"abilities": item.get_abilities(user),
"created_at": item.created_at.isoformat().replace("+00:00", "Z"),
"creator": {
"id": str(item.creator.id),
"full_name": item.creator.full_name,
"short_name": item.creator.short_name,
},
@@ -367,6 +371,7 @@ def test_api_items_retrieve_authenticated_related_direct():
"id": str(item.id),
"abilities": item.get_abilities(user),
"creator": {
"id": str(item.creator.id),
"full_name": item.creator.full_name,
"short_name": item.creator.short_name,
},
@@ -426,6 +431,7 @@ def test_api_items_retrieve_authenticated_related_parent():
"id": str(item.id),
"abilities": item.get_abilities(user),
"creator": {
"id": str(item.creator.id),
"full_name": item.creator.full_name,
"short_name": item.creator.short_name,
},
@@ -604,6 +610,7 @@ def test_api_items_retrieve_authenticated_related_team_members(
"abilities": item.get_abilities(user),
"created_at": item.created_at.isoformat().replace("+00:00", "Z"),
"creator": {
"id": str(item.creator.id),
"full_name": item.creator.full_name,
"short_name": item.creator.short_name,
},
@@ -675,6 +682,7 @@ def test_api_items_retrieve_authenticated_related_team_administrators(
"abilities": item.get_abilities(user),
"created_at": item.created_at.isoformat().replace("+00:00", "Z"),
"creator": {
"id": str(item.creator.id),
"full_name": item.creator.full_name,
"short_name": item.creator.short_name,
},
@@ -746,6 +754,7 @@ def test_api_items_retrieve_authenticated_related_team_owners(
"abilities": item.get_abilities(user),
"created_at": item.created_at.isoformat().replace("+00:00", "Z"),
"creator": {
"id": str(item.creator.id),
"full_name": item.creator.full_name,
"short_name": item.creator.short_name,
},
@@ -1111,6 +1120,7 @@ def test_api_items_retrieve_file_with_url_property(upload_state):
"abilities": item.get_abilities(user),
"created_at": item.created_at.isoformat().replace("+00:00", "Z"),
"creator": {
"id": str(item.creator.id),
"full_name": item.creator.full_name,
"short_name": item.creator.short_name,
},
@@ -67,6 +67,7 @@ def test_api_items_trashbin_format(settings):
"created_at": item.created_at.isoformat().replace("+00:00", "Z"),
"deleted_at": item.deleted_at.isoformat().replace("+00:00", "Z"),
"creator": {
"id": str(item.creator.id),
"full_name": item.creator.full_name,
"short_name": item.creator.short_name,
},
@@ -143,6 +143,7 @@ def test_items_api_anonymous_to_a_public_tree_structure():
"children": [],
"created_at": level2_1.created_at.isoformat().replace("+00:00", "Z"),
"creator": {
"id": str(level2_1.creator.id),
"full_name": level2_1.creator.full_name,
"short_name": level2_1.creator.short_name,
},
@@ -174,6 +175,7 @@ def test_items_api_anonymous_to_a_public_tree_structure():
"children": [],
"created_at": level2_2.created_at.isoformat().replace("+00:00", "Z"),
"creator": {
"id": str(level2_2.creator.id),
"full_name": level2_2.creator.full_name,
"short_name": level2_2.creator.short_name,
},
@@ -203,6 +205,7 @@ def test_items_api_anonymous_to_a_public_tree_structure():
],
"created_at": level1_2.created_at.isoformat().replace("+00:00", "Z"),
"creator": {
"id": str(level1_2.creator.id),
"full_name": level1_2.creator.full_name,
"short_name": level1_2.creator.short_name,
},
@@ -348,6 +351,7 @@ def test_items_api_tree_authenticated_direct_access(django_assert_num_queries):
"+00:00", "Z"
),
"creator": {
"id": str(level2_1.item.creator.id),
"full_name": level2_1.item.creator.full_name,
"short_name": level2_1.item.creator.short_name,
},
@@ -386,6 +390,7 @@ def test_items_api_tree_authenticated_direct_access(django_assert_num_queries):
"+00:00", "Z"
),
"creator": {
"id": str(level3_1.item.creator.id),
"full_name": level3_1.item.creator.full_name,
"short_name": level3_1.item.creator.short_name,
},
@@ -422,6 +427,7 @@ def test_items_api_tree_authenticated_direct_access(django_assert_num_queries):
"+00:00", "Z"
),
"creator": {
"id": str(level2_2.item.creator.id),
"full_name": level2_2.item.creator.full_name,
"short_name": level2_2.item.creator.short_name,
},
@@ -455,6 +461,7 @@ def test_items_api_tree_authenticated_direct_access(django_assert_num_queries):
"+00:00", "Z"
),
"creator": {
"id": str(level1_1.item.creator.id),
"full_name": level1_1.item.creator.full_name,
"short_name": level1_1.item.creator.short_name,
},
@@ -490,6 +497,7 @@ def test_items_api_tree_authenticated_direct_access(django_assert_num_queries):
"+00:00", "Z"
),
"creator": {
"id": str(level1_2.item.creator.id),
"full_name": level1_2.item.creator.full_name,
"short_name": level1_2.item.creator.short_name,
},
@@ -525,6 +533,7 @@ def test_items_api_tree_authenticated_direct_access(django_assert_num_queries):
"+00:00", "Z"
),
"creator": {
"id": str(level1_3.item.creator.id),
"full_name": level1_3.item.creator.full_name,
"short_name": level1_3.item.creator.short_name,
},
@@ -556,6 +565,7 @@ def test_items_api_tree_authenticated_direct_access(django_assert_num_queries):
],
"created_at": root.item.created_at.isoformat().replace("+00:00", "Z"),
"creator": {
"id": str(root.item.creator.id),
"full_name": root.item.creator.full_name,
"short_name": root.item.creator.short_name,
},
@@ -668,6 +678,7 @@ def test_api_items_tree_authenticated_with_access_authenticated():
assert response.json() == {
"created_at": level1_1.created_at.isoformat().replace("+00:00", "Z"),
"creator": {
"id": str(level1_1.creator.id),
"full_name": level1_1.creator.full_name,
"short_name": level1_1.creator.short_name,
},
@@ -700,6 +711,7 @@ def test_api_items_tree_authenticated_with_access_authenticated():
"children": [],
"created_at": level2_1.created_at.isoformat().replace("+00:00", "Z"),
"creator": {
"id": str(level2_1.creator.id),
"full_name": level2_1.creator.full_name,
"short_name": level2_1.creator.short_name,
},
@@ -731,6 +743,7 @@ def test_api_items_tree_authenticated_with_access_authenticated():
"children": [],
"created_at": level2_2.created_at.isoformat().replace("+00:00", "Z"),
"creator": {
"id": str(level2_2.creator.id),
"full_name": level2_2.creator.full_name,
"short_name": level2_2.creator.short_name,
},