fix(email): allow larger email templates (#15146)
## Description Branded email layouts and other email templates can now contain up to 262,144 characters instead of the generic 20,000-character text limit. This supports customer layouts around 41 KB and 100 KB while retaining a defined application-level ceiling. The account and inbox API schemas now expose the same maximum. ## Closes [CW-7682](https://linear.app/chatwoot/issue/CW-7682/allow-larger-branded-email-templates) Related: [CW-7514](https://linear.app/chatwoot/issue/CW-7514/branded-html-email-templates-per-inboxbrand) ## Type of change - [x] Bug fix (non-breaking change which fixes an issue) - [x] This change requires a documentation update ## How Has This Been Tested? 1. As an administrator with `branded_email_templates` enabled, update an account branded layout with a 100 KB Liquid layout containing `{{ content_for_layout }}` and confirm the request succeeds. 2. Update an Email inbox layout with more than 262,144 characters and confirm the API returns `422`. 3. Confirm a layout at exactly 262,144 characters remains valid. ## Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my code - [ ] I have commented on my code, particularly in hard-to-understand areas - [x] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [x] Any dependent changes have been merged and published in downstream modules
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
class EmailTemplate < ApplicationRecord
|
||||
BRANDED_LAYOUT_NAME = 'base'.freeze
|
||||
DEFAULT_LOCALE = 'en'.freeze
|
||||
MAX_BODY_LENGTH = 256.kilobytes
|
||||
CONTENT_FOR_LAYOUT_PATTERN = /\{\{\s*content_for_layout\s*\}\}/
|
||||
|
||||
enum :locale, LANGUAGES_CONFIG.map { |key, val| [val[:iso_639_1_code], key] }.to_h, prefix: true
|
||||
@@ -34,6 +35,7 @@ class EmailTemplate < ApplicationRecord
|
||||
if: :installation_scoped?
|
||||
validates :name, uniqueness: { scope: %i[account_id template_type locale], conditions: -> { where(inbox_id: nil) } }, if: :account_scoped?
|
||||
validates :name, uniqueness: { scope: %i[inbox_id template_type locale] }, if: :inbox_scoped?
|
||||
validates :body, length: { maximum: MAX_BODY_LENGTH }
|
||||
validate :validate_inbox_account
|
||||
validate :validate_liquid_body
|
||||
validate :validate_layout_slot, if: :layout?
|
||||
|
||||
Reference in New Issue
Block a user