-
Notifications
You must be signed in to change notification settings - Fork 26
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
✨ [#4398] Check object ownership when creating submission #4696
✨ [#4398] Check object ownership when creating submission #4696
Conversation
8e700b5
to
7891ead
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #4696 +/- ##
==========================================
- Coverage 96.61% 96.61% -0.01%
==========================================
Files 751 752 +1
Lines 25762 25848 +86
Branches 3413 3422 +9
==========================================
+ Hits 24891 24974 +83
- Misses 609 612 +3
Partials 262 262 ☔ View full report in Codecov by Sentry. |
7891ead
to
18dc4e6
Compare
18dc4e6
to
ac6305a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is happening at the wrong place with the wrong assumptions 😬
For starters, session[FORM_AUTH_SESSION_KEY]
should not be relied on - ideally once the submission is created/started, this should be cleaned from the session data entirely since we have a hook/signal that records it on the submission itself.
Second - we should always pass a submission
instance when performing this kind of validation, exactly because different credentials could apply to a submission vs. what's in the session (the session data is a data race, since you can have different authentication details there compared to a submission that is also still in your session, for example when you are filling out two forms at the same time with different login options).
I think the prefill plugin itself should perform this access control, since:
- in
submissions.api.viewsets.SubmissionViewSet.perform_create
we dispatch the submission start signal, that ensures we have the auth details stored - after that, we call
prefill_variables
, which receives thesubmission
instance and passes it to the plugin - inside the plugin, you should be able to
raise PermissionDenied
if anything is fishy - if that exception is raised, it should bubble up to the API endpoint, will result in an HTTP 403 and the DB transaction should be rolled back so that the submission record is never persisted in the database
I'm afraid that makes this PR/ticket depend on #4620 then 🤔
55dc86e
to
84e00ce
Compare
@sergei-maertens it was mentioned in #4721 that the mechanism to pass |
uh... right. I'll have to think about that 😅 |
@sergei-maertens maybe there should be some kind of hook in |
@stevenbal I still don't see a simple/elegant way to do this, especially because data can be mutated externally and be outdated. E.g., if you verify it at I'm kind of leaning towards implementing the permission check itself once in It's again a case of two different systems doing very similar things, but that doesn't make them the same. The prefill mapping and registration mapping are technically independent from each other too, we'll just offer convenience UI options to use one as a source for the other, but in the backend, they don't know of each other's existence and that's fine. The meaning of Perhaps for registration plugins we define a new hook on the base plugin which raises |
@sergei-maertens that sound like a good idea, I'll see if I can implement this |
52daf64
to
ca09bd7
Compare
2aa507c
to
1cd37e4
Compare
The TargetPathSelect component is now decoupled from its possible FieldArray parent, and the option label display is incorporated in the component itself so that options no longer need to be pre-processed. On top of that, it's now refactored to be based on react-select for consistency in the UI, and separate stories have been added so we can do (visual) regression testing/isolated development. We use this component in a number of places now: * the path to the auth attribute (no variablesMapping parent context), used in registration and prefill plugins for the Objects API * the path for the generic Object Types V2 registration mapping, here a variablesMapping parent container/context is relevant and different form state management semantics apply * the path to specialized AddressNL subfield mappings - a parent is relevant, but not within a bigger variable mapping so we can use the standard field assignment semantics of Formik.
3ceac3e
to
215fa49
Compare
This is now possible because we render modals in the proper portal/body element to make these queries work.
45b3acb
to
3f25d66
Compare
Instead of prop-drilling, make sure to process validation errors at the locations where the shape/structure is known and rely on the generic mechanisms to pass/display the validation errors. This also adds some JSDoc type hinting to the helpers because I keep getting lost on what the expected shape of data/input is.
3f25d66
to
953d574
Compare
de93db9
to
f5f620b
Compare
* Ensure we use the deserialized, strongly typed options in plugins * Dropped unused error cases/flows that are obsoleted * Made serializer options all required, since the prefill cannot possibly work without and must match the type definitions of the options.
f5f620b
to
6d45ca2
Compare
…n details The important pattern is that certain validation checks run, not the implementation details of the objects api prefill plugin. So, we can properly isolate this by setting up a different plugin registry and doing the dependency injection through a helper, applying the same pattern as with registration plugins.
Dropped the bits that are not relevant.
The task/generic machinery takes care of deserializing the plugin options and passes them to the hook for ownership verification, greatly simplifying the code that needs to be implemented.
Properly mock the registry of plugins instead of having to rely on particular demo plugins having certain behaviours or needing to mock implementation details in tests.
* Converted the tests to make use of VCR for the actual implementation details of the ownership verification * Simplified the tests and ensured they're unit tests focused around a single method. We have a generic pattern test that ensures the method gets called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy with it being in this state, let's hope CI passes too and then it's finally done! 🎉
Closes #4398
Changes
Checklist
Check off the items that are completed or not relevant.
Impact on features
Release management
I have updated the translations assets (you do NOT need to provide translations)
./bin/makemessages_js.sh
./bin/compilemessages_js.sh
Commit hygiene