Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#5034] Fix object ownership in Objects API #5062

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/openforms/registrations/contrib/objects_api/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ def set_defaults(options: RegistrationOptions) -> None:
def verify_initial_data_ownership(
self, submission: Submission, options: RegistrationOptions
) -> None:
# Object's ownership validation makes sense if we want to update an object
if not options["update_existing_object"]:
return

assert submission.initial_data_reference
api_group = options["objects_api_group"]
assert api_group, "Can't do anything useful without an API group"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from openforms.contrib.objects_api.tests.factories import ObjectsAPIGroupConfigFactory
from openforms.payments.constants import PaymentStatus
from openforms.payments.tests.factories import SubmissionPaymentFactory
from openforms.submissions.constants import PostSubmissionEvents
from openforms.submissions.tasks import pre_registration
from openforms.submissions.tests.factories import (
SubmissionFactory,
SubmissionFileAttachmentFactory,
Expand Down Expand Up @@ -1029,6 +1031,29 @@ def test_submission_with_auth_context_data_not_authenticated(self):

self.assertEqual(result["record"]["data"]["auth"], None)

@tag("gh-5034")
def test_object_ownership_not_validated_if_new_object(self):
submission = SubmissionFactory.from_components(
[{"key": "textfield", "type": "textfield"}],
completed_not_preregistered=True,
form__registration_backend=PLUGIN_IDENTIFIER,
form__registration_backend_options={
"objects_api_group": self.objects_api_group.pk,
"version": 1,
"objecttype": "8faed0fa-7864-4409-aa6d-533a37616a9e",
"objecttype_version": 1,
"update_existing_object": False,
"auth_attribute_path": [],
},
submitted_data={"textfield": "test"},
initial_data_reference="some ref",
)

try:
pre_registration(submission.pk, PostSubmissionEvents.on_retry)
except AssertionError:
self.fail("Assertion should have passed.")


class V1HandlerTests(TestCase):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from openforms.contrib.objects_api.tests.factories import ObjectsAPIGroupConfigFactory
from openforms.payments.constants import PaymentStatus
from openforms.payments.tests.factories import SubmissionPaymentFactory
from openforms.submissions.constants import PostSubmissionEvents
from openforms.submissions.tasks import pre_registration
from openforms.submissions.tests.factories import (
SubmissionFactory,
SubmissionFileAttachmentFactory,
Expand Down Expand Up @@ -514,6 +516,30 @@ def test_addressNl_legacy_before_of_30(self):
},
)

@tag("gh-5034")
def test_object_ownership_not_validated_if_new_object(self):
submission = SubmissionFactory.from_components(
[{"key": "textfield", "type": "textfield"}],
completed_not_preregistered=True,
form__registration_backend=PLUGIN_IDENTIFIER,
form__registration_backend_options={
"objects_api_group": self.objects_api_group.pk,
"version": 2,
"objecttype": "8faed0fa-7864-4409-aa6d-533a37616a9e",
"objecttype_version": 1,
"update_existing_object": False,
"auth_attribute_path": [],
"variables_mapping": [],
},
submitted_data={"textfield": "test"},
initial_data_reference="some ref",
)

try:
pre_registration(submission.pk, PostSubmissionEvents.on_retry)
except AssertionError:
self.fail("Assertion should have passed.")


class V2HandlerTests(TestCase):
"""
Expand Down
Loading