@@ -24,7 +24,6 @@ def initialize(allow_error_email:)
24
24
@contacts_by_email = { }
25
25
@contacts_by_id = { }
26
26
@colliding_emails = [ ]
27
- @leads_by_email = { }
28
27
end
29
28
30
29
def self . call ( allow_error_email : false )
@@ -91,59 +90,6 @@ def call
91
90
end
92
91
end
93
92
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
-
147
93
notify_errors
148
94
149
95
info ( "Finished" )
@@ -178,30 +124,6 @@ def contacts
178
124
. to_a
179
125
end
180
126
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
-
205
127
def prepare_contacts
206
128
colliding_emails = [ ]
207
129
0 commit comments