AdminAPI: Omit relay user from users list
authorMaxim Filippov <colixer@gmail.com>
Wed, 30 Oct 2019 23:26:02 +0000 (02:26 +0300)
committerMaxim Filippov <colixer@gmail.com>
Wed, 30 Oct 2019 23:26:02 +0000 (02:26 +0300)
lib/pleroma/web/activity_pub/relay.ex
lib/pleroma/web/admin_api/admin_api_controller.ex
test/web/admin_api/admin_api_controller_test.exs

index f90d75a8a4de249ddc7437c7240db506b9d31222..fc2619680f8e00d96606e7918b1291d65519dbe5 100644 (file)
@@ -11,13 +11,17 @@ defmodule Pleroma.Web.ActivityPub.Relay do
 
   def get_actor do
     actor =
-      "#{Pleroma.Web.Endpoint.url()}/relay"
+      relay_ap_id()
       |> User.get_or_create_service_actor_by_ap_id()
 
     {:ok, actor} = User.set_invisible(actor, true)
     actor
   end
 
+  def relay_ap_id do
+    "#{Pleroma.Web.Endpoint.url()}/relay"
+  end
+
   @spec follow(String.t()) :: {:ok, Activity.t()} | {:error, any()}
   def follow(target_instance) do
     with %User{} = local_user <- get_actor(),
index 7ffbb23e7c77d83ce773f5a31120b64d4dc762be..4533d0114ac72a48ced1840fbac1421984f2268f 100644 (file)
@@ -333,7 +333,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
       email: params["email"]
     }
 
-    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),
          do:
            conn
            |> json(
@@ -345,6 +346,12 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
            )
   end
 
+  defp filter_relay_user(users) do
+    filtered_users = Enum.reject(users, &(&1.ap_id == Relay.relay_ap_id()))
+
+    {:ok, filtered_users, length(filtered_users)}
+  end
+
   @filters ~w(local external active deactivated is_admin is_moderator)
 
   @spec maybe_parse_filters(String.t()) :: %{required(String.t()) => true} | %{}
index 22c989892a976593df08ec619dcc31db985653cb..045c87e952bef70158c0ddd5aca0c68607042f80 100644 (file)
@@ -13,6 +13,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
   alias Pleroma.Tests.ObanHelpers
   alias Pleroma.User
   alias Pleroma.UserInviteToken
+  alias Pleroma.Web.ActivityPub.Relay
   alias Pleroma.Web.CommonAPI
   alias Pleroma.Web.MediaProxy
   import Pleroma.Factory
@@ -1044,6 +1045,32 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
                ]
              }
     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
 
   test "PATCH /api/pleroma/admin/users/activate" do