@@ -48,15 +48,33 @@ def initialize_from_org_autocomplete(name:, funder: false)
4848 end
4949 # rubocop:enable Metrics/AbcSize
5050
51+ # Hardcoded list of email domains that need special handling because the email domain
52+ # does not match the organization's domain
53+ def intercept_from_email_domain ( email_domain )
54+ case email_domain . downcase
55+ when "childrens.harvard.edu"
56+ matches = ::RegistryOrg . where ( "home_page LIKE '%childrenshospital.org'" )
57+ return nil if matches . empty? || matches . first . org_id . nil?
58+
59+ ::Org . find_by ( id : matches . first . org_id )
60+ else
61+ nil
62+ end
63+ end
64+
5165 # Attempt to determine the Org (or RegistryOrg) based on the email's domain
5266 # rubocop:disable Metrics/AbcSize
5367 def from_email_domain ( email_domain :)
5468 return nil if email_domain . blank?
5569 return nil if ignored_email_domains . include? ( email_domain . downcase )
5670
57- org = ::RegistryOrg . from_email_domain ( email_domain : email_domain )
71+ # First see if the email domain requires special handling
72+ org = intercept_from_email_domain ( email_domain )
73+ # If it did not, then try to find it by matching the email domain to RegistryOrg home_page
74+ org = ::RegistryOrg . from_email_domain ( email_domain : email_domain ) unless org . present?
5875 return org if org . present?
5976
77+ # Nothing was found, so try to see what others with that email domain belong to
6078 hash = ::User . where ( 'email LIKE ?' , "%@#{ email_domain . downcase } " ) . group ( :org_id ) . count
6179 return nil if hash . blank?
6280
0 commit comments