forked from AkkomaGang/akkoma
Merge branch 'feature/omit-relay-user' into 'develop'
AdminAPI: Omit relay user from users list Closes #1349 See merge request pleroma/pleroma!1924
This commit is contained in:
commit
74135e1318
3 changed files with 44 additions and 1 deletions
|
@ -11,13 +11,17 @@ defmodule Pleroma.Web.ActivityPub.Relay do
|
||||||
|
|
||||||
def get_actor do
|
def get_actor do
|
||||||
actor =
|
actor =
|
||||||
"#{Pleroma.Web.Endpoint.url()}/relay"
|
relay_ap_id()
|
||||||
|> User.get_or_create_service_actor_by_ap_id()
|
|> User.get_or_create_service_actor_by_ap_id()
|
||||||
|
|
||||||
{:ok, actor} = User.set_invisible(actor, true)
|
{:ok, actor} = User.set_invisible(actor, true)
|
||||||
actor
|
actor
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def relay_ap_id do
|
||||||
|
"#{Pleroma.Web.Endpoint.url()}/relay"
|
||||||
|
end
|
||||||
|
|
||||||
@spec follow(String.t()) :: {:ok, Activity.t()} | {:error, any()}
|
@spec follow(String.t()) :: {:ok, Activity.t()} | {:error, any()}
|
||||||
def follow(target_instance) do
|
def follow(target_instance) do
|
||||||
with %User{} = local_user <- get_actor(),
|
with %User{} = local_user <- get_actor(),
|
||||||
|
|
|
@ -334,6 +334,7 @@ def list_users(conn, params) do
|
||||||
}
|
}
|
||||||
|
|
||||||
with {:ok, users, count} <- Search.user(Map.merge(search_params, filters)),
|
with {:ok, users, count} <- Search.user(Map.merge(search_params, filters)),
|
||||||
|
{:ok, users, count} <- filter_relay_user(users, count),
|
||||||
do:
|
do:
|
||||||
conn
|
conn
|
||||||
|> json(
|
|> json(
|
||||||
|
@ -345,6 +346,17 @@ def list_users(conn, params) do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp filter_relay_user(users, count) do
|
||||||
|
filtered_users = Enum.reject(users, &relay_user?/1)
|
||||||
|
count = if Enum.any?(users, &relay_user?/1), do: length(filtered_users), else: count
|
||||||
|
|
||||||
|
{:ok, filtered_users, count}
|
||||||
|
end
|
||||||
|
|
||||||
|
defp relay_user?(user) do
|
||||||
|
user.ap_id == Relay.relay_ap_id()
|
||||||
|
end
|
||||||
|
|
||||||
@filters ~w(local external active deactivated is_admin is_moderator)
|
@filters ~w(local external active deactivated is_admin is_moderator)
|
||||||
|
|
||||||
@spec maybe_parse_filters(String.t()) :: %{required(String.t()) => true} | %{}
|
@spec maybe_parse_filters(String.t()) :: %{required(String.t()) => true} | %{}
|
||||||
|
|
|
@ -13,6 +13,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
||||||
alias Pleroma.Tests.ObanHelpers
|
alias Pleroma.Tests.ObanHelpers
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
alias Pleroma.UserInviteToken
|
alias Pleroma.UserInviteToken
|
||||||
|
alias Pleroma.Web.ActivityPub.Relay
|
||||||
alias Pleroma.Web.CommonAPI
|
alias Pleroma.Web.CommonAPI
|
||||||
alias Pleroma.Web.MediaProxy
|
alias Pleroma.Web.MediaProxy
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
|
@ -1044,6 +1045,32 @@ test "it works with multiple filters" do
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "it omits relay user", %{admin: admin} do
|
||||||
|
assert %User{} = Relay.get_actor()
|
||||||
|
|
||||||
|
conn =
|
||||||
|
build_conn()
|
||||||
|
|> assign(:user, admin)
|
||||||
|
|> get("/api/pleroma/admin/users")
|
||||||
|
|
||||||
|
assert json_response(conn, 200) == %{
|
||||||
|
"count" => 1,
|
||||||
|
"page_size" => 50,
|
||||||
|
"users" => [
|
||||||
|
%{
|
||||||
|
"deactivated" => admin.deactivated,
|
||||||
|
"id" => admin.id,
|
||||||
|
"nickname" => admin.nickname,
|
||||||
|
"roles" => %{"admin" => true, "moderator" => false},
|
||||||
|
"local" => true,
|
||||||
|
"tags" => [],
|
||||||
|
"avatar" => User.avatar_url(admin) |> MediaProxy.url(),
|
||||||
|
"display_name" => HTML.strip_tags(admin.name || admin.nickname)
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test "PATCH /api/pleroma/admin/users/activate" do
|
test "PATCH /api/pleroma/admin/users/activate" do
|
||||||
|
|
Loading…
Reference in a new issue