Skip to content

Commit

Permalink
[#3378] Fixed form logic trigger_from_step for copied form
Browse files Browse the repository at this point in the history
Backport-of: #3478
  • Loading branch information
vaszig authored and sergei-maertens committed Sep 18, 2023
1 parent 745eceb commit 361dc2d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/openforms/forms/models/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,10 +411,16 @@ def copy(self):

form_step.save()

for logic in self.formlogic_set.all():
for logic in self.formlogic_set.all().select_related("trigger_from_step"):
logic.pk = None
logic.uuid = _uuid.uuid4()
logic.form = copy

if logic.trigger_from_step:
logic.trigger_from_step = logic.form.formstep_set.get(
order=logic.trigger_from_step.order
)

logic.save()

FormVariable.objects.create_for_form(copy)
Expand Down
19 changes: 19 additions & 0 deletions src/openforms/forms/tests/admin/test_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,25 @@ def test_form_admin_copy(self):
copied_form.confirmation_email_template.id, confirmation_email_template.id
)

@tag("gh-3378")
def test_copy_form_with_trigger_from_step_in_logic(self):
user = SuperUserFactory.create()
self.client.force_login(user)

form_step = FormStepFactory.create()
FormLogicFactory.create(form=form_step.form, trigger_from_step=form_step)

admin_url = reverse("admin:forms_form_change", args=(form_step.form.pk,))

# React UI renders this input, so simulate it in a raw POST call
self.client.post(admin_url, data={"_copy": "Copy"})

copied_form = Form.objects.exclude(pk=form_step.form.pk).get()
copied_step = FormStep.objects.exclude(pk=form_step.pk).get()
copied_logic = copied_form.formlogic_set.get()

self.assertEqual(copied_logic.trigger_from_step, copied_step)


@disable_2fa
class FormAdminActionsTests(FormListAjaxMixin, WebTest):
Expand Down

0 comments on commit 361dc2d

Please sign in to comment.