Repository: liqd/adhocracy4

Issue:
project duplicate functionality with image
**URL:** https://meinberlin-dev.liqd.net/dashboard/projects/fake-project-799/basic/
**user:** moderator/ initiator/admin/
**expected behaviour:** When a project is duplicated, images of the new (duplicated) project are saved correctly
**behaviour:** *Duplicated new project's images are saved with a duplicated file path, e.g instead of `projects/background/image.png`, they are saved as `projects/background/projects/background/image.png`
~**important screensize:** *mobile? desktop?*~
~**device & browser:** *e.g. Desktop, firefox 68.0.2 (64-Bit)*~
**Comment/Question:** *Is this easy to do? What ideas do you have? Would this be a story?* 
![image](https://github.com/liqd/adhocracy4/assets/5695572/cd009432-8aa6-4f9f-b0c6-4320eeda752b)




Discussion:

Resolving patch:
diff --git a/adhocracy4/dashboard/mixins.py b/adhocracy4/dashboard/mixins.py
--- a/adhocracy4/dashboard/mixins.py
+++ b/adhocracy4/dashboard/mixins.py
@@ -167,12 +167,6 @@ def post(self, request, *args, **kwargs):
 
             project_clone = deepcopy(project)
             project_clone.pk = None
-            if project_clone.tile_image:
-                project_clone.tile_image.save(
-                    project.tile_image.name, project.tile_image, False
-                )
-            if project_clone.image:
-                project_clone.image.save(project.image.name, project.image, False)
             project_clone.created = timezone.now()
             project_clone.is_draft = True
             project_clone.is_archived = False


Test patch:
diff --git a/tests/dashboard/test_views.py b/tests/dashboard/test_views.py
--- a/tests/dashboard/test_views.py
+++ b/tests/dashboard/test_views.py
@@ -37,7 +37,6 @@ def test_project_list(client, organisation, project_factory, user, another_user)
 
 @pytest.mark.django_db
 def test_blueprint_list(client, organisation, user, another_user):
-
     blueprint_list_url = reverse(
         "a4dashboard:blueprint-list", kwargs={"organisation_slug": organisation.slug}
     )
@@ -257,9 +256,13 @@ def test_project_publish_redirect(client, project, another_user):
 
 
 @pytest.mark.django_db
-def test_project_duplicate(client, another_user, area_settings, phase_factory):
+def test_project_duplicate(
+    client, another_user, area_settings, phase_factory, image_factory
+):
     module = area_settings.module
     project = module.project
+    test_image = image_factory((1500, 500), "JPEG")
+    test_tile_image = image_factory((300, 150), "JPEG")
     organisation = project.organisation
     organisation.initiators.add(another_user)
     phase = phase_factory(module=module)
@@ -267,6 +270,10 @@ def test_project_duplicate(client, another_user, area_settings, phase_factory):
     project.is_draft = False
     project.is_archived = True
 
+    project.tile_image = test_tile_image
+    project.image = test_image
+    project.save()
+
     project_list_url = reverse(
         "a4dashboard:project-list", kwargs={"organisation_slug": organisation.slug}
     )
@@ -284,6 +291,15 @@ def test_project_duplicate(client, another_user, area_settings, phase_factory):
 
     assert project_clone.is_draft is True
     assert project_clone.is_archived is False
+
+    assert project_clone.image == project.image
+    assert project_clone.image.name == project.image.name
+    assert project_clone.image.path == project.image.path
+
+    assert project_clone.tile_image == project.tile_image
+    assert project_clone.tile_image.name == project.tile_image.name
+    assert project_clone.tile_image.path == project.tile_image.path
+
     assert project_clone.created > project.created
     for attr in ("description", "information", "result", "access"):
         assert getattr(project_clone, attr) == getattr(project, attr)