From b48a07f517d719c4dd7ed0ec9013af15d596992d Mon Sep 17 00:00:00 2001 From: Byron Mulvogue Date: Fri, 24 Jul 2020 12:51:23 +0000 Subject: [PATCH] Allow staff to bypass rate limits --- lib/philomena_web/plugs/limit_plug.ex | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/philomena_web/plugs/limit_plug.ex b/lib/philomena_web/plugs/limit_plug.ex index bc1ea8d2..caf46337 100644 --- a/lib/philomena_web/plugs/limit_plug.ex +++ b/lib/philomena_web/plugs/limit_plug.ex @@ -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