from marshmallow import ValidationError from permissions.constants import vendor_star EMAIL_MAX_TOTAL_LENGTH = 254 EMAIL_MAX_LOCAL_PART_LENGTH = 64 def is_employee_email(email: str) -> bool: """Determine if an email belongs to an employee based on its domain.""" email_domain = email.split('@')[-1].lower() return email_domain in vendor_star.ALLOWED_VENDOR_STAR_EMAIL_DOMAINS def validate_auth0_email_length(email: str) -> None: """Reject emails Auth0 will refuse: total > 254 or local part > 64.""" if len(email) > EMAIL_MAX_TOTAL_LENGTH: raise ValidationError( f'Email exceeds maximum length of {EMAIL_MAX_TOTAL_LENGTH} characters.' ) local_part = email.split('@')[0] if len(local_part) > EMAIL_MAX_LOCAL_PART_LENGTH: raise ValidationError( f'Email local part exceeds maximum length of {EMAIL_MAX_LOCAL_PART_LENGTH} characters.' )