Skip to content

Commit 390a615

Browse files
lunikaAntoLC
authored andcommitted
✨(backend) expose deleted_at information in serializer
The front needs to know when a document has been deleted. We expose the deleted_at property on a document object,
1 parent 5bdf5d2 commit 390a615

9 files changed

+93
-2
lines changed

src/backend/core/api/serializers.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class ListDocumentSerializer(serializers.ModelSerializer):
9090
nb_accesses_direct = serializers.IntegerField(read_only=True)
9191
user_role = serializers.SerializerMethodField(read_only=True)
9292
abilities = serializers.SerializerMethodField(read_only=True)
93+
deleted_at = serializers.SerializerMethodField(read_only=True)
9394

9495
class Meta:
9596
model = models.Document
@@ -102,6 +103,7 @@ class Meta:
102103
"computed_link_role",
103104
"created_at",
104105
"creator",
106+
"deleted_at",
105107
"depth",
106108
"excerpt",
107109
"is_favorite",
@@ -124,6 +126,7 @@ class Meta:
124126
"computed_link_role",
125127
"created_at",
126128
"creator",
129+
"deleted_at",
127130
"depth",
128131
"excerpt",
129132
"is_favorite",
@@ -165,6 +168,10 @@ def get_user_role(self, instance):
165168
request = self.context.get("request")
166169
return instance.get_role(request.user) if request else None
167170

171+
def get_deleted_at(self, instance):
172+
"""Return the deleted_at of the current document."""
173+
return instance.ancestors_deleted_at
174+
168175

169176
class DocumentLightSerializer(serializers.ModelSerializer):
170177
"""Minial document serializer for nesting in document accesses."""
@@ -193,6 +200,7 @@ class Meta:
193200
"content",
194201
"created_at",
195202
"creator",
203+
"deleted_at",
196204
"depth",
197205
"excerpt",
198206
"is_favorite",
@@ -216,6 +224,7 @@ class Meta:
216224
"computed_link_role",
217225
"created_at",
218226
"creator",
227+
"deleted_at",
219228
"depth",
220229
"is_favorite",
221230
"link_role",

src/backend/core/api/viewsets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2157,7 +2157,7 @@ def get(self, request):
21572157
"LANGUAGES",
21582158
"LANGUAGE_CODE",
21592159
"SENTRY_DSN",
2160-
"TRASHBIN_CUTOFF_DAYS"
2160+
"TRASHBIN_CUTOFF_DAYS",
21612161
]
21622162
dict_settings = {}
21632163
for setting in array_settings:

src/backend/core/tests/documents/test_api_documents_children_list.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def test_api_documents_children_list_anonymous_public_standalone(
4141
"computed_link_role": child1.computed_link_role,
4242
"created_at": child1.created_at.isoformat().replace("+00:00", "Z"),
4343
"creator": str(child1.creator.id),
44+
"deleted_at": None,
4445
"depth": 2,
4546
"excerpt": child1.excerpt,
4647
"id": str(child1.id),
@@ -63,6 +64,7 @@ def test_api_documents_children_list_anonymous_public_standalone(
6364
"computed_link_role": child2.computed_link_role,
6465
"created_at": child2.created_at.isoformat().replace("+00:00", "Z"),
6566
"creator": str(child2.creator.id),
67+
"deleted_at": None,
6668
"depth": 2,
6769
"excerpt": child2.excerpt,
6870
"id": str(child2.id),
@@ -115,6 +117,7 @@ def test_api_documents_children_list_anonymous_public_parent(django_assert_num_q
115117
"computed_link_role": child1.computed_link_role,
116118
"created_at": child1.created_at.isoformat().replace("+00:00", "Z"),
117119
"creator": str(child1.creator.id),
120+
"deleted_at": None,
118121
"depth": 4,
119122
"excerpt": child1.excerpt,
120123
"id": str(child1.id),
@@ -137,6 +140,7 @@ def test_api_documents_children_list_anonymous_public_parent(django_assert_num_q
137140
"computed_link_role": child2.computed_link_role,
138141
"created_at": child2.created_at.isoformat().replace("+00:00", "Z"),
139142
"creator": str(child2.creator.id),
143+
"deleted_at": None,
140144
"depth": 4,
141145
"excerpt": child2.excerpt,
142146
"id": str(child2.id),
@@ -208,6 +212,7 @@ def test_api_documents_children_list_authenticated_unrelated_public_or_authentic
208212
"computed_link_role": child1.computed_link_role,
209213
"created_at": child1.created_at.isoformat().replace("+00:00", "Z"),
210214
"creator": str(child1.creator.id),
215+
"deleted_at": None,
211216
"depth": 2,
212217
"excerpt": child1.excerpt,
213218
"id": str(child1.id),
@@ -230,6 +235,7 @@ def test_api_documents_children_list_authenticated_unrelated_public_or_authentic
230235
"computed_link_role": child2.computed_link_role,
231236
"created_at": child2.created_at.isoformat().replace("+00:00", "Z"),
232237
"creator": str(child2.creator.id),
238+
"deleted_at": None,
233239
"depth": 2,
234240
"excerpt": child2.excerpt,
235241
"id": str(child2.id),
@@ -287,6 +293,7 @@ def test_api_documents_children_list_authenticated_public_or_authenticated_paren
287293
"computed_link_role": child1.computed_link_role,
288294
"created_at": child1.created_at.isoformat().replace("+00:00", "Z"),
289295
"creator": str(child1.creator.id),
296+
"deleted_at": None,
290297
"depth": 4,
291298
"excerpt": child1.excerpt,
292299
"id": str(child1.id),
@@ -309,6 +316,7 @@ def test_api_documents_children_list_authenticated_public_or_authenticated_paren
309316
"computed_link_role": child2.computed_link_role,
310317
"created_at": child2.created_at.isoformat().replace("+00:00", "Z"),
311318
"creator": str(child2.creator.id),
319+
"deleted_at": None,
312320
"depth": 4,
313321
"excerpt": child2.excerpt,
314322
"id": str(child2.id),
@@ -393,6 +401,7 @@ def test_api_documents_children_list_authenticated_related_direct(
393401
"computed_link_role": child1.computed_link_role,
394402
"created_at": child1.created_at.isoformat().replace("+00:00", "Z"),
395403
"creator": str(child1.creator.id),
404+
"deleted_at": None,
396405
"depth": 2,
397406
"excerpt": child1.excerpt,
398407
"id": str(child1.id),
@@ -415,6 +424,7 @@ def test_api_documents_children_list_authenticated_related_direct(
415424
"computed_link_role": child2.computed_link_role,
416425
"created_at": child2.created_at.isoformat().replace("+00:00", "Z"),
417426
"creator": str(child2.creator.id),
427+
"deleted_at": None,
418428
"depth": 2,
419429
"excerpt": child2.excerpt,
420430
"id": str(child2.id),
@@ -475,6 +485,7 @@ def test_api_documents_children_list_authenticated_related_parent(
475485
"computed_link_role": child1.computed_link_role,
476486
"created_at": child1.created_at.isoformat().replace("+00:00", "Z"),
477487
"creator": str(child1.creator.id),
488+
"deleted_at": None,
478489
"depth": 4,
479490
"excerpt": child1.excerpt,
480491
"id": str(child1.id),
@@ -497,6 +508,7 @@ def test_api_documents_children_list_authenticated_related_parent(
497508
"computed_link_role": child2.computed_link_role,
498509
"created_at": child2.created_at.isoformat().replace("+00:00", "Z"),
499510
"creator": str(child2.creator.id),
511+
"deleted_at": None,
500512
"depth": 4,
501513
"excerpt": child2.excerpt,
502514
"id": str(child2.id),
@@ -609,6 +621,7 @@ def test_api_documents_children_list_authenticated_related_team_members(
609621
"computed_link_role": child1.computed_link_role,
610622
"created_at": child1.created_at.isoformat().replace("+00:00", "Z"),
611623
"creator": str(child1.creator.id),
624+
"deleted_at": None,
612625
"depth": 2,
613626
"excerpt": child1.excerpt,
614627
"id": str(child1.id),
@@ -631,6 +644,7 @@ def test_api_documents_children_list_authenticated_related_team_members(
631644
"computed_link_role": child2.computed_link_role,
632645
"created_at": child2.created_at.isoformat().replace("+00:00", "Z"),
633646
"creator": str(child2.creator.id),
647+
"deleted_at": None,
634648
"depth": 2,
635649
"excerpt": child2.excerpt,
636650
"id": str(child2.id),

src/backend/core/tests/documents/test_api_documents_descendants.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def test_api_documents_descendants_list_anonymous_public_standalone():
3838
"computed_link_role": child1.computed_link_role,
3939
"created_at": child1.created_at.isoformat().replace("+00:00", "Z"),
4040
"creator": str(child1.creator.id),
41+
"deleted_at": None,
4142
"depth": 2,
4243
"excerpt": child1.excerpt,
4344
"id": str(child1.id),
@@ -62,6 +63,7 @@ def test_api_documents_descendants_list_anonymous_public_standalone():
6263
"computed_link_role": grand_child.computed_link_role,
6364
"created_at": grand_child.created_at.isoformat().replace("+00:00", "Z"),
6465
"creator": str(grand_child.creator.id),
66+
"deleted_at": None,
6567
"depth": 3,
6668
"excerpt": grand_child.excerpt,
6769
"id": str(grand_child.id),
@@ -84,6 +86,7 @@ def test_api_documents_descendants_list_anonymous_public_standalone():
8486
"computed_link_role": child2.computed_link_role,
8587
"created_at": child2.created_at.isoformat().replace("+00:00", "Z"),
8688
"creator": str(child2.creator.id),
89+
"deleted_at": None,
8790
"depth": 2,
8891
"excerpt": child2.excerpt,
8992
"id": str(child2.id),
@@ -135,6 +138,7 @@ def test_api_documents_descendants_list_anonymous_public_parent():
135138
"computed_link_role": child1.computed_link_role,
136139
"created_at": child1.created_at.isoformat().replace("+00:00", "Z"),
137140
"creator": str(child1.creator.id),
141+
"deleted_at": None,
138142
"depth": 4,
139143
"excerpt": child1.excerpt,
140144
"id": str(child1.id),
@@ -157,6 +161,7 @@ def test_api_documents_descendants_list_anonymous_public_parent():
157161
"computed_link_role": grand_child.computed_link_role,
158162
"created_at": grand_child.created_at.isoformat().replace("+00:00", "Z"),
159163
"creator": str(grand_child.creator.id),
164+
"deleted_at": None,
160165
"depth": 5,
161166
"excerpt": grand_child.excerpt,
162167
"id": str(grand_child.id),
@@ -179,6 +184,7 @@ def test_api_documents_descendants_list_anonymous_public_parent():
179184
"computed_link_role": child2.computed_link_role,
180185
"created_at": child2.created_at.isoformat().replace("+00:00", "Z"),
181186
"creator": str(child2.creator.id),
187+
"deleted_at": None,
182188
"depth": 4,
183189
"excerpt": child2.excerpt,
184190
"id": str(child2.id),
@@ -251,6 +257,7 @@ def test_api_documents_descendants_list_authenticated_unrelated_public_or_authen
251257
"computed_link_role": child1.computed_link_role,
252258
"created_at": child1.created_at.isoformat().replace("+00:00", "Z"),
253259
"creator": str(child1.creator.id),
260+
"deleted_at": None,
254261
"depth": 2,
255262
"excerpt": child1.excerpt,
256263
"id": str(child1.id),
@@ -273,6 +280,7 @@ def test_api_documents_descendants_list_authenticated_unrelated_public_or_authen
273280
"computed_link_role": grand_child.computed_link_role,
274281
"created_at": grand_child.created_at.isoformat().replace("+00:00", "Z"),
275282
"creator": str(grand_child.creator.id),
283+
"deleted_at": None,
276284
"depth": 3,
277285
"excerpt": grand_child.excerpt,
278286
"id": str(grand_child.id),
@@ -295,6 +303,7 @@ def test_api_documents_descendants_list_authenticated_unrelated_public_or_authen
295303
"computed_link_role": child2.computed_link_role,
296304
"created_at": child2.created_at.isoformat().replace("+00:00", "Z"),
297305
"creator": str(child2.creator.id),
306+
"deleted_at": None,
298307
"depth": 2,
299308
"excerpt": child2.excerpt,
300309
"id": str(child2.id),
@@ -352,6 +361,7 @@ def test_api_documents_descendants_list_authenticated_public_or_authenticated_pa
352361
"computed_link_role": child1.computed_link_role,
353362
"created_at": child1.created_at.isoformat().replace("+00:00", "Z"),
354363
"creator": str(child1.creator.id),
364+
"deleted_at": None,
355365
"depth": 4,
356366
"excerpt": child1.excerpt,
357367
"id": str(child1.id),
@@ -374,6 +384,7 @@ def test_api_documents_descendants_list_authenticated_public_or_authenticated_pa
374384
"computed_link_role": grand_child.computed_link_role,
375385
"created_at": grand_child.created_at.isoformat().replace("+00:00", "Z"),
376386
"creator": str(grand_child.creator.id),
387+
"deleted_at": None,
377388
"depth": 5,
378389
"excerpt": grand_child.excerpt,
379390
"id": str(grand_child.id),
@@ -396,6 +407,7 @@ def test_api_documents_descendants_list_authenticated_public_or_authenticated_pa
396407
"computed_link_role": child2.computed_link_role,
397408
"created_at": child2.created_at.isoformat().replace("+00:00", "Z"),
398409
"creator": str(child2.creator.id),
410+
"deleted_at": None,
399411
"depth": 4,
400412
"excerpt": child2.excerpt,
401413
"id": str(child2.id),
@@ -474,6 +486,7 @@ def test_api_documents_descendants_list_authenticated_related_direct():
474486
"computed_link_role": child1.computed_link_role,
475487
"created_at": child1.created_at.isoformat().replace("+00:00", "Z"),
476488
"creator": str(child1.creator.id),
489+
"deleted_at": None,
477490
"depth": 2,
478491
"excerpt": child1.excerpt,
479492
"id": str(child1.id),
@@ -496,6 +509,7 @@ def test_api_documents_descendants_list_authenticated_related_direct():
496509
"computed_link_role": grand_child.computed_link_role,
497510
"created_at": grand_child.created_at.isoformat().replace("+00:00", "Z"),
498511
"creator": str(grand_child.creator.id),
512+
"deleted_at": None,
499513
"depth": 3,
500514
"excerpt": grand_child.excerpt,
501515
"id": str(grand_child.id),
@@ -518,6 +532,7 @@ def test_api_documents_descendants_list_authenticated_related_direct():
518532
"computed_link_role": child2.computed_link_role,
519533
"created_at": child2.created_at.isoformat().replace("+00:00", "Z"),
520534
"creator": str(child2.creator.id),
535+
"deleted_at": None,
521536
"depth": 2,
522537
"excerpt": child2.excerpt,
523538
"id": str(child2.id),
@@ -576,6 +591,7 @@ def test_api_documents_descendants_list_authenticated_related_parent():
576591
"computed_link_role": child1.computed_link_role,
577592
"created_at": child1.created_at.isoformat().replace("+00:00", "Z"),
578593
"creator": str(child1.creator.id),
594+
"deleted_at": None,
579595
"depth": 4,
580596
"excerpt": child1.excerpt,
581597
"id": str(child1.id),
@@ -598,6 +614,7 @@ def test_api_documents_descendants_list_authenticated_related_parent():
598614
"computed_link_role": grand_child.computed_link_role,
599615
"created_at": grand_child.created_at.isoformat().replace("+00:00", "Z"),
600616
"creator": str(grand_child.creator.id),
617+
"deleted_at": None,
601618
"depth": 5,
602619
"excerpt": grand_child.excerpt,
603620
"id": str(grand_child.id),
@@ -620,6 +637,7 @@ def test_api_documents_descendants_list_authenticated_related_parent():
620637
"computed_link_role": child2.computed_link_role,
621638
"created_at": child2.created_at.isoformat().replace("+00:00", "Z"),
622639
"creator": str(child2.creator.id),
640+
"deleted_at": None,
623641
"depth": 4,
624642
"excerpt": child2.excerpt,
625643
"id": str(child2.id),
@@ -724,6 +742,7 @@ def test_api_documents_descendants_list_authenticated_related_team_members(
724742
"computed_link_role": child1.computed_link_role,
725743
"created_at": child1.created_at.isoformat().replace("+00:00", "Z"),
726744
"creator": str(child1.creator.id),
745+
"deleted_at": None,
727746
"depth": 2,
728747
"excerpt": child1.excerpt,
729748
"id": str(child1.id),
@@ -746,6 +765,7 @@ def test_api_documents_descendants_list_authenticated_related_team_members(
746765
"computed_link_role": grand_child.computed_link_role,
747766
"created_at": grand_child.created_at.isoformat().replace("+00:00", "Z"),
748767
"creator": str(grand_child.creator.id),
768+
"deleted_at": None,
749769
"depth": 3,
750770
"excerpt": grand_child.excerpt,
751771
"id": str(grand_child.id),
@@ -768,6 +788,7 @@ def test_api_documents_descendants_list_authenticated_related_team_members(
768788
"computed_link_role": child2.computed_link_role,
769789
"created_at": child2.created_at.isoformat().replace("+00:00", "Z"),
770790
"creator": str(child2.creator.id),
791+
"deleted_at": None,
771792
"depth": 2,
772793
"excerpt": child2.excerpt,
773794
"id": str(child2.id),

src/backend/core/tests/documents/test_api_documents_favorite_list.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def test_api_document_favorite_list_authenticated_with_favorite():
6565
"computed_link_role": document.computed_link_role,
6666
"created_at": document.created_at.isoformat().replace("+00:00", "Z"),
6767
"creator": str(document.creator.id),
68+
"deleted_at": None,
6869
"content": document.content,
6970
"depth": document.depth,
7071
"excerpt": document.excerpt,

src/backend/core/tests/documents/test_api_documents_list.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def test_api_documents_list_format():
6969
"computed_link_role": document.computed_link_role,
7070
"created_at": document.created_at.isoformat().replace("+00:00", "Z"),
7171
"creator": str(document.creator.id),
72+
"deleted_at": None,
7273
"depth": 1,
7374
"excerpt": document.excerpt,
7475
"is_favorite": True,

0 commit comments

Comments
 (0)