mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-23 20:18:00 +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 Phoenix.Controller
|
||||
alias Philomena.Users.User
|
||||
|
||||
@doc false
|
||||
@spec init(any()) :: any()
|
||||
|
@ -41,6 +42,9 @@ defmodule PhilomenaWeb.LimitPlug do
|
|||
amt <= limit ->
|
||||
conn
|
||||
|
||||
is_staff(conn.assigns.current_user) ->
|
||||
conn
|
||||
|
||||
true ->
|
||||
conn
|
||||
|> Controller.put_flash(:error, error)
|
||||
|
@ -49,6 +53,11 @@ defmodule PhilomenaWeb.LimitPlug do
|
|||
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(_), do: nil
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue