@@ -20,9 +20,9 @@ class User < ApplicationRecord
20
20
has_many :active_volunteerings , -> { where state : 'active' } , class_name : 'Volunteering'
21
21
has_many :projects , through : :active_volunteerings , source : 'user'
22
22
23
- before_save :push_changes_to_airtable , unless : :skip_push_to_airtable
23
+ # before_save :push_changes_to_airtable, unless: :skip_push_to_airtable
24
24
25
- after_create :send_slack_notification , unless : :skip_slack_notification
25
+ # after_create :send_slack_notification, unless: :skip_slack_notification
26
26
27
27
devise :omniauthable , omniauth_providers : [ :slack ]
28
28
@@ -180,7 +180,7 @@ def airtable_twin
180
180
end
181
181
end
182
182
183
- def sync_with_airtable ( airtable_user )
183
+ def sync_with_airtable ( airtable_user , airtable_table )
184
184
self . skip_push_to_airtable = true
185
185
186
186
if self . new_record?
@@ -199,41 +199,77 @@ def sync_with_airtable(airtable_user)
199
199
self . non_tech_skill_ids = Skill . match_with_airtable ( airtable_skills : airtable_user [ "Non-Tech Skills and Specialties" ] , tech : false )
200
200
end
201
201
202
- self . assign_attributes ( {
203
- name : airtable_user [ "Name" ] ,
204
- email : airtable_user [ "Contact E-Mail" ] ,
205
- slack_username : airtable_user [ "Member Handle" ] ,
206
- slack_userid : airtable_user [ "slack_id" ] ,
207
- optin : airtable_user [ "Optin" ] ,
208
- join_reason : airtable_user [ "Join Reason" ] ,
209
- overview : airtable_user [ "Overview" ] ,
210
- location : airtable_user [ "Location" ] ,
211
- phone : airtable_user [ "Phone" ] ,
212
- hear_about_us : airtable_user [ "Hear About Us" ] ,
213
- verification_urls : airtable_user [ "Verification URLs" ] ,
214
- gender_pronouns : airtable_user [ "Gender Pronouns" ] ,
215
- additional_info : airtable_user [ "Additional Info" ] ,
216
- anonymous : airtable_user [ "Anonymous" ] ,
217
- read_manifesto : airtable_user [ "Read Manifesto" ] ,
218
- read_code_of_conduct : airtable_user [ "Read Code of Conduct" ]
219
- } )
202
+ if airtable_table == "prog apps"
203
+
204
+ self . assign_attributes ( {
205
+ name : airtable_user [ "Name" ] ,
206
+ email : airtable_user [ "Contact E-Mail" ] ,
207
+ slack_username : airtable_user [ "Member Handle" ] ,
208
+ slack_userid : airtable_user [ "slack_id" ] ,
209
+ optin : airtable_user [ "Optin" ] ,
210
+ join_reason : airtable_user [ "Join Reason" ] ,
211
+ overview : airtable_user [ "Overview" ] ,
212
+ location : airtable_user [ "Location" ] ,
213
+ phone : airtable_user [ "Phone" ] ,
214
+ hear_about_us : airtable_user [ "Hear About Us" ] ,
215
+ verification_urls : airtable_user [ "Verification URLs" ] ,
216
+ gender_pronouns : airtable_user [ "Gender Pronouns" ] ,
217
+ additional_info : airtable_user [ "Additional Info" ] ,
218
+ anonymous : airtable_user [ "Anonymous" ] ,
219
+ read_manifesto : airtable_user [ "Read Manifesto" ] ,
220
+ read_code_of_conduct : airtable_user [ "Read Code of Conduct" ]
221
+ } )
220
222
221
- self . is_approved = true
223
+ self . is_approved = true
222
224
223
- if self . email . blank?
224
- if self . has_slack?
225
- self . get_email_from_slack
225
+ if self . email . blank?
226
+ if self . has_slack?
227
+ self . get_email_from_slack
228
+ end
229
+ end
230
+
231
+ if self . slack_userid . blank? && self . slack_username . present?
232
+ self . get_slack_userid
233
+ elsif self . slack_userid . present? && self . slack_username . blank?
234
+ self . get_slack_username
235
+ end
236
+
237
+ elsif airtable_table == "admin"
238
+ self . assign_attributes ( {
239
+ name : airtable_user [ "Name" ] ,
240
+ read_code_of_conduct : airtable_user [ "Read Code of Conduct" ] ,
241
+ anonymous : airtable_user [ "I prefer to remain anonymous." ] ,
242
+ welcome_email_sent : airtable_user [ "Welcome E-mail Sent" ] ,
243
+ attended_onboarding : airtable_user [ "Attended Onboarding" ] ,
244
+ slack_invite_sent : airtable_user [ "Slack invite sent?" ] ,
245
+ requested_additional_verification : airtable_user [ "Requested additional verification" ] ,
246
+ decline_membership : airtable_user [ "Declime Membership" ] ,
247
+ irs_email_sent : airtable_user [ "IRS Email Sent" ] ,
248
+ internal_notes : airtable_user [ "Internal Notes" ] ,
249
+ contributor : airtable_user [ "Contributor?" ] ,
250
+ email : airtable_user [ "Contact E-Mail" ] ,
251
+ verification_urls : airtable_user [ "Verification URLs" ] ,
252
+ hear_about_us : airtable_user [ "How did you hear about us?" ] ,
253
+ referrer_name : airtable_user [ "Name of ProgCode member who referred you." ] ,
254
+ skills_and_experience : airtable_user [ "Skills and Relevant Experience (Tech or Non-Tech)" ] ,
255
+ join_reason : airtable_user [ "Bio" ] ,
256
+ phone : airtable_user [ "Phone" ] ,
257
+ optin : airtable_user [ "Opt In to Anonymized Member Directory" ] ,
258
+ location : airtable_user [ "Location" ] ,
259
+ read_manifesto : airtable_user [ "Read Manifesto" ]
260
+ } )
261
+
262
+ if self . decline_membership
263
+ self . is_approved = false
264
+ elsif self . welcome_email_sent
265
+ self . is_approved = true
226
266
end
227
- end
228
267
229
- if self . slack_userid . blank? && self . slack_username . present?
230
- self . get_slack_userid
231
- elsif self . slack_userid . present? && self . slack_username . blank?
232
- self . get_slack_username
233
268
end
234
269
235
270
if self . email . present? || self . slack_userid . present?
236
- matches = AirtableUser . all . select { |u | ( self . email . present? && u [ "Contact E-Mail" ] == self . email ) || ( self . slack_userid . present? && u [ "slack_id" ] == self . slack_userid ) }
271
+ all_airtable_users = airtable_table == 'admin' ? AirtableUserFromAdmin . all : AirtableUser . all
272
+ matches = all_airtable_users . select { |u | ( self . email . present? && u [ "Contact E-Mail" ] == self . email ) || ( self . slack_userid . present? && u [ "slack_id" ] == self . slack_userid ) }
237
273
if matches . length > 1
238
274
self . flags << "This user appears more than once in Airtable"
239
275
end
0 commit comments