diff --git a/lib/philomena_web/plugs/limit_plug.ex b/lib/philomena_web/plugs/limit_plug.ex index caf46337..5aa4f9f9 100644 --- a/lib/philomena_web/plugs/limit_plug.ex +++ b/lib/philomena_web/plugs/limit_plug.ex @@ -45,6 +45,12 @@ defmodule PhilomenaWeb.LimitPlug do is_staff(conn.assigns.current_user) -> conn + ajax?(conn) -> + conn + |> Controller.put_flash(:error, error) + |> Conn.send_resp(:multiple_choices, "") + |> Conn.halt() + true -> conn |> Controller.put_flash(:error, error) @@ -60,4 +66,11 @@ defmodule PhilomenaWeb.LimitPlug do defp current_user_id(%{id: id}), do: id defp current_user_id(_), do: nil + + defp ajax?(conn) do + case Conn.get_req_header(conn, "x-requested-with") do + [value] -> String.downcase(value) == "xmlhttprequest" + _ -> false + end + end end