2020-05-22 13:52:26 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2023-01-02 20:38:50 +00:00
|
|
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
2020-05-22 13:52:26 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.AdminAPI.RelayController do
|
|
|
|
use Pleroma.Web, :controller
|
|
|
|
|
|
|
|
alias Pleroma.ModerationLog
|
|
|
|
alias Pleroma.Web.ActivityPub.Relay
|
2020-06-24 10:07:47 +00:00
|
|
|
alias Pleroma.Web.Plugs.OAuthScopesPlug
|
2020-05-22 13:52:26 +00:00
|
|
|
|
|
|
|
require Logger
|
|
|
|
|
|
|
|
plug(Pleroma.Web.ApiSpec.CastAndValidate)
|
|
|
|
|
|
|
|
plug(
|
|
|
|
OAuthScopesPlug,
|
2021-02-17 18:37:23 +00:00
|
|
|
%{scopes: ["admin:write:follows"]}
|
2020-05-22 13:52:26 +00:00
|
|
|
when action in [:follow, :unfollow]
|
|
|
|
)
|
|
|
|
|
2021-02-17 18:37:23 +00:00
|
|
|
plug(OAuthScopesPlug, %{scopes: ["admin:read"]} when action == :index)
|
2020-05-22 13:52:26 +00:00
|
|
|
|
|
|
|
action_fallback(Pleroma.Web.AdminAPI.FallbackController)
|
|
|
|
|
|
|
|
defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.Admin.RelayOperation
|
|
|
|
|
|
|
|
def index(conn, _params) do
|
|
|
|
with {:ok, list} <- Relay.list() do
|
|
|
|
json(conn, %{relays: list})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
Pleroma.Web.AdminAPI.RelayController: dialyzer errors
lib/pleroma/web/admin_api/controllers/relay_controller.ex:34:no_return
Function follow/2 has no local return.
________________________________________________________________________________
lib/pleroma/web/admin_api/controllers/relay_controller.ex:38:call
The function call will not succeed.
Phoenix.Controller.json(
_conn :: %{
:assigns => %{:user => _, _ => _},
:body_params => %{:relay_url => _, _ => _},
_ => _
},
%{:actor => binary(), :followed_back => boolean()}
)
breaks the contract
(Plug.Conn.t(), term()) :: Plug.Conn.t()
________________________________________________________________________________
lib/pleroma/web/admin_api/controllers/relay_controller.ex:41:call
The function call will not succeed.
Plug.Conn.put_status(
_conn :: %{
:assigns => %{:user => _, _ => _},
:body_params => %{:relay_url => _, _ => _},
_ => _
},
500
)
breaks the contract
(t(), status()) :: t()
________________________________________________________________________________
lib/pleroma/web/admin_api/controllers/relay_controller.ex:47:no_return
Function unfollow/2 has no local return.
________________________________________________________________________________
lib/pleroma/web/admin_api/controllers/relay_controller.ex:51:call
The function call will not succeed.
Phoenix.Controller.json(
_conn :: %{
:assigns => %{:user => _, _ => _},
:body_params => %{:relay_url => _, _ => _},
_ => _
},
_target :: binary()
)
breaks the contract
(Plug.Conn.t(), term()) :: Plug.Conn.t()
________________________________________________________________________________
lib/pleroma/web/admin_api/controllers/relay_controller.ex:54:call
The function call will not succeed.
Plug.Conn.put_status(
_conn :: %{
:assigns => %{:user => _, _ => _},
:body_params => %{:relay_url => _, _ => _},
_ => _
},
500
)
breaks the contract
(t(), status()) :: t()
2024-01-28 21:09:55 +00:00
|
|
|
def follow(%{assigns: %{user: admin}, body_params: %{"relay_url" => target}} = conn, _) do
|
2020-05-22 13:52:26 +00:00
|
|
|
with {:ok, _message} <- Relay.follow(target) do
|
2020-09-28 06:16:42 +00:00
|
|
|
ModerationLog.insert_log(%{action: "relay_follow", actor: admin, target: target})
|
2020-05-22 13:52:26 +00:00
|
|
|
|
2020-08-18 15:21:34 +00:00
|
|
|
json(conn, %{actor: target, followed_back: target in Relay.following()})
|
2020-05-22 13:52:26 +00:00
|
|
|
else
|
|
|
|
_ ->
|
|
|
|
conn
|
|
|
|
|> put_status(500)
|
|
|
|
|> json(target)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
Pleroma.Web.AdminAPI.RelayController: dialyzer errors
lib/pleroma/web/admin_api/controllers/relay_controller.ex:34:no_return
Function follow/2 has no local return.
________________________________________________________________________________
lib/pleroma/web/admin_api/controllers/relay_controller.ex:38:call
The function call will not succeed.
Phoenix.Controller.json(
_conn :: %{
:assigns => %{:user => _, _ => _},
:body_params => %{:relay_url => _, _ => _},
_ => _
},
%{:actor => binary(), :followed_back => boolean()}
)
breaks the contract
(Plug.Conn.t(), term()) :: Plug.Conn.t()
________________________________________________________________________________
lib/pleroma/web/admin_api/controllers/relay_controller.ex:41:call
The function call will not succeed.
Plug.Conn.put_status(
_conn :: %{
:assigns => %{:user => _, _ => _},
:body_params => %{:relay_url => _, _ => _},
_ => _
},
500
)
breaks the contract
(t(), status()) :: t()
________________________________________________________________________________
lib/pleroma/web/admin_api/controllers/relay_controller.ex:47:no_return
Function unfollow/2 has no local return.
________________________________________________________________________________
lib/pleroma/web/admin_api/controllers/relay_controller.ex:51:call
The function call will not succeed.
Phoenix.Controller.json(
_conn :: %{
:assigns => %{:user => _, _ => _},
:body_params => %{:relay_url => _, _ => _},
_ => _
},
_target :: binary()
)
breaks the contract
(Plug.Conn.t(), term()) :: Plug.Conn.t()
________________________________________________________________________________
lib/pleroma/web/admin_api/controllers/relay_controller.ex:54:call
The function call will not succeed.
Plug.Conn.put_status(
_conn :: %{
:assigns => %{:user => _, _ => _},
:body_params => %{:relay_url => _, _ => _},
_ => _
},
500
)
breaks the contract
(t(), status()) :: t()
2024-01-28 21:09:55 +00:00
|
|
|
def unfollow(
|
|
|
|
%{assigns: %{user: admin}, body_params: %{"relay_url" => target} = params} = conn,
|
|
|
|
_
|
|
|
|
) do
|
|
|
|
with {:ok, _message} <- Relay.unfollow(target, %{force: params["force"]}) do
|
2020-09-28 06:16:42 +00:00
|
|
|
ModerationLog.insert_log(%{action: "relay_unfollow", actor: admin, target: target})
|
2020-05-22 13:52:26 +00:00
|
|
|
|
|
|
|
json(conn, target)
|
|
|
|
else
|
|
|
|
_ ->
|
|
|
|
conn
|
|
|
|
|> put_status(500)
|
|
|
|
|> json(target)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|