diff --git a/lib/philomena_web/controllers/report_controller.ex b/lib/philomena_web/controllers/report_controller.ex index 60723b04..1ebc2412 100644 --- a/lib/philomena_web/controllers/report_controller.ex +++ b/lib/philomena_web/controllers/report_controller.ex @@ -40,7 +40,7 @@ defmodule PhilomenaWeb.ReportController do conn |> put_flash( :error, - "You may not have more than 3 open reports at a time. Did you read the reporting tips?" + "You may not have more than #{max_reports()} open reports at a time. Did you read the reporting tips?" ) |> redirect(to: "/") @@ -68,7 +68,13 @@ defmodule PhilomenaWeb.ReportController do defp too_many_reports?(conn) do user = conn.assigns.current_user - too_many_reports_user?(user) or too_many_reports_ip?(conn) + case user do + %{role: role} when role != "user" -> + false + + _user -> + too_many_reports_user?(user) or too_many_reports_ip?(conn) + end end defp too_many_reports_user?(nil), do: false @@ -80,7 +86,7 @@ defmodule PhilomenaWeb.ReportController do |> where([r], r.state in ["open", "in_progress"]) |> Repo.aggregate(:count, :id) - reports_open >= 3 + reports_open >= max_reports() end defp too_many_reports_ip?(conn) do @@ -92,9 +98,13 @@ defmodule PhilomenaWeb.ReportController do |> where([r], r.state in ["open", "in_progress"]) |> Repo.aggregate(:count, :id) - reports_open >= 3 + reports_open >= max_reports() end defp redirect_path(_conn, nil), do: "/" defp redirect_path(conn, _user), do: Routes.report_path(conn, :index) + + defp max_reports do + 3 + end end