From 920c5241ef6a91c31abacb72b9e155f1bc335dfe Mon Sep 17 00:00:00 2001 From: Michael Volo Date: Wed, 7 Feb 2024 16:32:46 -0600 Subject: [PATCH] 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 ff9e4a80d2770cd7a1e4381a247ce4097e9ef3d8. * 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 --- .../create_or_update_salesforce_lead.rb | 22 ++---- app/views/admin/users/_form.html.erb | 72 ++++++++---------- app/views/admin/users/index.html.erb | 76 +++++++++---------- spec/features/admin/users_spec.rb | 3 +- 4 files changed, 73 insertions(+), 100 deletions(-) diff --git a/app/routines/newflow/create_or_update_salesforce_lead.rb b/app/routines/newflow/create_or_update_salesforce_lead.rb index afdd856f8b..bd1b4459b2 100644 --- a/app/routines/newflow/create_or_update_salesforce_lead.rb +++ b/app/routines/newflow/create_or_update_salesforce_lead.rb @@ -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 diff --git a/app/views/admin/users/_form.html.erb b/app/views/admin/users/_form.html.erb index 46bfe6c29d..11c0e76de7 100644 --- a/app/views/admin/users/_form.html.erb +++ b/app/views/admin/users/_form.html.erb @@ -122,6 +122,7 @@ + <% if @user.sheerid_verification_id %>
<%= f.label :sheerid_verification_id, class: "col-sm-2 control-label" %>
@@ -130,6 +131,35 @@

+ <% end %> + + <% if @user.school %> +
+ <%= f.label :school, class: "col-sm-2 control-label" %> +
+

+ <% 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 %> +

+
+
+ <% end %> + + <% if @user.which_books %> +
+ <%= f.label :which_books, class: "col-sm-2 control-label" %> +
+

+ <%= @user.which_books %> +

+
+
+ <% end %> <% if @user.sheerid_reported_school %>
@@ -149,11 +179,7 @@ <% sf_id = @user.salesforce_lead_id %>

<% 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? %> @@ -323,33 +349,6 @@

-
- <%= f.label :is_kip, 'Key Institutional Partner?', class: "col-sm-2 control-label" %> -
-
- <%= f.check_box :is_kip, style: 'margin-left: 0px' %> -
-
-
- -
- <%= f.label :is_b_r_i_user, 'BRI User?', class: "col-sm-2 control-label" %> -
-
- <%= f.check_box :is_b_r_i_user, style: 'margin-left: 0px' %> -
-
-
- -
- <%= f.label :grant_tutor_access, 'Grant Tutor Access?', class: "col-sm-2 control-label" %> -
-
- <%= f.check_box :grant_tutor_access, style: 'margin-left: 0px' %> -
-
-
-
<%= f.label :is_administrator, 'Administrator?', class: "col-sm-2 control-label" %>
@@ -368,15 +367,6 @@
-
- <%= f.label :opt_out_of_cookies, 'Opt Out of Cookies?', class: "col-sm-2 control-label" %> -
-
- <%= f.check_box :opt_out_of_cookies, style: 'margin-left: 0px' %> -
-
-
- <% if @user.external_uuids.any? %>
diff --git a/app/views/admin/users/index.html.erb b/app/views/admin/users/index.html.erb index 0a20bc0bc0..e5aabdd9f4 100644 --- a/app/views/admin/users/index.html.erb +++ b/app/views/admin/users/index.html.erb @@ -37,9 +37,9 @@ Last Name Faculty Status Role - School Type - KIP? - Grant Tutor Access? + School + Salesforce + <% @handler_result.outputs[:items].each do |user| %> @@ -52,11 +52,38 @@ <%= link_to user.id, edit_admin_user_path(user), target: '_blank' %> <%= user.first_name || '---' %> <%= user.last_name || '---' %> - <%= user.faculty_status %> - <%= user.unknown_role? ? "Unknown" : user.role.capitalize %> - <%= user.school_type %> - <%= user.is_kip ? 'Yes' : 'No' %> - <%= user.grant_tutor_access ? 'Yes' : 'No' %> + <%= user.faculty_status.humanize %> + <%= user.school_type.humanize %> + + <% 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 %> + + + <% 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 %> + + <%= link_to admin_security_log_path(search: { query: "user_id:#{user.id}" }) do %><% end %> <%= link_to become_admin_user_path(user), method: :post, @@ -67,7 +94,7 @@ - +
Created: <%= user.created_at.in_time_zone('Central Time (US & Canada)') %> @@ -75,8 +102,6 @@ Updated: <%= user.updated_at.in_time_zone('Central Time (US & Canada)') %>
- <%= user.full_name || '(no name)' %> | - <% if user.is_administrator %> Administrator | <% end %> @@ -85,39 +110,10 @@ Test User | <% end %> - <% sf_id = user.salesforce_contact_id %> - - <% if sf_id.present? %> - - Salesforce: - - <% 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 %> - | - <% end %> - - <% security_log_params = { query: "user_id:#{user.id}" } %> - - - <%= link_to "Security Log", admin_security_log_path(search: security_log_params), target: '_blank' %> - | - - - State: <%= user.state %> - | - UUID: <%= user.uuid %> - - Support Identifier: <%= user.support_identifier || '(no support_identifier)' %> - - <% if user.self_reported_school.present? %> | Self-reported school: <%= user.self_reported_school %> diff --git a/spec/features/admin/users_spec.rb b/spec/features/admin/users_spec.rb index 3278185d87..7bc3feb2f2 100644 --- a/spec/features/admin/users_spec.rb +++ b/spec/features/admin/users_spec.rb @@ -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