Merge pull request #9 from philomena-dev/rate-limit-bypass

Allow staff to bypass rate limits
This commit is contained in:
liamwhite 2020-07-24 13:51:15 -04:00 committed by GitHub
commit f006635971
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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