Skip to content

Conversation

kuzmany
Copy link
Member

@kuzmany kuzmany commented Jun 30, 2025

Q A
Bug fix? (use the a.b branch)
New feature/enhancement? (use the a.x branch)
Deprecations?
BC breaks? (use the c.x branch)
Automated tests included?
Related user documentation PR URL N/A
Related developer documentation PR URL N/A
Issue(s) addressed Enhancement - add validation for email name and subject fields

Description

This PR adds 190 character length validation for email name field to match the existing subject field validation. This prevents users from creating emails with excessively long names that could cause issues in the database or UI.

Key Changes:

  • Added Length constraint for email name field with 190 character maximum
  • Added validator message mautic.email.name.length for the name length constraint
  • Subject field already had the 190 character limit validation

📋 Steps to test this PR:

  1. Open this PR on Gitpod or pull down for testing locally
  2. Go to Channels → Emails
  3. Create a new email or edit an existing one
  4. Try to enter a name longer than 190 characters in the "Internal Name" field
  5. Try to enter a subject longer than 190 characters in the "Subject" field
  6. Save the email
  7. Verify that validation errors are displayed for both fields when they exceed 190 characters
  8. Verify that emails can be saved successfully when both fields are 190 characters or less

Expected Result: Error messages should appear for both name and subject fields when they exceed 190 characters, preventing the email from being saved.

- Add 190 character limit validation for email name field
- Add validation message for email name length constraint
- Subject field already has 190 character limit validation

Steps to test:
- Go to emails
- Create/edit one
- Try to put a name or a subject longer than 190 characters
- An error should be thrown on save

Co-authored-by: Hugo Prossaird <hpr@webmecanik.com>
Co-authored-by: Zdeno Kuzmany <zdeno@kuzmany.biz>
@Copilot Copilot AI review requested due to automatic review settings June 30, 2025 09:05
@kuzmany kuzmany added feature A new feature for inclusion in minor or major releases ready-to-test PR's that are ready to test labels Jun 30, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR ensures the email “Internal Name” field has the same 190-character maximum validation as the subject.

  • Added a Length constraint to the name property in Email.php
  • Introduced a new translation entry for the name length validation message

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
app/bundles/EmailBundle/Entity/Email.php Add a 190-character Length constraint for name
app/bundles/CoreBundle/Translations/en_US/validators.ini Add mautic.email.name.length translation entry
Comments suppressed due to low confidence (1)

app/bundles/EmailBundle/Entity/Email.php:445

  • There's no automated test covering the new name length validation. Consider adding unit or integration tests to ensure the 190-character limit is enforced.
        $metadata->addPropertyConstraint(

Copy link

codecov bot commented Jun 30, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 64.78%. Comparing base (b5179b1) to head (6188a81).
Report is 15 commits behind head on 6.0.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##                6.0   #15147   +/-   ##
=========================================
  Coverage     64.78%   64.78%           
- Complexity    34752    34753    +1     
=========================================
  Files          2276     2276           
  Lines        103809   103812    +3     
=========================================
+ Hits          67254    67258    +4     
+ Misses        36555    36554    -1     
Files with missing lines Coverage Δ
app/bundles/EmailBundle/Entity/Email.php 92.09% <100.00%> (+0.05%) ⬆️

... and 1 file with indirect coverage changes

🚀 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.

@kuzmany kuzmany changed the title [Private Fork] Add email name and subject maxlength validation Add email name and subject maxlength validation Jun 30, 2025
@kuzmany kuzmany added bug Issues or PR's relating to bugs and removed feature A new feature for inclusion in minor or major releases labels Jun 30, 2025
@kuzmany kuzmany added this to the 6.0.4 milestone Jun 30, 2025
kuzmany added 7 commits June 30, 2025 11:24
- Add MAX_NAME_SUBJECT_LENGTH constant (190) to Email entity
- Use constant in both name and subject Length constraints
- Improves maintainability by eliminating magic number duplication

Addresses Copilot AI feedback about duplicated magic numbers.
- Add testEmailNameLengthValidation() - tests 191 char name triggers validation error
- Add testEmailSubjectLengthValidation() - tests 191 char subject triggers validation error
- Add testValidEmailNameAndSubjectLength() - tests 190 char fields are accepted

Tests validate the new MAX_NAME_SUBJECT_LENGTH constant (190 chars) and ensure
validation error messages are displayed when limits are exceeded.

Addresses test coverage gap for email field length constraints.
- Remove testEmailNameLengthValidation() test
- Remove testEmailSubjectLengthValidation() test
- Keep only testValidEmailNameAndSubjectLength() for positive validation

This simplifies the test suite and avoids potential issues with
form validation testing that might be causing CI failures.
- Move mautic.email.name.length from CoreBundle to EmailBundle validators.ini
- Update tests to check for actual translated messages instead of translation keys
- Add back testEmailNameLengthValidation() and testEmailSubjectLengthValidation()
- Tests now check for "Email name maximum length is 190 characters" string
- Tests now check for "Email subject maximum length is 190 characters" string

This should resolve CI failures by checking for the actual validation
messages that appear in the UI rather than untranslated keys.
…ranslation keys

- Remove mautic.email.name.length from CoreBundle validators.ini
- Add mautic.email.name.length to EmailBundle validators.ini
- Remove testValidEmailNameAndSubjectLength test
- Add testEmailNameLengthValidation() checking for 'mautic.email.name.length' key
- Add testEmailSubjectLengthValidation() checking for 'mautic.email.subject.length' key

Tests now validate the actual translation keys that should appear in validation errors.
- Change testEmailNameLengthValidation to check for "Email name maximum length is 190 characters"
- Change testEmailSubjectLengthValidation to check for "Email subject maximum length is 190 characters"

Tests now validate the actual user-facing error messages instead of translation keys.
This is the proper way to test validation since users see the translated messages.
Copy link

Copy link
Member

@patrykgruszka patrykgruszka left a comment

Choose a reason for hiding this comment

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

Code looks fine and functions as intended 👍
image

@kuzmany kuzmany modified the milestones: 6.0.4, 6.0.3 Jun 30, 2025
@kuzmany kuzmany merged commit f1fb19c into mautic:6.0 Jun 30, 2025
19 checks passed
@oltmanns-leuchtfeuer
Copy link
Contributor

@kuzmany could you check this issue related to the length limitations? :)
#15394

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues or PR's relating to bugs ready-to-test PR's that are ready to test
Projects
Status: 🥳 Done
Development

Successfully merging this pull request may close these issues.

3 participants