Skip to content

Conversation

@pierreben
Copy link
Contributor

@pierreben pierreben commented Nov 18, 2025

When using hcaptcha with djangocms-form-builder the captcha_field value is included in the sent mail :

image

It should be ignored in the mail template.

And, I've changed the "trans" tags into "translate"

Summary by Sourcery

Exclude the captcha field from form submission emails and update translation tags in the default mail template

Bug Fixes:

  • Exclude 'captcha_field' from form submission emails

Enhancements:

  • Replace '{% trans %}' tags with '{% translate %}' in the mail HTML template

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Nov 18, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Updates the default HTML email template to skip the hCaptcha field in form submissions and standardizes translation tag usage by replacing all {% trans %} tags with {% translate %}.

Flow diagram for excluding captcha_field from email template

flowchart TD
    A["Start: cleaned_data.items loop"] --> B{Is field == 'captcha_field'?}
    B -- Yes --> C["Skip field"]
    B -- No --> D["Render field and value in email"]
    D --> E["Continue loop"]
    C --> E
Loading

File-Level Changes

Change Details Files
Exclude captcha_field from rendered email content
  • Wrap each form field row in a conditional to skip 'captcha_field'
djangocms_form_builder/templates/djangocms_form_builder/mails/default/mail_html.html
Replace 'trans' tags with 'translate' for i18n consistency
  • Update all {% trans %} tags to {% translate %} for headings, table headers, labels, and footers
djangocms_form_builder/templates/djangocms_form_builder/mails/default/mail_html.html

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov
Copy link

codecov bot commented Nov 18, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.50%. Comparing base (73acd21) to head (39fdd70).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #37      +/-   ##
==========================================
+ Coverage   81.39%   81.50%   +0.10%     
==========================================
  Files          21       21              
  Lines        1473     1476       +3     
  Branches      181      181              
==========================================
+ Hits         1199     1203       +4     
  Misses        219      219              
+ Partials       55       54       -1     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@fsbraun fsbraun changed the title Fix/exclude captcha field from mail fix: Exclude captcha field from mail Nov 18, 2025
@fsbraun
Copy link
Member

fsbraun commented Nov 18, 2025

@pierreben Ohh... Well spotted!

Hm. I believe we should move the rule for excluding the captcha field into python where the context is created. Also, I would remove any password fields (to keep secrets save). Ideally, those would also not be stored into the database when the SaveToDBAction is invoked.

Maybe the FormAction class can have a static method to turn a form's cleaned data dict into a sanitized dictionary w/o captchas or secrets?

What do you think?

@pierreben
Copy link
Contributor Author

I don’t yet have much perspective on the module as a whole, but here are a couple of observations:

  • Captcha field: I don’t see any use case where it’s relevant to retain the Captcha value after form submission. Perhaps we could simply clear its value in the clean method of the SimpleFrontendForm class. I’ve tested this approach in this commit. What do you think?

  • Sensitive fields values: There are likely scenarios where subclasses of FormAction need to access the raw values of sensitive fields, and others where those values should be sanitized. So yes for me it seems appropriate to add a dedicated method in the FormAction class. Each subclass could then call this method (or not) in def execute(self, form, request):, depending on the action’s requirements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants