Skip to content

Commit

Permalink
[#4397] Added object_reference to the submission
Browse files Browse the repository at this point in the history
This is done in order to save the initial data reference which comes from the frontend
as a query parameter. It will be used to retreive additional information for
the object from the Objects API (we are going to support only this for now)
  • Loading branch information
vaszig committed Jul 17, 2024
1 parent edf1df2 commit 32ad9fb
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9630,6 +9630,13 @@ components:
writeOnly: true
default: false
description: Whether the submission was started anonymously or not.
initialDataReference:
type: string
description: An identifier that can be passed as a querystring when the
form is started. Initial form field values are pre-populated from the
retrieved data. During registration, the object may be updated again (or
a new record may be created). This can be an object reference in the Objects
API, for example.
required:
- form
- formUrl
Expand Down
1 change: 1 addition & 0 deletions src/openforms/submissions/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ class SubmissionAdmin(admin.ModelAdmin):
"statement_of_truth_accepted",
"_is_cleaned",
"previous_submission",
"initial_data_reference",
),
"classes": ("collapse",),
},
Expand Down
1 change: 1 addition & 0 deletions src/openforms/submissions/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ class Meta:
"payment",
"form_url",
"anonymous",
"initial_data_reference",
)
extra_kwargs = {
"id": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 4.2.14 on 2024-07-16 14:25

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("submissions", "0007_add_legacy_constraint"),
]

operations = [
migrations.AddField(
model_name="submission",
name="initial_data_reference",
field=models.CharField(
blank=True,
help_text="An identifier that can be passed as a querystring when the form is started. Initial form field values are pre-populated from the retrieved data. During registration, the object may be updated again (or a new record may be created). This can be an object reference in the Objects API, for example.",
verbose_name="initial data reference",
),
),
]
10 changes: 10 additions & 0 deletions src/openforms/submissions/models/submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,16 @@ class Submission(models.Model):
"Indicates whether sensitive data (if there was any) has been removed from this submission."
),
)
initial_data_reference = models.CharField(
_("initial data reference"),
blank=True,
help_text=_(
"An identifier that can be passed as a querystring when the form is started. "
"Initial form field values are pre-populated from the retrieved data. "
"During registration, the object may be updated again (or a new record may be created). "
"This can be an object reference in the Objects API, for example."
),
)

# TODO: Deprecated, replaced by the PostCompletionMetadata model
on_completion_task_ids = ArrayField(
Expand Down
1 change: 1 addition & 0 deletions src/openforms/submissions/tests/test_list_submissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def test_list_response_format(self):
"url": f"http://testserver{submission_path}",
"form": f"http://testserver{form_path}",
"formUrl": "http://formserver/myform",
"initial_data_reference": "",
"steps": [
{
"id": str(self.step.uuid),
Expand Down
1 change: 1 addition & 0 deletions src/openforms/submissions/tests/test_read_submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def test_retrieve_submission_nothing_submitted(self):
"url": f"http://testserver{self.endpoint}",
"form": f"http://testserver{form_path}",
"formUrl": "",
"initial_data_reference": "",
"steps": [
{
"id": str(self.step.uuid),
Expand Down
16 changes: 16 additions & 0 deletions src/openforms/submissions/tests/test_start_submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,19 @@ def test_start_submission_with_prefill(self, mock_logevent):
self.assertEqual(
SubmissionValueVariableSources.prefill, prefilled_variable.source
)

def test_start_submission_with_initial_data_reference(self):
body = {
"form": f"http://testserver.com{self.form_url}",
"formUrl": "http://testserver.com/my-form",
"initialDataReference": "of-or-3452fre3",
}

response = self.client.post(self.endpoint, body)

submission = Submission.objects.get()

self.assertEqual(response.status_code, status.HTTP_201_CREATED)
self.assertEqual(
submission.initial_data_reference, body["initialDataReference"]
)

0 comments on commit 32ad9fb

Please sign in to comment.