Skip to content

Commit

Permalink
School info in admin, Sentry message on school error during lead crea…
Browse files Browse the repository at this point in the history
…tion (#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
  • Loading branch information
mwvolo authored Feb 7, 2024
1 parent ebad9a1 commit 920c524
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 100 deletions.
22 changes: 5 additions & 17 deletions app/routines/newflow/create_or_update_salesforce_lead.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,31 +121,19 @@ def exec(user:)
event_data: { lead_id: lead.id.to_s }
)
else
if lead.errors.messages.inspect.include? == 'INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY'
Sentry.capture_message("Invalid school (#{user.school.salesforce_id}) for user (#{user.id})")
end
SecurityLog.create!(
user: user,
event_type: :educator_sign_up_failed,
event_data: {
message: "saving the user's lead id FAILED",
lead_id: lead.id
}
event_data: { lead_id: lead.id }
)
Sentry.capture_message("User #{user.id} was not successfully saved with lead #{lead.id}")
end
outputs.lead = lead
else
message = "#{self.class.name} error creating SF lead! #{lead.inspect}; User: #{user.id}; Error: #{lead.errors.full_messages}"

Sentry.capture_message(message)

SecurityLog.create!(
user: user,
event_type: :salesforce_error,
event_data: {
message: message
}
)
end

outputs.lead = lead
outputs.user = user
end

Expand Down
72 changes: 31 additions & 41 deletions app/views/admin/users/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
</div>
</div>

<% if @user.sheerid_verification_id %>
<div class="form-group">
<%= f.label :sheerid_verification_id, class: "col-sm-2 control-label" %>
<div class="col-sm-10">
Expand All @@ -130,6 +131,35 @@
</p>
</div>
</div>
<% end %>

<% if @user.school %>
<div class="form-group">
<%= f.label :school, class: "col-sm-2 control-label" %>
<div class="col-sm-10">
<p class="form-control-static">
<% sf_id = @user.school.salesforce_id %>
<% instance_url = ActiveForce.sfdc_client.instance_url rescue nil %>
<% if instance_url.nil? %>
<%= @user.school.name %>
<% else %>
<%= link_to @user.school.name, instance_url + "/" + sf_id, target: '_blank' %>
<% end %>
</p>
</div>
</div>
<% end %>

<% if @user.which_books %>
<div class="form-group">
<%= f.label :which_books, class: "col-sm-2 control-label" %>
<div class="col-sm-10">
<p class="form-control-static">
<%= @user.which_books %>
</p>
</div>
</div>
<% end %>

<% if @user.sheerid_reported_school %>
<div class="form-group">
Expand All @@ -149,11 +179,7 @@
<% sf_id = @user.salesforce_lead_id %>
<p class="form-control-static">
<% if sf_id.nil? %>
<%= link_to 'Not Set. Force Push?', force_update_lead_admin_user_path(@user),
remote: true, method: :post,
class: 'btn btn-default',
data: {confirm: "Are you sure you want to force sync this lead with Salesforce?"}
%>
No Lead
<% else %>
<% instance_url = ActiveForce.sfdc_client.instance_url rescue nil %>
<% if instance_url.nil? %>
Expand Down Expand Up @@ -323,33 +349,6 @@
</div>
</div>

<div class="form-group">
<%= f.label :is_kip, 'Key Institutional Partner?', class: "col-sm-2 control-label" %>
<div class="col-sm-10">
<div class="checkbox">
<%= f.check_box :is_kip, style: 'margin-left: 0px' %>
</div>
</div>
</div>

<div class="form-group">
<%= f.label :is_b_r_i_user, 'BRI User?', class: "col-sm-2 control-label" %>
<div class="col-sm-10">
<div class="checkbox">
<%= f.check_box :is_b_r_i_user, style: 'margin-left: 0px' %>
</div>
</div>
</div>

<div class="form-group">
<%= f.label :grant_tutor_access, 'Grant Tutor Access?', class: "col-sm-2 control-label" %>
<div class="col-sm-10">
<div class="checkbox">
<%= f.check_box :grant_tutor_access, style: 'margin-left: 0px' %>
</div>
</div>
</div>

<div class="form-group">
<%= f.label :is_administrator, 'Administrator?', class: "col-sm-2 control-label" %>
<div class="col-sm-10">
Expand All @@ -368,15 +367,6 @@
</div>
</div>

<div class="form-group">
<%= f.label :opt_out_of_cookies, 'Opt Out of Cookies?', class: "col-sm-2 control-label" %>
<div class="col-sm-10">
<div class="checkbox">
<%= f.check_box :opt_out_of_cookies, style: 'margin-left: 0px' %>
</div>
</div>
</div>

