Allow staff to bypass rate limits

This commit is contained in:
Byron Mulvogue 2020-07-24 12:51:23 +00:00
parent f4b9a0902d
commit b48a07f517

View file

@ -10,6 +10,7 @@ defmodule PhilomenaWeb.LimitPlug do
alias Plug.Conn alias Plug.Conn
alias Phoenix.Controller alias Phoenix.Controller
alias Philomena.Users.User
@doc false @doc false
@spec init(any()) :: any() @spec init(any()) :: any()
@ -41,6 +42,9 @@ defmodule PhilomenaWeb.LimitPlug do
amt <= limit -> amt <= limit ->
conn conn
is_staff(conn.assigns.current_user) ->
conn
true -> true ->
conn conn
|> Controller.put_flash(:error, error) |> Controller.put_flash(:error, error)
@ -49,6 +53,11 @@ defmodule PhilomenaWeb.LimitPlug do
end end
end end
defp is_staff(%User{role: "admin"}), do: true
defp is_staff(%User{role: "moderator"}), do: true
defp is_staff(%User{role: "assistant"}), do: true
defp is_staff(_), do: false
defp current_user_id(%{id: id}), do: id defp current_user_id(%{id: id}), do: id
defp current_user_id(_), do: nil defp current_user_id(_), do: nil
end end