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

This commit is contained in:
Adam Rutkowski 2023-02-01 09:36:14 +01:00 committed by GitHub
parent 061cb6ec83
commit f678cfab25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 3 deletions

View File

@ -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

View File

@ -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)