From 1c64d31cdf3dd61201e181995cbc185caaf36296 Mon Sep 17 00:00:00 2001 From: Dhwani Patel Date: Tue, 26 Sep 2023 15:29:53 -0600 Subject: [PATCH] Fix Drag and drop in Appraisal tab --- .../src/components/filesystem_ajax/views.py | 5 +- src/dashboard/src/main/models.py | 5 +- src/dashboard/tests/test_filesystem_ajax.py | 49 +++++++++++++++++++ 3 files changed, 55 insertions(+), 4 deletions(-) diff --git a/src/dashboard/src/components/filesystem_ajax/views.py b/src/dashboard/src/components/filesystem_ajax/views.py index 073b91ce33..c53b232ad2 100644 --- a/src/dashboard/src/components/filesystem_ajax/views.py +++ b/src/dashboard/src/components/filesystem_ajax/views.py @@ -751,7 +751,6 @@ def _copy_files_to_arrange( ): sourcepath = sourcepath.lstrip("/") # starts with 'originals/', not '/originals/' # Insert each file into the DB - # Lots of error checking: if not sourcepath or not destination: raise ValueError(_("GET parameter 'filepath' or 'destination' was blank.")) @@ -915,8 +914,8 @@ def copy_to_arrange(request, sources=None, destinations=None, fetch_children=Fal for entry in entries: entries_to_copy.append( models.SIPArrange( - original_path=entry["original_path"], - arrange_path=entry["arrange_path"], + original_path=entry["original_path"].encode(), + arrange_path=entry["arrange_path"].encode(), file_uuid=entry["file_uuid"], transfer_uuid=entry["transfer_uuid"], ) diff --git a/src/dashboard/src/main/models.py b/src/dashboard/src/main/models.py index 221818e9c7..47b49abe0b 100644 --- a/src/dashboard/src/main/models.py +++ b/src/dashboard/src/main/models.py @@ -635,7 +635,10 @@ class Meta: def __str__(self): return str( _("%(original)s -> %(arrange)s") - % {"original": self.original_path, "arrange": self.arrange_path} + % { + "original": self.original_path.decode(), + "arrange": self.arrange_path.decode(), + } ) @classmethod diff --git a/src/dashboard/tests/test_filesystem_ajax.py b/src/dashboard/tests/test_filesystem_ajax.py index bb75e7544e..a94bd6df44 100644 --- a/src/dashboard/tests/test_filesystem_ajax.py +++ b/src/dashboard/tests/test_filesystem_ajax.py @@ -230,6 +230,55 @@ def test_move_within_arrange(self): assert b64encode_string("newsip") in response_dict["entries"] assert len(response_dict["entries"]) == 2 + @mock.patch( + "storageService.get_first_location", + return_value={"uuid": "355d110f-b641-4b6b-b1c0-8426e63951e5"}, + ) + @mock.patch( + "storageService.get_file_metadata", + side_effect=[ + [ + { + "fileuuid": "0b603cee-1f8a-4842-996a-e02a0307ccf7", + "sipuuid": "99c87143-6f74-4398-84e0-14a8ca4bd05a", + } + ], + [ + { + "fileuuid": "03a33ef5-8714-46cc-aefe-7283186341ca", + "sipuuid": "4ae7b624-9ba7-452a-adbc-1588223b7098", + } + ], + ], + ) + @mock.patch( + "storageService.browse_location", + return_value={ + "directories": [], + "entries": ["error.txt", "tree_a.txt"], + "properties": { + "error.txt": {"size": 8}, + "tree_a.txt": {"size": 6}, + }, + }, + ) + def test_copy_within_arrange( + self, browse_location, get_file_metadata, get_first_location + ): + # Copy directory + response = self.client.post( + reverse("filesystem_ajax:copy_to_arrange"), + data={ + "filepath": b64encode_string("/originals/objects/"), + "destination": b64encode_string("/arrange/"), + }, + follow=True, + ) + assert response.status_code == 201 + assert json.loads(response.content.decode("utf8")) == { + "message": "Files added to the SIP." + } + def test_copy_from_arrange_to_completed(self): sip_uuid = "a29e7e86-eca9-43b6-b059-6f23a9802dc8" models.SIP.objects.create(uuid=sip_uuid)