From abab1d680a7d26acd1004c0166e33c5b930fd99d Mon Sep 17 00:00:00 2001 From: August Thornton Date: Thu, 16 Jul 2020 13:15:48 -0600 Subject: [PATCH] report user_role when submitting error form We have a shared error form partial that we use for various response codes that we handle in the Canvas app. Support wanted to mimic our already existing behavior found in our Help Dialog. This change includes the user's current roles in the POST to generate an ErrorReport; if there is a current user session. We give the opportunity to submit comments for things like 404 or 500 errors that the app handles and that's where this change comes into play. closes FOO-490 flag = none test plan: * The easiest way to test this commit out is to trigger a handled 500 error. I twiddled with some account settings code to make it happen. * You should get a spiffy image of a spacecraft and something along the lines of "Page Error", "Something broke unexpectedly" * There will be a "Click here to tell us what happened link" * Open up DevTools and head on over to the Network tab * Fill out the input and click the "Send Comments" button to submit the form * Inspect your network traffic and find the request to error_reports * Verify the Form Data includes the param "error[user_roles]" and it includes a comma seperated list of user roles * Find the associated ErrorReport for that submission /error_reports * Ensure it includes an optional data key for `user_roles:` below `type`, with the same comma seperated values that you inspected above Change-Id: I5e014b599e481e27e9a66683d038e6270fa50b1d Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/242809 Tested-by: Service Cloud Jenkins QA-Review: Ahmad Amireh Product-Review: Ahmad Amireh Reviewed-by: Charley Kline Reviewed-by: Simon Williams --- app/views/shared/errors/_error_form.html.erb | 1 + spec/controllers/errors_controller_spec.rb | 4 +++- spec/views/shared/errors/_error_form.html.erb_spec.rb | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/views/shared/errors/_error_form.html.erb b/app/views/shared/errors/_error_form.html.erb index fc8eeb289df..0f71edf8a69 100644 --- a/app/views/shared/errors/_error_form.html.erb +++ b/app/views/shared/errors/_error_form.html.erb @@ -26,6 +26,7 @@ <%= text_area :error, :comments, :style => "width: 100%; height: 100px; border: 1px solid #888;" %> <% if @current_user %> <%= before_label('email_optional', %{Email (optional)}) %> + <%= hidden_field :error, :user_roles, :value => @current_user.try(:roles, @domain_root_account).join(',') %> <% else %> <%= before_label('email_required', %{Email (required)}) %> <% end %> diff --git a/spec/controllers/errors_controller_spec.rb b/spec/controllers/errors_controller_spec.rb index 49a15da544c..565b88982b5 100644 --- a/spec/controllers/errors_controller_spec.rb +++ b/spec/controllers/errors_controller_spec.rb @@ -46,11 +46,13 @@ describe ErrorsController do error: { url: "someurl", message: "BigError", - email: "testerrors42@example.com" + email: "testerrors42@example.com", + user_roles: "user,student" } } assert_recorded_error expect(ErrorReport.last.email).to eq("testerrors42@example.com") + expect(ErrorReport.last.data["user_roles"]).to eq("user,student") end it "doesnt need authentication" do diff --git a/spec/views/shared/errors/_error_form.html.erb_spec.rb b/spec/views/shared/errors/_error_form.html.erb_spec.rb index 29c606a5fad..0df9fc7d48a 100644 --- a/spec/views/shared/errors/_error_form.html.erb_spec.rb +++ b/spec/views/shared/errors/_error_form.html.erb_spec.rb @@ -25,6 +25,7 @@ describe "/shared/errors/_error_form" do view_context render :partial => "shared/errors/error_form" expect(response).not_to be_nil + expect(response).to include("error[user_roles]") end end