This commit is contained in:
j3d1 2026-08-31 14:41:52 +02:00
parent 4671860fa4
commit 18a3e40435
7 changed files with 43 additions and 11 deletions

View file

@ -33,7 +33,8 @@ def list_all_files(request, format=None):
# request.user is a ToolshedUser here; reach group membership via public_identity.
files = File.objects.select_related().filter(
Q(connected_items__owner=request.user) |
Q(connected_items__owner_group__in=request.user.public_identity.member_of_groups.all())
Q(connected_items__owner_group__in=request.user.public_identity.member_of_groups.all()),
connected_items__is_deleted=False
).distinct()
return Response(FileSerializer(files, many=True).data)

View file

@ -39,6 +39,17 @@ class FileApiTestCase(UserTestMixin, FilesTestMixin, InventoryTestMixin, Toolshe
self.assertEqual(response.json()[1]['name'],
f"/media/{self.f['hash2'][:2]}/{self.f['hash2'][2:4]}/{self.f['hash2'][4:6]}/{self.f['hash2'][6:]}")
def test_list_all_files_excludes_files_only_connected_via_deleted_item(self):
# test_file2 is only reachable through item1; test_file1 is also reachable through item2,
# which stays live. Soft-deleting item1 doesn't sever its files M2M rows, so this would
# regress to listing test_file2 as if it were still owned if the join-based filter ever
# stops excluding soft-deleted items again.
self.f['item1'].delete()
response = client.get(f"/api/v1/files/", self.f['local_user1'])
self.assertEqual(response.status_code, 200)
hashes = [f['hash'] for f in response.json()]
self.assertEqual(hashes, [self.f['hash1']])
def test_files(self):
response = client.get(f"/api/v1/item_files/{self.f['item1'].id}/", self.f['local_user1'])
self.assertEqual(response.status_code, 200)