mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-12-17 22:47:59 +01:00
Allow staff to bypass rate limits
This commit is contained in:
parent
f4b9a0902d
commit
b48a07f517
1 changed files with 9 additions and 0 deletions
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue