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

Add metadata to data being sent to API endpoint in json dump registration backend #5053

Conversation

viktorvanwijk
Copy link
Contributor

@viktorvanwijk viktorvanwijk commented Jan 28, 2025

Closes #5012

Changes

Add metadata to data being sent to API endpoint in JSON dump registration backend

Checklist

Check off the items that are completed or not relevant.

  • Impact on features

    • Checked copying a form
    • Checked import/export of a form
    • Config checks in the configuration overview admin page
    • Problem detection in the admin email digest is handled
  • Release management

    • I have labelled the PR as "needs-backport" accordingly
  • I have updated the translations assets (you do NOT need to provide translations)

    • Ran ./bin/makemessages_js.sh
    • Ran ./bin/compilemessages_js.sh
  • Dockerfile/scripts

    • Updated the Dockerfile with the necessary scripts from the ./bin folder
  • Commit hygiene

    • Commit messages refer to the relevant Github issue
    • Commit messages explain the "why" of change, not the how

@viktorvanwijk viktorvanwijk force-pushed the feature/5012-add-metadata-to-data-being-sent-to-api-endpoint-in-json-dump-registration-backend branch 6 times, most recently from 047a0c9 to 54efef5 Compare January 30, 2025 15:55
Copy link

codecov bot commented Jan 30, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.73%. Comparing base (53752fa) to head (58b6492).
Report is 9 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5053   +/-   ##
=======================================
  Coverage   96.72%   96.73%           
=======================================
  Files         770      771    +1     
  Lines       26534    26588   +54     
  Branches     3452     3458    +6     
=======================================
+ Hits        25666    25720   +54     
  Misses        606      606           
  Partials      262      262           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@viktorvanwijk viktorvanwijk force-pushed the feature/5012-add-metadata-to-data-being-sent-to-api-endpoint-in-json-dump-registration-backend branch from 54efef5 to 8f487bf Compare January 30, 2025 16:14
@viktorvanwijk viktorvanwijk marked this pull request as ready for review January 31, 2025 08:20
@viktorvanwijk
Copy link
Contributor Author

viktorvanwijk commented Jan 31, 2025

Few design considerations:

Tried making the JSONDumpOptionsSerializer.required_metadata_variables field read_only, but then it won't be available in validated_data of the serializer, which is passed to the JSONDumpRegistration.register_submission. Thought about overwriting validated_data and adding the required_metadata_variables manually, but didn't seem like the right thing to do. Or adding a non-field constant for the default values of required_metadata_variables, so it can be accessed easily from the plugin without instantiating the serializer, but not sure if there are any best practises for that.

To show all metadata variables (additional and required) in the metadata selection box, and grey out all variables which are required by default, thought about adding the registration variables to the VariablesSelection component. But, because they are just static variables, they would all be added to this group in the drop-down menu. And afaik we cannot guarantee unique keys between regular static variables and registration variables (or registration variables of different plugins as well). So I would have to redo the grouping of variables in this component, and wasn't sure it would be worth it, or even desired behaviour.

@viktorvanwijk viktorvanwijk force-pushed the feature/5012-add-metadata-to-data-being-sent-to-api-endpoint-in-json-dump-registration-backend branch 2 times, most recently from 205d6aa to 5a5e6a8 Compare January 31, 2025 13:45
Copy link
Member

@sergei-maertens sergei-maertens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, I think it's mostly polishing from here on :)

@viktorvanwijk viktorvanwijk force-pushed the feature/5012-add-metadata-to-data-being-sent-to-api-endpoint-in-json-dump-registration-backend branch from 5a5e6a8 to a191924 Compare February 4, 2025 13:07
Copy link
Member

@sergei-maertens sergei-maertens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat!

One more thing that caught my attention in storybook is that your help texts for the form fields don't end with a <kbd>.</kbd>, which looks odd and is inconsistent with (most of) the other form fields.

So, form label can be without, help text/tooltip should be with period as they are typically actual sentences (or should be!).

@viktorvanwijk viktorvanwijk force-pushed the feature/5012-add-metadata-to-data-being-sent-to-api-endpoint-in-json-dump-registration-backend branch 3 times, most recently from 53eacd6 to d81405f Compare February 5, 2025 09:49
@viktorvanwijk viktorvanwijk force-pushed the feature/5012-add-metadata-to-data-being-sent-to-api-endpoint-in-json-dump-registration-backend branch from d81405f to 857c799 Compare February 5, 2025 10:26
Also add support for an extra static variables registry in generate_json_schema
If there is no authentication, the value can be an empty string
If there is no content (in case of an HTTP 204 response for example), converting the response to json results in an error, so we just return an empty string
* Improve UX by introducing a (collapsed) fieldset which contains a table of fixed variables, and a variable selection box to add additional variables.
* Fix imports
* Add TODO: currently, this is tricky because the form registration options are saved before the (user defined) form variables are persisted. If this field is limited to static/registration variables, however, it will be possible as they are defined in the code. At this point in time, though, not sure how strict we should make this.
* Fix help texts of JSON dump option fields. They are sentences that should end with a period
@viktorvanwijk viktorvanwijk force-pushed the feature/5012-add-metadata-to-data-being-sent-to-api-endpoint-in-json-dump-registration-backend branch from 857c799 to 377bd53 Compare February 5, 2025 10:30
@sergei-maertens sergei-maertens force-pushed the feature/5012-add-metadata-to-data-being-sent-to-api-endpoint-in-json-dump-registration-backend branch from 377bd53 to 58b6492 Compare February 5, 2025 12:03
@sergei-maertens sergei-maertens merged commit eea9c23 into master Feb 5, 2025
17 of 18 checks passed
@sergei-maertens sergei-maertens deleted the feature/5012-add-metadata-to-data-being-sent-to-api-endpoint-in-json-dump-registration-backend branch February 5, 2025 12:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add metadata to data being sent to API endpoint in JSON dump registration backend
3 participants