Skip to content

Commit 920c524

Browse files
authored
School info in admin, Sentry message on school error during lead creation (#1236)
* cleanup users with changed school ids from salesforce * only run the tests after the migrations workflow * Revert "only run the tests after the migrations workflow" This reverts commit ff9e4a8. * run migrations in tests workflow * no need to migrate, just forgot the db schema file * Add school info to accounts admin, cleanup * change to store the possible new school id * update the correct school * move updating school to lead creation * remove stale_id, only update school if lead returns it is bad * check error for invalid access to ref entity from salesforce * just throw a message to sentry if the school is bad
1 parent ebad9a1 commit 920c524

File tree

4 files changed

+73
-100
lines changed

4 files changed

+73
-100
lines changed

app/routines/newflow/create_or_update_salesforce_lead.rb

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -121,31 +121,19 @@ def exec(user:)
121121
event_data: { lead_id: lead.id.to_s }
122122
)
123123
else
124+
if lead.errors.messages.inspect.include? == 'INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY'
125+
Sentry.capture_message("Invalid school (#{user.school.salesforce_id}) for user (#{user.id})")
126+
end
124127
SecurityLog.create!(
125128
user: user,
126129
event_type: :educator_sign_up_failed,
127-
event_data: {
128-
message: "saving the user's lead id FAILED",
129-
lead_id: lead.id
130-
}
130+
event_data: { lead_id: lead.id }
131131
)
132132
Sentry.capture_message("User #{user.id} was not successfully saved with lead #{lead.id}")
133133
end
134-
outputs.lead = lead
135-
else
136-
message = "#{self.class.name} error creating SF lead! #{lead.inspect}; User: #{user.id}; Error: #{lead.errors.full_messages}"
137-
138-
Sentry.capture_message(message)
139-
140-
SecurityLog.create!(
141-
user: user,
142-
event_type: :salesforce_error,
143-
event_data: {
144-
message: message
145-
}
146-
)
147134
end
148135

136+
outputs.lead = lead
149137
outputs.user = user
150138
end
151139

app/views/admin/users/_form.html.erb

Lines changed: 31 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
</div>
123123
</div>
124124

125+
<% if @user.sheerid_verification_id %>
125126
<div class="form-group">
126127
<%= f.label :sheerid_verification_id, class: "col-sm-2 control-label" %>
127128
<div class="col-sm-10">
@@ -130,6 +131,35 @@
130131
</p>
131132
</div>
132133
</div>
134+
<% end %>
135+
136+
<% if @user.school %>
137+
<div class="form-group">
138+
<%= f.label :school, class: "col-sm-2 control-label" %>
139+
<div class="col-sm-10">
140+
<p class="form-control-static">
141+
<% sf_id = @user.school.salesforce_id %>
142+
<% instance_url = ActiveForce.sfdc_client.instance_url rescue nil %>
143+
<% if instance_url.nil? %>
144+
<%= @user.school.name %>
145+
<% else %>
146+
<%= link_to @user.school.name, instance_url + "/" + sf_id, target: '_blank' %>
147+
<% end %>
148+
</p>
149+
</div>
150+
</div>
151+
<% end %>
152+
153+
<% if @user.which_books %>
154+
<div class="form-group">
155+
<%= f.label :which_books, class: "col-sm-2 control-label" %>
156+
<div class="col-sm-10">
157+
<p class="form-control-static">
158+
<%= @user.which_books %>
159+
</p>
160+
</div>
161+
</div>
162+
<% end %>
133163

134164
<% if @user.sheerid_reported_school %>
135165
<div class="form-group">
@@ -149,11 +179,7 @@
149179
<% sf_id = @user.salesforce_lead_id %>
150180
<p class="form-control-static">
151181
<% if sf_id.nil? %>
152-
<%= link_to 'Not Set. Force Push?', force_update_lead_admin_user_path(@user),
153-
remote: true, method: :post,
154-
class: 'btn btn-default',
155-
data: {confirm: "Are you sure you want to force sync this lead with Salesforce?"}
156-
%>
182+
No Lead
157183
<% else %>
158184
<% instance_url = ActiveForce.sfdc_client.instance_url rescue nil %>
159185
<% if instance_url.nil? %>
@@ -323,33 +349,6 @@
323349
</div>
324350
</div>
325351

326-
<div class="form-group">
327-
<%= f.label :is_kip, 'Key Institutional Partner?', class: "col-sm-2 control-label" %>
328-
<div class="col-sm-10">
329-
<div class="checkbox">
330-
<%= f.check_box :is_kip, style: 'margin-left: 0px' %>
331-
</div>
332-
</div>
333-
</div>
334-
335-
<div class="form-group">
336-
<%= f.label :is_b_r_i_user, 'BRI User?', class: "col-sm-2 control-label" %>
337-
<div class="col-sm-10">
338-
<div class="checkbox">
339-
<%= f.check_box :is_b_r_i_user, style: 'margin-left: 0px' %>
340-
</div>
341-
</div>
342-
</div>
343-
344-
<div class="form-group">
345-
<%= f.label :grant_tutor_access, 'Grant Tutor Access?', class: "col-sm-2 control-label" %>
346-
<div class="col-sm-10">
347-
<div class="checkbox">
348-
<%= f.check_box :grant_tutor_access, style: 'margin-left: 0px' %>
349-
</div>
350-
</div>
351-
</div>
352-
353352
<div class="form-group">
354353
<%= f.label :is_administrator, 'Administrator?', class: "col-sm-2 control-label" %>
355354
<div class="col-sm-10">
@@ -368,15 +367,6 @@
368367
</div>
369368
</div>
370369

