Prevent error reports from being sent with short feedback (#2635)

pull/2637/head r2023.02.01-49
Adam Rutkowski 4 years ago committed by GitHub
parent 061cb6ec83
commit f678cfab25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -6,10 +6,12 @@ defmodule PlausibleWeb.ErrorReportController do
def submit_error_report(conn, %{
"error" => %{"trace_id" => trace_id, "user_feedback" => feedback}
}) do
reported_by = "#{conn.assigns.current_user.name} <#{conn.assigns.current_user.email}>"
email_template = PlausibleWeb.Email.error_report(reported_by, trace_id, feedback)
if String.length(String.trim(feedback)) > 5 do
reported_by = "#{conn.assigns.current_user.name} <#{conn.assigns.current_user.email}>"
email_template = PlausibleWeb.Email.error_report(reported_by, trace_id, feedback)
Plausible.Mailer.deliver_later(email_template)
Plausible.Mailer.deliver_later(email_template)
end
thanks(conn)
end

@ -68,6 +68,22 @@ defmodule PlausibleWeb.ErrorReportControllerTest do
})
end
test "short feedback is not sent", %{conn: conn} do
action_path = Routes.error_report_path(Endpoint, :submit_error_report)
conn =
post(conn, action_path, %{
"error" => %{"trace_id" => "some-trace-id", "user_feedback" => "short"}
})
assert html = html_response(conn, 200)
assert html =~ "Your report has been submitted"
refute_email_delivered_with(%{
subject: "Feedback to Sentry Trace some-trace-id"
})
end
test "submitting no feedback for authenticated user", %{conn: conn} do
action_path = Routes.error_report_path(Endpoint, :submit_error_report)

Loading…
Cancel
Save