disable report limit for staff

This commit is contained in:
byte[] 2020-09-09 22:33:57 -04:00
parent 389100dae2
commit 75e07bfb13

View file

@ -40,7 +40,7 @@ defmodule PhilomenaWeb.ReportController do
conn conn
|> put_flash( |> put_flash(
:error, :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: "/") |> redirect(to: "/")
@ -68,8 +68,14 @@ defmodule PhilomenaWeb.ReportController do
defp too_many_reports?(conn) do defp too_many_reports?(conn) do
user = conn.assigns.current_user user = conn.assigns.current_user
case user do
%{role: role} when role != "user" ->
false
_user ->
too_many_reports_user?(user) or too_many_reports_ip?(conn) too_many_reports_user?(user) or too_many_reports_ip?(conn)
end end
end
defp too_many_reports_user?(nil), do: false defp too_many_reports_user?(nil), do: false
@ -80,7 +86,7 @@ defmodule PhilomenaWeb.ReportController do
|> where([r], r.state in ["open", "in_progress"]) |> where([r], r.state in ["open", "in_progress"])
|> Repo.aggregate(:count, :id) |> Repo.aggregate(:count, :id)
reports_open >= 3 reports_open >= max_reports()
end end
defp too_many_reports_ip?(conn) do defp too_many_reports_ip?(conn) do
@ -92,9 +98,13 @@ defmodule PhilomenaWeb.ReportController do
|> where([r], r.state in ["open", "in_progress"]) |> where([r], r.state in ["open", "in_progress"])
|> Repo.aggregate(:count, :id) |> Repo.aggregate(:count, :id)
reports_open >= 3 reports_open >= max_reports()
end end
defp redirect_path(_conn, nil), do: "/" defp redirect_path(_conn, nil), do: "/"
defp redirect_path(conn, _user), do: Routes.report_path(conn, :index) defp redirect_path(conn, _user), do: Routes.report_path(conn, :index)
defp max_reports do
3
end
end end