Skip to content

Commit 8142aff

Browse files
authored
[hotfix] remove lead syncing code from update_salesforce_user_info (#989)
* remove lead syncing code from update_salesforce_user_info * update feature specs and cassettes * remove leads from routine spec * rerecord all cassettes * grab school by id, not latest created * add context for new schools to spec
1 parent 70fb08a commit 8142aff

16 files changed

+296
-1524
lines changed

app/routines/update_user_salesforce_info.rb

Lines changed: 0 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ def initialize(allow_error_email:)
2424
@contacts_by_email = {}
2525
@contacts_by_id = {}
2626
@colliding_emails = []
27-
@leads_by_email = {}
2827
end
2928

3029
def self.call(allow_error_email: false)
@@ -91,59 +90,6 @@ def call
9190
end
9291
end
9392

94-
# Now that we've done all we can with Contacts, see if any Users who still don't
95-
# have a salesforce_contact_id might have Leads in SF, and if so mark them as pending
96-
# or rejected based on the info in those Leads.
97-
98-
prepare_leads
99-
100-
user_ids_that_were_looked_at_for_leads = []
101-
102-
@leads_by_email.keys.each_slice(1000) do |emails|
103-
User.joins(:contact_infos)
104-
.eager_load(:contact_infos)
105-
.where(salesforce_contact_id: nil)
106-
.where(contact_infos: { verified: true })
107-
.where( ci_table[:value].lower.in(emails) )
108-
.each do |user|
109-
begin
110-
user_ids_that_were_looked_at_for_leads.push(user.id)
111-
112-
leads = user.contact_infos
113-
.flat_map{|ci| @leads_by_email[ci.value.downcase]}
114-
.uniq
115-
116-
statuses = leads.map(&:status).uniq
117-
118-
# Whenever a lead is processed (in our case when it is either used to
119-
# confirm or reject a faculty application), its status is set to
120-
# 'Converted'. If any of the statuses we have now are not 'Converted',
121-
# we know that the user has a lead that is still under review, so they
122-
# are set to `pending_faculty`. If the statuses only consist of
123-
# 'Converted' statuses, we know the user has been rejected as faculty.
124-
125-
unless user.is_newflow? # because the new Accounts flow works differently; don't mess with it.
126-
user.faculty_status =
127-
if statuses == ["Converted"]
128-
:rejected_faculty
129-
else
130-
:pending_faculty
131-
end
132-
end
133-
134-
user.save! if user.changed?
135-
rescue StandardError => ee
136-
error!(exception: ee, user: user)
137-
end
138-
end
139-
end
140-
141-
User.where(salesforce_contact_id: nil)
142-
.where(faculty_status: User.faculty_statuses.except(User::NO_FACULTY_INFO).values)
143-
.where(is_newflow: false) # because the new Accounts flow works differently; don't mess with it.
144-
.where( user_table[:id].not_in(user_ids_that_were_looked_at_for_leads) )
145-
.update_all(faculty_status: User::NO_FACULTY_INFO)
146-
14793
notify_errors
14894

14995
info("Finished")
@@ -178,30 +124,6 @@ def contacts
178124
.to_a
179125
end
180126

181-
def leads
182-
# Leads come from many sources; we only care about those created for faculty
183-
# verification ("OSC Faculty")
184-
185-
@leads ||= OpenStax::Salesforce::Remote::Lead
186-
.where(source: "OSC Faculty")
187-
.select(:id, :email)
188-
.to_a
189-
end
190-
191-
def prepare_leads
192-
leads.each do |lead|
193-
email = lead.email.try!(&:downcase).try!(:strip)
194-
195-
next if email.nil?
196-
197-
# Leads don't normally get deleted after they are processed, so there may
198-
# be multiple per email.
199-
200-
@leads_by_email[email] ||= []
201-
@leads_by_email[email].push(lead)
202-
end
203-
end
204-
205127
def prepare_contacts
206128
colliding_emails = []
207129

spec/cassettes/UpdateUserSalesforceInfo/email_collisions/errors_and_doesn_t_link_when_two_contacts_with_same_alt_email.yml

Lines changed: 43 additions & 89 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)