1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.Plugs.EnsurePrivilegedPlug do
7 Ensures staff are privileged enough to do certain tasks.
9 import Pleroma.Web.TranslationHelpers
19 def call(%{assigns: %{user: %User{is_admin: false, is_moderator: false}}} = conn, _) do
21 |> render_error(:forbidden, "User isn't privileged.")
26 %{assigns: %{user: %User{is_admin: is_admin, is_moderator: is_moderator}}} = conn,
29 if (is_admin and privilege in Config.get([:instance, :admin_privileges])) or
30 (is_moderator and privilege in Config.get([:instance, :moderator_privileges])) do
34 |> render_error(:forbidden, "User isn't privileged.")
41 |> render_error(:forbidden, "User isn't privileged.")