Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

60 строки
1.6KB

  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.AdminAPI.RelayController do
  5. use Pleroma.Web, :controller
  6. alias Pleroma.ModerationLog
  7. alias Pleroma.Web.ActivityPub.Relay
  8. alias Pleroma.Web.Plugs.OAuthScopesPlug
  9. require Logger
  10. plug(Pleroma.Web.ApiSpec.CastAndValidate)
  11. plug(
  12. OAuthScopesPlug,
  13. %{scopes: ["write:follows"], admin: true}
  14. when action in [:follow, :unfollow]
  15. )
  16. plug(OAuthScopesPlug, %{scopes: ["read"], admin: true} when action == :index)
  17. action_fallback(Pleroma.Web.AdminAPI.FallbackController)
  18. defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.Admin.RelayOperation
  19. def index(conn, _params) do
  20. with {:ok, list} <- Relay.list() do
  21. json(conn, %{relays: list})
  22. end
  23. end
  24. def follow(%{assigns: %{user: admin}, body_params: %{relay_url: target}} = conn, _) do
  25. with {:ok, _message} <- Relay.follow(target) do
  26. ModerationLog.insert_log(%{action: "relay_follow", actor: admin, target: target})
  27. json(conn, %{actor: target, followed_back: target in Relay.following()})
  28. else
  29. _ ->
  30. conn
  31. |> put_status(500)
  32. |> json(target)
  33. end
  34. end
  35. def unfollow(%{assigns: %{user: admin}, body_params: %{relay_url: target} = params} = conn, _) do
  36. with {:ok, _message} <- Relay.unfollow(target, %{force: params[:force]}) do
  37. ModerationLog.insert_log(%{action: "relay_unfollow", actor: admin, target: target})
  38. json(conn, target)
  39. else
  40. _ ->
  41. conn
  42. |> put_status(500)
  43. |> json(target)
  44. end
  45. end
  46. end