[Users] Add a reasonable length limit on emails

The spec allows for addresses up to 255. A limit of 100 impacts 3 users right now
This commit is contained in:
Earlopain 2024-04-28 11:28:07 +02:00
parent 5f6fa2b83d
commit 0dce1e50f2
No known key found for this signature in database
GPG Key ID: 48860312319ADF61

View File

@ -62,6 +62,7 @@ class User < ApplicationRecord
validates :email, presence: { if: :enable_email_verification? } validates :email, presence: { if: :enable_email_verification? }
validates :email, uniqueness: { case_sensitive: false, if: :enable_email_verification? } validates :email, uniqueness: { case_sensitive: false, if: :enable_email_verification? }
validates :email, format: { with: /\A.+@[^ ,;@]+\.[^ ,;@]+\z/, if: :enable_email_verification? } validates :email, format: { with: /\A.+@[^ ,;@]+\.[^ ,;@]+\z/, if: :enable_email_verification? }
validates :email, length: { maximum: 100 }
validate :validate_email_address_allowed, on: [:create, :update], if: ->(rec) { (rec.new_record? && rec.email.present?) || (rec.email.present? && rec.email_changed?) } validate :validate_email_address_allowed, on: [:create, :update], if: ->(rec) { (rec.new_record? && rec.email.present?) || (rec.email.present? && rec.email_changed?) }
validates :name, user_name: true, on: :create validates :name, user_name: true, on: :create