Skip to content

Commit 95e353f

Browse files
committed
Added function to provide special handling for certain org's SSO logic when users create an account
1 parent fec4380 commit 95e353f

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## DMPTool Releases
44

5+
### v5.43
6+
- Add logic to provide special handling for certain Org's SSO #734
7+
58
### v5.41
69
- Update klaro styles to use `klaro-ui-light` to try and fix missing background button color
710

app/models/concerns/dmptool/org.rb

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)