Merge remote-tracking branch 'remotes/upstream/develop' into 1304-user-info-deprecation
[akkoma] / lib / pleroma / plugs / user_is_admin_plug.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Plugs.UserIsAdminPlug do
6 import Pleroma.Web.TranslationHelpers
7 import Plug.Conn
8 alias Pleroma.User
9
10 def init(options) do
11 options
12 end
13
14 def call(%{assigns: %{user: %User{is_admin: true}}} = conn, _) do
15 conn
16 end
17
18 def call(conn, _) do
19 conn
20 |> render_error(:forbidden, "User is not admin.")
21 |> halt
22 end
23 end