Skip to content

Commit

Permalink
✨ [#4398] Ensure logs from ownership check in pre-registration work
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenbal committed Oct 29, 2024
1 parent 53288d2 commit b4f669b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
8 changes: 8 additions & 0 deletions src/openforms/logging/logevent.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,14 @@ def registration_attempts_limited(submission: Submission):
)


def object_ownership_check_failure(submission: Submission, plugin=None):
_create_log(
submission,
"object_ownership_check_failure",
plugin=plugin,
)


# - - -


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{% load i18n %}
{% blocktrans trimmed with plugin=log.fmt_plugin lead=log.fmt_lead %}
{{ lead }}: Registration plugin {{ plugin }} reported: authenticated user is not the owner of referenced object.
{% endblocktrans %}
31 changes: 17 additions & 14 deletions src/openforms/registrations/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,27 +74,30 @@ def pre_registration(submission_id: int, event: PostSubmissionEvents) -> None:
)
return

registration_plugin = get_registration_plugin(submission)

# If an `initial_data_reference` was passed, we must verify that the
# authenticated user is the owner of the referenced object
if registration_plugin and submission.initial_data_reference:
try:
registration_plugin.verify_initial_data_ownership(submission)
except PermissionDenied as e:
logger.exception(
"Submission with initial_data_reference did not pass ownership check for plugin %s",
registration_plugin.verbose_name,
)
logevent.object_ownership_check_failure(
submission, plugin=registration_plugin
)
raise e

with transaction.atomic():
registration_plugin = get_registration_plugin(submission)
if not registration_plugin:
set_submission_reference(submission)
submission.pre_registration_completed = True
submission.save()
return

# If an `initial_data_reference` was passed, we must verify that the
# authenticated user is the owner of the referenced object
if submission.initial_data_reference:
try:
registration_plugin.verify_initial_data_ownership(submission)
except PermissionDenied as e:
logger.exception(
"Submission with initial_data_reference did not pass ownership check for plugin %s",
registration_plugin.verbose_name,
)
logevent.registration_failure(submission, e, plugin=registration_plugin)
raise e

options_serializer = registration_plugin.configuration_options(
data=submission.registration_backend.options,
context={"validate_business_logic": False},
Expand Down

0 comments on commit b4f669b

Please sign in to comment.