<% if @user.external_uuids.any? %>
<br>

Expand Down
76 changes: 36 additions & 40 deletions app/views/admin/users/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
<th>Last Name</th>
<th>Faculty Status</th>
<th>Role</th>
<th>School Type</th>
<th>KIP?</th>
<th>Grant Tutor Access?</th>
<th>School</th>
<th>Salesforce</th>
<th></th>
<th></th>
</tr>
<% @handler_result.outputs[:items].each do |user| %>
Expand All @@ -52,11 +52,38 @@
<td><%= link_to user.id, edit_admin_user_path(user), target: '_blank' %></td>
<td><%= user.first_name || '---' %></td>
<td><%= user.last_name || '---' %></td>
<td><%= user.faculty_status %></td>
<td><%= user.unknown_role? ? "Unknown" : user.role.capitalize %></td>
<td><%= user.school_type %></td>
<td><%= user.is_kip ? 'Yes' : 'No' %></td>
<td><%= user.grant_tutor_access ? 'Yes' : 'No' %></td>
<td><%= user.faculty_status.humanize %></td>
<td><%= user.school_type.humanize %></td>
<td>
<% if user.school %>
<% sf_id = user.school.salesforce_id %>
<% instance_url = ActiveForce.sfdc_client.instance_url rescue nil %>
<% if instance_url.nil? %>
<%= sf_id %>
<% else %>
<%= link_to user.school.name, instance_url + "/" + sf_id, target: '_blank' %>
<% end %>
<% end %>
</td>
<td>
<% if !user.salesforce_contact_id.nil? %>
<% sf_id = user.salesforce_contact_id %>
<% sf_type = 'Contact' %>
<% elsif !user.salesforce_lead_id.nil? %>
<% sf_id = user.salesforce_lead_id%>
<% sf_type = 'Lead' %>
<% end %>

<% if !sf_id.nil? %>
<% instance_url = ActiveForce.sfdc_client.instance_url rescue nil %>
<% if instance_url.nil? %>
<%= sf_id %>
<% else %>
<%= link_to sf_type, instance_url + "/" + sf_id, target: '_blank' %>
<% end %>
<% end %>
</td>
<td><%= link_to admin_security_log_path(search: { query: "user_id:#{user.id}" }) do %><i class="fa fa-history"></i><% end %></td>
<td>
<%= link_to become_admin_user_path(user),
method: :post,
Expand All @@ -67,16 +94,14 @@
</tr>
<tr class="<%= zebra %> details">
<td></td>
<td colspan=6>
<td colspan=8>
<div>
<div style="float:right">
<span class="created"><i>Created:</i> <%= user.created_at.in_time_zone('Central Time (US & Canada)') %></span>
<br/>
<span class="updated"><i>Updated:</i> <%= user.updated_at.in_time_zone('Central Time (US & Canada)') %></span>
</div>

<span class="full-name"><%= user.full_name || '(no name)' %></span> |

<% if user.is_administrator %>
<span class="admin">Administrator</span> |
<% end %>
Expand All @@ -85,39 +110,10 @@
<span class="test">Test User</span> |
<% end %>

<% sf_id = user.salesforce_contact_id %>

<% if sf_id.present? %>
<span class="sf">
<i>Salesforce:</i>

<% instance_url = ActiveForce.sfdc_client.instance_url rescue nil %>
<% if instance_url.nil? %>
<%= sf_id %>
<% else %>
<%= link_to sf_id, instance_url + "/" + sf_id, target: '_blank' %>
<% end %>
</span> |
<% end %>

<% security_log_params = { query: "user_id:#{user.id}" } %>

<span class="security_log">
<%= link_to "Security Log", admin_security_log_path(search: security_log_params), target: '_blank' %>
</span> |

<span class="state">
<i>State:</i> <%= user.state %>
</span> |

<span class="uuid">
<i>UUID:</i> <%= user.uuid %>
</span>

<span class="support_identifier">
<i>Support Identifier:</i> <%= user.support_identifier || '(no support_identifier)' %>
</span>

<% if user.self_reported_school.present? %>
| <span class="school">
<i>Self-reported school:</i> <%= user.self_reported_school %>
Expand Down
3 changes: 1 addition & 2 deletions spec/features/admin/users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@

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

expect(page).to have_content("#{@admin_user.full_name} | Administrator |")
expect(page).to have_content("#{@sf_user.full_name} | Salesforce: booyah")
expect(page).to have_content("Administrator |")
end

it "can bring up the edit page without exploding" do
Expand Down

0 comments on commit 920c524

Please sign in to comment.