From 4faaa6ed1916922a58ff7e7772e6ac3a4ca2d15c Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 20 Aug 2025 08:54:04 -0400 Subject: [PATCH] Rely on `email_domain` method from approval require check --- app/models/user.rb | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 8e0785e7fdd..9aa3ad88c57 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -458,18 +458,16 @@ class User < ApplicationRecord end def sign_up_email_requires_approval? - return false if email.blank? + return false if email_domain.blank? - _, domain = email.split('@', 2) - return false if domain.blank? + EmailDomainBlock.requires_approval?(approval_domains, attempt_ip: sign_up_ip) + end - records = [] - - # Doing this conditionally is not very satisfying, but this is consistent - # with the MX records validations we do and keeps the specs tractable. - records = DomainResource.new(domain).mx unless self.class.skip_mx_check? - - EmailDomainBlock.requires_approval?(records + [domain], attempt_ip: sign_up_ip) + def approval_domains + [email_domain].tap do |records| + # MX lookup is enabled only in production by default + records << DomainResource.new(email_domain).mx unless self.class.skip_mx_check? + end.flatten end def sign_up_username_requires_approval?