Skip to content

Remove email invariant and add adapter to toggle email_report#133

Merged
xispa merged 7 commits into
senaite:masterfrom
nnpvaan:fix-validate-email-from-request-body
Jan 11, 2026
Merged

Remove email invariant and add adapter to toggle email_report#133
xispa merged 7 commits into
senaite:masterfrom
nnpvaan:fix-validate-email-from-request-body

Conversation

@nnpvaan

@nnpvaan nnpvaan commented Nov 17, 2025

Copy link
Copy Markdown
Contributor

Description of the issue/feature this PR addresses

This PR removes the validate_email_report invariant and replaces it with an EditFormAdapter that handles the visibility of the email_report field based on whether the entered email is valid. Email validation should not be part of the invariant’s responsibility.

Current behavior before PR

The validate_email_report invariant attempted to validate the email by checking request.form, which does not work for JSON API requests and mixes responsibilities. As a result, email validation failed in API scenarios and the logic for showing/hiding email_report was not handled cleanly.

Desired behavior after PR is merged

  • The invariant is removed entirely.
  • An EditFormAdapter now automatically shows the email_report field when the email field contains a valid email, and hides it otherwise.
  • Behavior is consistent for both form submissions and JSON API usage

--
I confirm I have tested this PR thoroughly and coded it according to PEP8
and Plone's Python styleguide standards.

@xispa xispa left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This invariant checks whether the value provided in the email field is valid (and non-empty) when the boolean field validate_email_report is set to True (i.e., when the "Email results report" checkbox is ticked).

However, this validation is tightly coupled to the form submission workflow. Instead of performing this check at the schema level, I suggest removing the invariant and implementing an IAjaxEditFormAdapter to hide and uncheck the email_report (“Email results report”) field dynamically. This approach keeps the schema cleaner and moves the UI-dependent logic to the appropriate layer.

@nnpvaan nnpvaan changed the title Enhance email extraction in IPatientSchema to support JSON request body Remove email invariant and add adapter to toggle email_report Dec 2, 2025
@nnpvaan nnpvaan requested a review from xispa December 2, 2025 06:42

@xispa xispa left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you move the "EmailReport" field to appear after the "Primary Email Address" field? Currently, the two fields are on different tabs, which can be a bit confusing

@nnpvaan nnpvaan requested a review from xispa December 8, 2025 02:18
@xispa xispa merged commit 9d81bc6 into senaite:master Jan 11, 2026
1 check passed
@xispa xispa deleted the fix-validate-email-from-request-body branch January 11, 2026 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants