1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.AdminAPI.RelayController do
6 use Pleroma.Web, :controller
8 alias Pleroma.ModerationLog
9 alias Pleroma.Plugs.OAuthScopesPlug
10 alias Pleroma.Web.ActivityPub.Relay
14 plug(Pleroma.Web.ApiSpec.CastAndValidate)
18 %{scopes: ["write:follows"], admin: true}
19 when action in [:follow, :unfollow]
22 plug(OAuthScopesPlug, %{scopes: ["read"], admin: true} when action == :index)
24 action_fallback(Pleroma.Web.AdminAPI.FallbackController)
26 defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.Admin.RelayOperation
28 def index(conn, _params) do
29 with {:ok, list} <- Relay.list() do
30 json(conn, %{relays: list})
34 def follow(%{assigns: %{user: admin}, body_params: %{relay_url: target}} = conn, _) do
35 with {:ok, _message} <- Relay.follow(target) do
36 ModerationLog.insert_log(%{
37 action: "relay_follow",
51 def unfollow(%{assigns: %{user: admin}, body_params: %{relay_url: target}} = conn, _) do
52 with {:ok, _message} <- Relay.unfollow(target) do
53 ModerationLog.insert_log(%{
54 action: "relay_unfollow",