371-
<div class="form-group">
372-
<%= f.label :opt_out_of_cookies, 'Opt Out of Cookies?', class: "col-sm-2 control-label" %>
373-
<div class="col-sm-10">
374-
<div class="checkbox">
375-
<%= f.check_box :opt_out_of_cookies, style: 'margin-left: 0px' %>
376-
</div>
377-
</div>
378-
</div>
379-
380370
<% if @user.external_uuids.any? %>
381371
<br>
382372

app/views/admin/users/index.html.erb

Lines changed: 36 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@
3737
<th>Last Name</th>
3838
<th>Faculty Status</th>
3939
<th>Role</th>
40-
<th>School Type</th>
41-
<th>KIP?</th>
42-
<th>Grant Tutor Access?</th>
40+
<th>School</th>
41+
<th>Salesforce</th>
42+
<th></th>
4343
<th></th>
4444
</tr>
4545
<% @handler_result.outputs[:items].each do |user| %>
@@ -52,11 +52,38 @@
5252
<td><%= link_to user.id, edit_admin_user_path(user), target: '_blank' %></td>
5353
<td><%= user.first_name || '---' %></td>
5454
<td><%= user.last_name || '---' %></td>
55-
<td><%= user.faculty_status %></td>
56-
<td><%= user.unknown_role? ? "Unknown" : user.role.capitalize %></td>
57-
<td><%= user.school_type %></td>
58-
<td><%= user.is_kip ? 'Yes' : 'No' %></td>
59-
<td><%= user.grant_tutor_access ? 'Yes' : 'No' %></td>
55+
<td><%= user.faculty_status.humanize %></td>
56+
<td><%= user.school_type.humanize %></td>
57+
<td>
58+
<% if user.school %>
59+
<% sf_id = user.school.salesforce_id %>
60+
<% instance_url = ActiveForce.sfdc_client.instance_url rescue nil %>
61+
<% if instance_url.nil? %>
62+
<%= sf_id %>
63+
<% else %>
64+
<%= link_to user.school.name, instance_url + "/" + sf_id, target: '_blank' %>
65+
<% end %>
66+
<% end %>
67+
</td>
68+
<td>
69+
<% if !user.salesforce_contact_id.nil? %>
70+
<% sf_id = user.salesforce_contact_id %>
71+
<% sf_type = 'Contact' %>
72+
<% elsif !user.salesforce_lead_id.nil? %>
73+
<% sf_id = user.salesforce_lead_id%>
74+
<% sf_type = 'Lead' %>
75+
<% end %>
76+
77+
<% if !sf_id.nil? %>
78+
<% instance_url = ActiveForce.sfdc_client.instance_url rescue nil %>
79+
<% if instance_url.nil? %>
80+
<%= sf_id %>
81+
<% else %>
82+
<%= link_to sf_type, instance_url + "/" + sf_id, target: '_blank' %>
83+
<% end %>
84+
<% end %>
85+
</td>
86+
<td><%= link_to admin_security_log_path(search: { query: "user_id:#{user.id}" }) do %><i class="fa fa-history"></i><% end %></td>
6087
<td>
6188
<%= link_to become_admin_user_path(user),
6289
method: :post,
@@ -67,16 +94,14 @@
6794
</tr>
6895
<tr class="<%= zebra %> details">
6996
<td></td>
70-
<td colspan=6>
97+
<td colspan=8>
7198
<div>
7299
<div style="float:right">
73100
<span class="created"><i>Created:</i> <%= user.created_at.in_time_zone('Central Time (US & Canada)') %></span>
74101
<br/>
75102
<span class="updated"><i>Updated:</i> <%= user.updated_at.in_time_zone('Central Time (US & Canada)') %></span>
76103
</div>
77104

78-
<span class="full-name"><%= user.full_name || '(no name)' %></span> |
79-
80105
<% if user.is_administrator %>
81106
<span class="admin">Administrator</span> |
82107
<% end %>
@@ -85,39 +110,10 @@
85110
<span class="test">Test User</span> |
86111
<% end %>
87112

88-
<% sf_id = user.salesforce_contact_id %>
89-
90-
<% if sf_id.present? %>
91-
<span class="sf">
92-
<i>Salesforce:</i>
93-
94-
<% instance_url = ActiveForce.sfdc_client.instance_url rescue nil %>
95-
<% if instance_url.nil? %>
96-
<%= sf_id %>
97-
<% else %>
98-
<%= link_to sf_id, instance_url + "/" + sf_id, target: '_blank' %>
99-
<% end %>
100-
</span> |
101-
<% end %>
102-
103-
<% security_log_params = { query: "user_id:#{user.id}" } %>
104-
105-
<span class="security_log">
106-
<%= link_to "Security Log", admin_security_log_path(search: security_log_params), target: '_blank' %>
107-
</span> |
108-
109-
<span class="state">
110-
<i>State:</i> <%= user.state %>
111-
</span> |
112-
113113
<span class="uuid">
114114
<i>UUID:</i> <%= user.uuid %>
115115
</span>
116116

117-
<span class="support_identifier">
118-
<i>Support Identifier:</i> <%= user.support_identifier || '(no support_identifier)' %>
119-
</span>
120-
121117
<% if user.self_reported_school.present? %>
122118
| <span class="school">
123119
<i>Self-reported school:</i> <%= user.self_reported_school %>

spec/features/admin/users_spec.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424

2525
page.all(:css, '.expand').each(&:click)
2626

27-
expect(page).to have_content("#{@admin_user.full_name} | Administrator |")
28-
expect(page).to have_content("#{@sf_user.full_name} | Salesforce: booyah")
27+
expect(page).to have_content("Administrator |")
2928
end
3029

3130
it "can bring up the edit page without exploding" do

0 commit comments

Comments
 (0)