mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-30 14:57:59 +01:00
Merge pull request #9 from philomena-dev/rate-limit-bypass
Allow staff to bypass rate limits
This commit is contained in:
commit
f006635971
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