Skip to content

Commit dd56a8a

Browse files
committed
🐛(backend) fix trashbin list
Fix listing of deleted documents in trashbin for users without owner access
1 parent 145c688 commit dd56a8a

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to
1515

1616
- 🐛(frontend) fix duplicate document entries in grid #1479
1717
- 🐛(frontend) show full nested doc names with ajustable bar #1456
18+
- 🐛(backend) fix trashbin list
1819

1920
## [3.8.2] - 2025-10-17
2021

src/backend/core/api/viewsets.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,9 @@ def trashbin(self, request, *args, **kwargs):
636636
.values_list("document__path", flat=True)
637637
)
638638

639+
if not access_documents_paths:
640+
return self.get_response_for_queryset(self.queryset.none())
641+
639642
children_clause = db.Q()
640643
for path in access_documents_paths:
641644
children_clause |= db.Q(path__startswith=path)

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,3 +293,29 @@ def test_api_documents_trashbin_distinct():
293293
content = response.json()
294294
assert len(content["results"]) == 1
295295
assert content["results"][0]["id"] == str(document.id)
296+
297+
298+
def test_api_documents_trashbin_empty_queryset_bug():
299+
"""
300+
Test that users with no owner role don't see documents.
301+
"""
302+
# Create a new user with no owner access to any document
303+
new_user = factories.UserFactory()
304+
client = APIClient()
305+
client.force_login(new_user)
306+
307+
# Create some deleted documents owned by other users
308+
other_user = factories.UserFactory()
309+
item1 = factories.DocumentFactory(users=[(other_user, "owner")])
310+
item1.soft_delete()
311+
item2 = factories.DocumentFactory(users=[(other_user, "owner")])
312+
item2.soft_delete()
313+
item3 = factories.DocumentFactory(users=[(other_user, "owner")])
314+
item3.soft_delete()
315+
316+
response = client.get("/api/v1.0/documents/trashbin/")
317+
318+
assert response.status_code == 200
319+
content = response.json()
320+
assert content["count"] == 0
321+
assert len(content["results"]) == 0

0 commit comments

Comments
 (0)