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.AdminAPIControllerTest do
6 use Pleroma.Web.ConnCase
7 use Oban.Testing, repo: Pleroma.Repo
9 import ExUnit.CaptureLog
11 import Pleroma.Factory
12 import Swoosh.TestAssertions
14 alias Pleroma.Activity
18 alias Pleroma.ModerationLog
20 alias Pleroma.Tests.ObanHelpers
23 alias Pleroma.Web.ActivityPub.Relay
24 alias Pleroma.Web.CommonAPI
25 alias Pleroma.Web.MediaProxy
28 Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
34 admin = insert(:user, is_admin: true)
35 token = insert(:oauth_admin_token, user: admin)
39 |> assign(:user, admin)
40 |> assign(:token, token)
42 {:ok, %{admin: admin, token: token, conn: conn}}
45 test "with valid `admin_token` query parameter, skips OAuth scopes check" do
46 clear_config([:admin_token], "password123")
50 conn = get(build_conn(), "/api/pleroma/admin/users/#{user.nickname}?admin_token=password123")
52 assert json_response(conn, 200)
55 describe "with [:auth, :enforce_oauth_admin_scope_usage]," do
56 setup do: clear_config([:auth, :enforce_oauth_admin_scope_usage], true)
58 test "GET /api/pleroma/admin/users/:nickname requires admin:read:accounts or broader scope",
61 url = "/api/pleroma/admin/users/#{user.nickname}"
63 good_token1 = insert(:oauth_token, user: admin, scopes: ["admin"])
64 good_token2 = insert(:oauth_token, user: admin, scopes: ["admin:read"])
65 good_token3 = insert(:oauth_token, user: admin, scopes: ["admin:read:accounts"])
67 bad_token1 = insert(:oauth_token, user: admin, scopes: ["read:accounts"])
68 bad_token2 = insert(:oauth_token, user: admin, scopes: ["admin:read:accounts:partial"])
71 for good_token <- [good_token1, good_token2, good_token3] do
74 |> assign(:user, admin)
75 |> assign(:token, good_token)
78 assert json_response(conn, 200)
81 for good_token <- [good_token1, good_token2, good_token3] do
85 |> assign(:token, good_token)
88 assert json_response(conn, :forbidden)
91 for bad_token <- [bad_token1, bad_token2, bad_token3] do
94 |> assign(:user, admin)
95 |> assign(:token, bad_token)
98 assert json_response(conn, :forbidden)
103 describe "unless [:auth, :enforce_oauth_admin_scope_usage]," do
104 setup do: clear_config([:auth, :enforce_oauth_admin_scope_usage], false)
106 test "GET /api/pleroma/admin/users/:nickname requires " <>
107 "read:accounts or admin:read:accounts or broader scope",
110 url = "/api/pleroma/admin/users/#{user.nickname}"
112 good_token1 = insert(:oauth_token, user: admin, scopes: ["admin"])
113 good_token2 = insert(:oauth_token, user: admin, scopes: ["admin:read"])
114 good_token3 = insert(:oauth_token, user: admin, scopes: ["admin:read:accounts"])
115 good_token4 = insert(:oauth_token, user: admin, scopes: ["read:accounts"])
116 good_token5 = insert(:oauth_token, user: admin, scopes: ["read"])
118 good_tokens = [good_token1, good_token2, good_token3, good_token4, good_token5]
120 bad_token1 = insert(:oauth_token, user: admin, scopes: ["read:accounts:partial"])
121 bad_token2 = insert(:oauth_token, user: admin, scopes: ["admin:read:accounts:partial"])
124 for good_token <- good_tokens do
127 |> assign(:user, admin)
128 |> assign(:token, good_token)
131 assert json_response(conn, 200)
134 for good_token <- good_tokens do
137 |> assign(:user, nil)
138 |> assign(:token, good_token)
141 assert json_response(conn, :forbidden)
144 for bad_token <- [bad_token1, bad_token2, bad_token3] do
147 |> assign(:user, admin)
148 |> assign(:token, bad_token)
151 assert json_response(conn, :forbidden)
156 describe "DELETE /api/pleroma/admin/users" do
157 test "single user", %{admin: admin, conn: conn} do
159 clear_config([:instance, :federating], true)
161 refute user.deactivated
163 with_mock Pleroma.Web.Federator,
164 publish: fn _ -> nil end do
167 |> put_req_header("accept", "application/json")
168 |> delete("/api/pleroma/admin/users?nickname=#{user.nickname}")
170 ObanHelpers.perform_all()
172 assert User.get_by_nickname(user.nickname).deactivated
174 log_entry = Repo.one(ModerationLog)
176 assert ModerationLog.get_log_entry_message(log_entry) ==
177 "@#{admin.nickname} deleted users: @#{user.nickname}"
179 assert json_response(conn, 200) == [user.nickname]
181 user = Repo.get(User, user.id)
182 assert user.deactivated
184 assert called(Pleroma.Web.Federator.publish(:_))
188 test "multiple users", %{admin: admin, conn: conn} do
189 user_one = insert(:user)
190 user_two = insert(:user)
194 |> put_req_header("accept", "application/json")
195 |> delete("/api/pleroma/admin/users", %{
196 nicknames: [user_one.nickname, user_two.nickname]
199 log_entry = Repo.one(ModerationLog)
201 assert ModerationLog.get_log_entry_message(log_entry) ==
202 "@#{admin.nickname} deleted users: @#{user_one.nickname}, @#{user_two.nickname}"
204 response = json_response(conn, 200)
205 assert response -- [user_one.nickname, user_two.nickname] == []
209 describe "/api/pleroma/admin/users" do
210 test "Create", %{conn: conn} do
213 |> put_req_header("accept", "application/json")
214 |> post("/api/pleroma/admin/users", %{
217 "nickname" => "lain",
218 "email" => "lain@example.org",
222 "nickname" => "lain2",
223 "email" => "lain2@example.org",
229 response = json_response(conn, 200) |> Enum.map(&Map.get(&1, "type"))
230 assert response == ["success", "success"]
232 log_entry = Repo.one(ModerationLog)
234 assert ["lain", "lain2"] -- Enum.map(log_entry.data["subjects"], & &1["nickname"]) == []
237 test "Cannot create user with existing email", %{conn: conn} do
242 |> put_req_header("accept", "application/json")
243 |> post("/api/pleroma/admin/users", %{
246 "nickname" => "lain",
247 "email" => user.email,
253 assert json_response(conn, 409) == [
257 "email" => user.email,
260 "error" => "email has already been taken",
266 test "Cannot create user with existing nickname", %{conn: conn} do
271 |> put_req_header("accept", "application/json")
272 |> post("/api/pleroma/admin/users", %{
275 "nickname" => user.nickname,
276 "email" => "someuser@plerama.social",
282 assert json_response(conn, 409) == [
286 "email" => "someuser@plerama.social",
287 "nickname" => user.nickname
289 "error" => "nickname has already been taken",
295 test "Multiple user creation works in transaction", %{conn: conn} do
300 |> put_req_header("accept", "application/json")
301 |> post("/api/pleroma/admin/users", %{
304 "nickname" => "newuser",
305 "email" => "newuser@pleroma.social",
309 "nickname" => "lain",
310 "email" => user.email,
316 assert json_response(conn, 409) == [
320 "email" => user.email,
323 "error" => "email has already been taken",
329 "email" => "newuser@pleroma.social",
330 "nickname" => "newuser"
337 assert User.get_by_nickname("newuser") === nil
341 describe "/api/pleroma/admin/users/:nickname" do
342 test "Show", %{conn: conn} do
345 conn = get(conn, "/api/pleroma/admin/users/#{user.nickname}")
348 "deactivated" => false,
349 "id" => to_string(user.id),
351 "nickname" => user.nickname,
352 "roles" => %{"admin" => false, "moderator" => false},
354 "avatar" => User.avatar_url(user) |> MediaProxy.url(),
355 "display_name" => HTML.strip_tags(user.name || user.nickname),
356 "confirmation_pending" => false,
357 "approval_pending" => false,
359 "registration_reason" => nil
362 assert expected == json_response(conn, 200)
365 test "when the user doesn't exist", %{conn: conn} do
368 conn = get(conn, "/api/pleroma/admin/users/#{user.nickname}")
370 assert %{"error" => "Not found"} == json_response(conn, 404)
374 describe "/api/pleroma/admin/users/follow" do
375 test "allows to force-follow another user", %{admin: admin, conn: conn} do
377 follower = insert(:user)
380 |> put_req_header("accept", "application/json")
381 |> post("/api/pleroma/admin/users/follow", %{
382 "follower" => follower.nickname,
383 "followed" => user.nickname
386 user = User.get_cached_by_id(user.id)
387 follower = User.get_cached_by_id(follower.id)
389 assert User.following?(follower, user)
391 log_entry = Repo.one(ModerationLog)
393 assert ModerationLog.get_log_entry_message(log_entry) ==
394 "@#{admin.nickname} made @#{follower.nickname} follow @#{user.nickname}"
398 describe "/api/pleroma/admin/users/unfollow" do
399 test "allows to force-unfollow another user", %{admin: admin, conn: conn} do
401 follower = insert(:user)
403 User.follow(follower, user)
406 |> put_req_header("accept", "application/json")
407 |> post("/api/pleroma/admin/users/unfollow", %{
408 "follower" => follower.nickname,
409 "followed" => user.nickname
412 user = User.get_cached_by_id(user.id)
413 follower = User.get_cached_by_id(follower.id)
415 refute User.following?(follower, user)
417 log_entry = Repo.one(ModerationLog)
419 assert ModerationLog.get_log_entry_message(log_entry) ==
420 "@#{admin.nickname} made @#{follower.nickname} unfollow @#{user.nickname}"
424 describe "PUT /api/pleroma/admin/users/tag" do
425 setup %{conn: conn} do
426 user1 = insert(:user, %{tags: ["x"]})
427 user2 = insert(:user, %{tags: ["y"]})
428 user3 = insert(:user, %{tags: ["unchanged"]})
432 |> put_req_header("accept", "application/json")
434 "/api/pleroma/admin/users/tag?nicknames[]=#{user1.nickname}&nicknames[]=" <>
435 "#{user2.nickname}&tags[]=foo&tags[]=bar"
438 %{conn: conn, user1: user1, user2: user2, user3: user3}
441 test "it appends specified tags to users with specified nicknames", %{
447 assert empty_json_response(conn)
448 assert User.get_cached_by_id(user1.id).tags == ["x", "foo", "bar"]
449 assert User.get_cached_by_id(user2.id).tags == ["y", "foo", "bar"]
451 log_entry = Repo.one(ModerationLog)
454 [user1.nickname, user2.nickname]
455 |> Enum.map(&"@#{&1}")
458 tags = ["foo", "bar"] |> Enum.join(", ")
460 assert ModerationLog.get_log_entry_message(log_entry) ==
461 "@#{admin.nickname} added tags: #{tags} to users: #{users}"
464 test "it does not modify tags of not specified users", %{conn: conn, user3: user3} do
465 assert empty_json_response(conn)
466 assert User.get_cached_by_id(user3.id).tags == ["unchanged"]
470 describe "DELETE /api/pleroma/admin/users/tag" do
471 setup %{conn: conn} do
472 user1 = insert(:user, %{tags: ["x"]})
473 user2 = insert(:user, %{tags: ["y", "z"]})
474 user3 = insert(:user, %{tags: ["unchanged"]})
478 |> put_req_header("accept", "application/json")
480 "/api/pleroma/admin/users/tag?nicknames[]=#{user1.nickname}&nicknames[]=" <>
481 "#{user2.nickname}&tags[]=x&tags[]=z"
484 %{conn: conn, user1: user1, user2: user2, user3: user3}
487 test "it removes specified tags from users with specified nicknames", %{
493 assert empty_json_response(conn)
494 assert User.get_cached_by_id(user1.id).tags == []
495 assert User.get_cached_by_id(user2.id).tags == ["y"]
497 log_entry = Repo.one(ModerationLog)
500 [user1.nickname, user2.nickname]
501 |> Enum.map(&"@#{&1}")
504 tags = ["x", "z"] |> Enum.join(", ")
506 assert ModerationLog.get_log_entry_message(log_entry) ==
507 "@#{admin.nickname} removed tags: #{tags} from users: #{users}"
510 test "it does not modify tags of not specified users", %{conn: conn, user3: user3} do
511 assert empty_json_response(conn)
512 assert User.get_cached_by_id(user3.id).tags == ["unchanged"]
516 describe "/api/pleroma/admin/users/:nickname/permission_group" do
517 test "GET is giving user_info", %{admin: admin, conn: conn} do
520 |> put_req_header("accept", "application/json")
521 |> get("/api/pleroma/admin/users/#{admin.nickname}/permission_group/")
523 assert json_response(conn, 200) == %{
525 "is_moderator" => false
529 test "/:right POST, can add to a permission group", %{admin: admin, conn: conn} do
534 |> put_req_header("accept", "application/json")
535 |> post("/api/pleroma/admin/users/#{user.nickname}/permission_group/admin")
537 assert json_response(conn, 200) == %{
541 log_entry = Repo.one(ModerationLog)
543 assert ModerationLog.get_log_entry_message(log_entry) ==
544 "@#{admin.nickname} made @#{user.nickname} admin"
547 test "/:right POST, can add to a permission group (multiple)", %{admin: admin, conn: conn} do
548 user_one = insert(:user)
549 user_two = insert(:user)
553 |> put_req_header("accept", "application/json")
554 |> post("/api/pleroma/admin/users/permission_group/admin", %{
555 nicknames: [user_one.nickname, user_two.nickname]
558 assert json_response(conn, 200) == %{"is_admin" => true}
560 log_entry = Repo.one(ModerationLog)
562 assert ModerationLog.get_log_entry_message(log_entry) ==
563 "@#{admin.nickname} made @#{user_one.nickname}, @#{user_two.nickname} admin"
566 test "/:right DELETE, can remove from a permission group", %{admin: admin, conn: conn} do
567 user = insert(:user, is_admin: true)
571 |> put_req_header("accept", "application/json")
572 |> delete("/api/pleroma/admin/users/#{user.nickname}/permission_group/admin")
574 assert json_response(conn, 200) == %{"is_admin" => false}
576 log_entry = Repo.one(ModerationLog)
578 assert ModerationLog.get_log_entry_message(log_entry) ==
579 "@#{admin.nickname} revoked admin role from @#{user.nickname}"
582 test "/:right DELETE, can remove from a permission group (multiple)", %{
586 user_one = insert(:user, is_admin: true)
587 user_two = insert(:user, is_admin: true)
591 |> put_req_header("accept", "application/json")
592 |> delete("/api/pleroma/admin/users/permission_group/admin", %{
593 nicknames: [user_one.nickname, user_two.nickname]
596 assert json_response(conn, 200) == %{"is_admin" => false}
598 log_entry = Repo.one(ModerationLog)
600 assert ModerationLog.get_log_entry_message(log_entry) ==
601 "@#{admin.nickname} revoked admin role from @#{user_one.nickname}, @#{
607 test "/api/pleroma/admin/users/:nickname/password_reset", %{conn: conn} do
612 |> put_req_header("accept", "application/json")
613 |> get("/api/pleroma/admin/users/#{user.nickname}/password_reset")
615 resp = json_response(conn, 200)
617 assert Regex.match?(~r/(http:\/\/|https:\/\/)/, resp["link"])
620 describe "GET /api/pleroma/admin/users" do
621 test "renders users array for the first page", %{conn: conn, admin: admin} do
622 user = insert(:user, local: false, tags: ["foo", "bar"])
623 user2 = insert(:user, approval_pending: true, registration_reason: "I'm a chill dude")
625 conn = get(conn, "/api/pleroma/admin/users?page=1")
630 "deactivated" => admin.deactivated,
632 "nickname" => admin.nickname,
633 "roles" => %{"admin" => true, "moderator" => false},
636 "avatar" => User.avatar_url(admin) |> MediaProxy.url(),
637 "display_name" => HTML.strip_tags(admin.name || admin.nickname),
638 "confirmation_pending" => false,
639 "approval_pending" => false,
640 "url" => admin.ap_id,
641 "registration_reason" => nil
644 "deactivated" => user.deactivated,
646 "nickname" => user.nickname,
647 "roles" => %{"admin" => false, "moderator" => false},
649 "tags" => ["foo", "bar"],
650 "avatar" => User.avatar_url(user) |> MediaProxy.url(),
651 "display_name" => HTML.strip_tags(user.name || user.nickname),
652 "confirmation_pending" => false,
653 "approval_pending" => false,
655 "registration_reason" => nil
658 "deactivated" => user2.deactivated,
660 "nickname" => user2.nickname,
661 "roles" => %{"admin" => false, "moderator" => false},
664 "avatar" => User.avatar_url(user2) |> MediaProxy.url(),
665 "display_name" => HTML.strip_tags(user2.name || user2.nickname),
666 "confirmation_pending" => false,
667 "approval_pending" => true,
668 "url" => user2.ap_id,
669 "registration_reason" => "I'm a chill dude"
672 |> Enum.sort_by(& &1["nickname"])
674 assert json_response(conn, 200) == %{
681 test "pagination works correctly with service users", %{conn: conn} do
682 service1 = User.get_or_create_service_actor_by_ap_id(Web.base_url() <> "/meido", "meido")
684 insert_list(25, :user)
686 assert %{"count" => 26, "page_size" => 10, "users" => users1} =
688 |> get("/api/pleroma/admin/users?page=1&filters=", %{page_size: "10"})
689 |> json_response(200)
691 assert Enum.count(users1) == 10
692 assert service1 not in users1
694 assert %{"count" => 26, "page_size" => 10, "users" => users2} =
696 |> get("/api/pleroma/admin/users?page=2&filters=", %{page_size: "10"})
697 |> json_response(200)
699 assert Enum.count(users2) == 10
700 assert service1 not in users2
702 assert %{"count" => 26, "page_size" => 10, "users" => users3} =
704 |> get("/api/pleroma/admin/users?page=3&filters=", %{page_size: "10"})
705 |> json_response(200)
707 assert Enum.count(users3) == 6
708 assert service1 not in users3
711 test "renders empty array for the second page", %{conn: conn} do
714 conn = get(conn, "/api/pleroma/admin/users?page=2")
716 assert json_response(conn, 200) == %{
723 test "regular search", %{conn: conn} do
724 user = insert(:user, nickname: "bob")
726 conn = get(conn, "/api/pleroma/admin/users?query=bo")
728 assert json_response(conn, 200) == %{
733 "deactivated" => user.deactivated,
735 "nickname" => user.nickname,
736 "roles" => %{"admin" => false, "moderator" => false},
739 "avatar" => User.avatar_url(user) |> MediaProxy.url(),
740 "display_name" => HTML.strip_tags(user.name || user.nickname),
741 "confirmation_pending" => false,
742 "approval_pending" => false,
744 "registration_reason" => nil
750 test "search by domain", %{conn: conn} do
751 user = insert(:user, nickname: "nickname@domain.com")
754 conn = get(conn, "/api/pleroma/admin/users?query=domain.com")
756 assert json_response(conn, 200) == %{
761 "deactivated" => user.deactivated,
763 "nickname" => user.nickname,
764 "roles" => %{"admin" => false, "moderator" => false},
767 "avatar" => User.avatar_url(user) |> MediaProxy.url(),
768 "display_name" => HTML.strip_tags(user.name || user.nickname),
769 "confirmation_pending" => false,
770 "approval_pending" => false,
772 "registration_reason" => nil
778 test "search by full nickname", %{conn: conn} do
779 user = insert(:user, nickname: "nickname@domain.com")
782 conn = get(conn, "/api/pleroma/admin/users?query=nickname@domain.com")
784 assert json_response(conn, 200) == %{
789 "deactivated" => user.deactivated,
791 "nickname" => user.nickname,
792 "roles" => %{"admin" => false, "moderator" => false},
795 "avatar" => User.avatar_url(user) |> MediaProxy.url(),
796 "display_name" => HTML.strip_tags(user.name || user.nickname),
797 "confirmation_pending" => false,
798 "approval_pending" => false,
800 "registration_reason" => nil
806 test "search by display name", %{conn: conn} do
807 user = insert(:user, name: "Display name")
810 conn = get(conn, "/api/pleroma/admin/users?name=display")
812 assert json_response(conn, 200) == %{
817 "deactivated" => user.deactivated,
819 "nickname" => user.nickname,
820 "roles" => %{"admin" => false, "moderator" => false},
823 "avatar" => User.avatar_url(user) |> MediaProxy.url(),
824 "display_name" => HTML.strip_tags(user.name || user.nickname),
825 "confirmation_pending" => false,
826 "approval_pending" => false,
828 "registration_reason" => nil
834 test "search by email", %{conn: conn} do
835 user = insert(:user, email: "email@example.com")
838 conn = get(conn, "/api/pleroma/admin/users?email=email@example.com")
840 assert json_response(conn, 200) == %{
845 "deactivated" => user.deactivated,
847 "nickname" => user.nickname,
848 "roles" => %{"admin" => false, "moderator" => false},
851 "avatar" => User.avatar_url(user) |> MediaProxy.url(),
852 "display_name" => HTML.strip_tags(user.name || user.nickname),
853 "confirmation_pending" => false,
854 "approval_pending" => false,
856 "registration_reason" => nil
862 test "regular search with page size", %{conn: conn} do
863 user = insert(:user, nickname: "aalice")
864 user2 = insert(:user, nickname: "alice")
866 conn1 = get(conn, "/api/pleroma/admin/users?query=a&page_size=1&page=1")
868 assert json_response(conn1, 200) == %{
873 "deactivated" => user.deactivated,
875 "nickname" => user.nickname,
876 "roles" => %{"admin" => false, "moderator" => false},
879 "avatar" => User.avatar_url(user) |> MediaProxy.url(),
880 "display_name" => HTML.strip_tags(user.name || user.nickname),
881 "confirmation_pending" => false,
882 "approval_pending" => false,
884 "registration_reason" => nil
889 conn2 = get(conn, "/api/pleroma/admin/users?query=a&page_size=1&page=2")
891 assert json_response(conn2, 200) == %{
896 "deactivated" => user2.deactivated,
898 "nickname" => user2.nickname,
899 "roles" => %{"admin" => false, "moderator" => false},
902 "avatar" => User.avatar_url(user2) |> MediaProxy.url(),
903 "display_name" => HTML.strip_tags(user2.name || user2.nickname),
904 "confirmation_pending" => false,
905 "approval_pending" => false,
906 "url" => user2.ap_id,
907 "registration_reason" => nil
913 test "only local users" do
914 admin = insert(:user, is_admin: true, nickname: "john")
915 token = insert(:oauth_admin_token, user: admin)
916 user = insert(:user, nickname: "bob")
918 insert(:user, nickname: "bobb", local: false)
922 |> assign(:user, admin)
923 |> assign(:token, token)
924 |> get("/api/pleroma/admin/users?query=bo&filters=local")
926 assert json_response(conn, 200) == %{
931 "deactivated" => user.deactivated,
933 "nickname" => user.nickname,
934 "roles" => %{"admin" => false, "moderator" => false},
937 "avatar" => User.avatar_url(user) |> MediaProxy.url(),
938 "display_name" => HTML.strip_tags(user.name || user.nickname),
939 "confirmation_pending" => false,
940 "approval_pending" => false,
942 "registration_reason" => nil
948 test "only local users with no query", %{conn: conn, admin: old_admin} do
949 admin = insert(:user, is_admin: true, nickname: "john")
950 user = insert(:user, nickname: "bob")
952 insert(:user, nickname: "bobb", local: false)
954 conn = get(conn, "/api/pleroma/admin/users?filters=local")
959 "deactivated" => user.deactivated,
961 "nickname" => user.nickname,
962 "roles" => %{"admin" => false, "moderator" => false},
965 "avatar" => User.avatar_url(user) |> MediaProxy.url(),
966 "display_name" => HTML.strip_tags(user.name || user.nickname),
967 "confirmation_pending" => false,
968 "approval_pending" => false,
970 "registration_reason" => nil
973 "deactivated" => admin.deactivated,
975 "nickname" => admin.nickname,
976 "roles" => %{"admin" => true, "moderator" => false},
979 "avatar" => User.avatar_url(admin) |> MediaProxy.url(),
980 "display_name" => HTML.strip_tags(admin.name || admin.nickname),
981 "confirmation_pending" => false,
982 "approval_pending" => false,
983 "url" => admin.ap_id,
984 "registration_reason" => nil
987 "deactivated" => false,
988 "id" => old_admin.id,
990 "nickname" => old_admin.nickname,
991 "roles" => %{"admin" => true, "moderator" => false},
993 "avatar" => User.avatar_url(old_admin) |> MediaProxy.url(),
994 "display_name" => HTML.strip_tags(old_admin.name || old_admin.nickname),
995 "confirmation_pending" => false,
996 "approval_pending" => false,
997 "url" => old_admin.ap_id,
998 "registration_reason" => nil
1001 |> Enum.sort_by(& &1["nickname"])
1003 assert json_response(conn, 200) == %{
1010 test "only unapproved users", %{conn: conn} do
1014 approval_pending: true,
1015 registration_reason: "Plz let me in!"
1018 insert(:user, nickname: "happyboy", approval_pending: false)
1020 conn = get(conn, "/api/pleroma/admin/users?filters=need_approval")
1025 "deactivated" => user.deactivated,
1027 "nickname" => user.nickname,
1028 "roles" => %{"admin" => false, "moderator" => false},
1031 "avatar" => User.avatar_url(user) |> MediaProxy.url(),
1032 "display_name" => HTML.strip_tags(user.name || user.nickname),
1033 "confirmation_pending" => false,
1034 "approval_pending" => true,
1035 "url" => user.ap_id,
1036 "registration_reason" => "Plz let me in!"
1039 |> Enum.sort_by(& &1["nickname"])
1041 assert json_response(conn, 200) == %{
1048 test "load only admins", %{conn: conn, admin: admin} do
1049 second_admin = insert(:user, is_admin: true)
1053 conn = get(conn, "/api/pleroma/admin/users?filters=is_admin")
1058 "deactivated" => false,
1060 "nickname" => admin.nickname,
1061 "roles" => %{"admin" => true, "moderator" => false},
1062 "local" => admin.local,
1064 "avatar" => User.avatar_url(admin) |> MediaProxy.url(),
1065 "display_name" => HTML.strip_tags(admin.name || admin.nickname),
1066 "confirmation_pending" => false,
1067 "approval_pending" => false,
1068 "url" => admin.ap_id,
1069 "registration_reason" => nil
1072 "deactivated" => false,
1073 "id" => second_admin.id,
1074 "nickname" => second_admin.nickname,
1075 "roles" => %{"admin" => true, "moderator" => false},
1076 "local" => second_admin.local,
1078 "avatar" => User.avatar_url(second_admin) |> MediaProxy.url(),
1079 "display_name" => HTML.strip_tags(second_admin.name || second_admin.nickname),
1080 "confirmation_pending" => false,
1081 "approval_pending" => false,
1082 "url" => second_admin.ap_id,
1083 "registration_reason" => nil
1086 |> Enum.sort_by(& &1["nickname"])
1088 assert json_response(conn, 200) == %{
1095 test "load only moderators", %{conn: conn} do
1096 moderator = insert(:user, is_moderator: true)
1100 conn = get(conn, "/api/pleroma/admin/users?filters=is_moderator")
1102 assert json_response(conn, 200) == %{
1107 "deactivated" => false,
1108 "id" => moderator.id,
1109 "nickname" => moderator.nickname,
1110 "roles" => %{"admin" => false, "moderator" => true},
1111 "local" => moderator.local,
1113 "avatar" => User.avatar_url(moderator) |> MediaProxy.url(),
1114 "display_name" => HTML.strip_tags(moderator.name || moderator.nickname),
1115 "confirmation_pending" => false,
1116 "approval_pending" => false,
1117 "url" => moderator.ap_id,
1118 "registration_reason" => nil
1124 test "load users with tags list", %{conn: conn} do
1125 user1 = insert(:user, tags: ["first"])
1126 user2 = insert(:user, tags: ["second"])
1130 conn = get(conn, "/api/pleroma/admin/users?tags[]=first&tags[]=second")
1135 "deactivated" => false,
1137 "nickname" => user1.nickname,
1138 "roles" => %{"admin" => false, "moderator" => false},
1139 "local" => user1.local,
1140 "tags" => ["first"],
1141 "avatar" => User.avatar_url(user1) |> MediaProxy.url(),
1142 "display_name" => HTML.strip_tags(user1.name || user1.nickname),
1143 "confirmation_pending" => false,
1144 "approval_pending" => false,
1145 "url" => user1.ap_id,
1146 "registration_reason" => nil
1149 "deactivated" => false,
1151 "nickname" => user2.nickname,
1152 "roles" => %{"admin" => false, "moderator" => false},
1153 "local" => user2.local,
1154 "tags" => ["second"],
1155 "avatar" => User.avatar_url(user2) |> MediaProxy.url(),
1156 "display_name" => HTML.strip_tags(user2.name || user2.nickname),
1157 "confirmation_pending" => false,
1158 "approval_pending" => false,
1159 "url" => user2.ap_id,
1160 "registration_reason" => nil
1163 |> Enum.sort_by(& &1["nickname"])
1165 assert json_response(conn, 200) == %{
1172 test "`active` filters out users pending approval", %{token: token} do
1173 insert(:user, approval_pending: true)
1174 %{id: user_id} = insert(:user, approval_pending: false)
1175 %{id: admin_id} = token.user
1179 |> assign(:user, token.user)
1180 |> assign(:token, token)
1181 |> get("/api/pleroma/admin/users?filters=active")
1187 %{"id" => ^admin_id},
1190 } = json_response(conn, 200)
1193 test "it works with multiple filters" do
1194 admin = insert(:user, nickname: "john", is_admin: true)
1195 token = insert(:oauth_admin_token, user: admin)
1196 user = insert(:user, nickname: "bob", local: false, deactivated: true)
1198 insert(:user, nickname: "ken", local: true, deactivated: true)
1199 insert(:user, nickname: "bobb", local: false, deactivated: false)
1203 |> assign(:user, admin)
1204 |> assign(:token, token)
1205 |> get("/api/pleroma/admin/users?filters=deactivated,external")
1207 assert json_response(conn, 200) == %{
1212 "deactivated" => user.deactivated,
1214 "nickname" => user.nickname,
1215 "roles" => %{"admin" => false, "moderator" => false},
1216 "local" => user.local,
1218 "avatar" => User.avatar_url(user) |> MediaProxy.url(),
1219 "display_name" => HTML.strip_tags(user.name || user.nickname),
1220 "confirmation_pending" => false,
1221 "approval_pending" => false,
1222 "url" => user.ap_id,
1223 "registration_reason" => nil
1229 test "it omits relay user", %{admin: admin, conn: conn} do
1230 assert %User{} = Relay.get_actor()
1232 conn = get(conn, "/api/pleroma/admin/users")
1234 assert json_response(conn, 200) == %{
1239 "deactivated" => admin.deactivated,
1241 "nickname" => admin.nickname,
1242 "roles" => %{"admin" => true, "moderator" => false},
1245 "avatar" => User.avatar_url(admin) |> MediaProxy.url(),
1246 "display_name" => HTML.strip_tags(admin.name || admin.nickname),
1247 "confirmation_pending" => false,
1248 "approval_pending" => false,
1249 "url" => admin.ap_id,
1250 "registration_reason" => nil
1257 test "PATCH /api/pleroma/admin/users/activate", %{admin: admin, conn: conn} do
1258 user_one = insert(:user, deactivated: true)
1259 user_two = insert(:user, deactivated: true)
1264 "/api/pleroma/admin/users/activate",
1265 %{nicknames: [user_one.nickname, user_two.nickname]}
1268 response = json_response(conn, 200)
1269 assert Enum.map(response["users"], & &1["deactivated"]) == [false, false]
1271 log_entry = Repo.one(ModerationLog)
1273 assert ModerationLog.get_log_entry_message(log_entry) ==
1274 "@#{admin.nickname} activated users: @#{user_one.nickname}, @#{user_two.nickname}"
1277 test "PATCH /api/pleroma/admin/users/deactivate", %{admin: admin, conn: conn} do
1278 user_one = insert(:user, deactivated: false)
1279 user_two = insert(:user, deactivated: false)
1284 "/api/pleroma/admin/users/deactivate",
1285 %{nicknames: [user_one.nickname, user_two.nickname]}
1288 response = json_response(conn, 200)
1289 assert Enum.map(response["users"], & &1["deactivated"]) == [true, true]
1291 log_entry = Repo.one(ModerationLog)
1293 assert ModerationLog.get_log_entry_message(log_entry) ==
1294 "@#{admin.nickname} deactivated users: @#{user_one.nickname}, @#{user_two.nickname}"
1297 test "PATCH /api/pleroma/admin/users/approve", %{admin: admin, conn: conn} do
1298 user_one = insert(:user, approval_pending: true)
1299 user_two = insert(:user, approval_pending: true)
1304 "/api/pleroma/admin/users/approve",
1305 %{nicknames: [user_one.nickname, user_two.nickname]}
1308 response = json_response(conn, 200)
1309 assert Enum.map(response["users"], & &1["approval_pending"]) == [false, false]
1311 log_entry = Repo.one(ModerationLog)
1313 assert ModerationLog.get_log_entry_message(log_entry) ==
1314 "@#{admin.nickname} approved users: @#{user_one.nickname}, @#{user_two.nickname}"
1317 test "PATCH /api/pleroma/admin/users/:nickname/toggle_activation", %{admin: admin, conn: conn} do
1318 user = insert(:user)
1320 conn = patch(conn, "/api/pleroma/admin/users/#{user.nickname}/toggle_activation")
1322 assert json_response(conn, 200) ==
1324 "deactivated" => !user.deactivated,
1326 "nickname" => user.nickname,
1327 "roles" => %{"admin" => false, "moderator" => false},
1330 "avatar" => User.avatar_url(user) |> MediaProxy.url(),
1331 "display_name" => HTML.strip_tags(user.name || user.nickname),
1332 "confirmation_pending" => false,
1333 "approval_pending" => false,
1334 "url" => user.ap_id,
1335 "registration_reason" => nil
1338 log_entry = Repo.one(ModerationLog)
1340 assert ModerationLog.get_log_entry_message(log_entry) ==
1341 "@#{admin.nickname} deactivated users: @#{user.nickname}"
1344 describe "PUT disable_mfa" do
1345 test "returns 200 and disable 2fa", %{conn: conn} do
1348 multi_factor_authentication_settings: %MFA.Settings{
1350 totp: %MFA.Settings.TOTP{secret: "otp_secret", confirmed: true}
1356 |> put("/api/pleroma/admin/users/disable_mfa", %{nickname: user.nickname})
1357 |> json_response(200)
1359 assert response == user.nickname
1360 mfa_settings = refresh_record(user).multi_factor_authentication_settings
1362 refute mfa_settings.enabled
1363 refute mfa_settings.totp.confirmed
1366 test "returns 404 if user not found", %{conn: conn} do
1369 |> put("/api/pleroma/admin/users/disable_mfa", %{nickname: "nickname"})
1370 |> json_response(404)
1372 assert response == %{"error" => "Not found"}
1376 describe "GET /api/pleroma/admin/restart" do
1377 setup do: clear_config(:configurable_from_database, true)
1379 test "pleroma restarts", %{conn: conn} do
1381 assert conn |> get("/api/pleroma/admin/restart") |> json_response(200) == %{}
1382 end) =~ "pleroma restarted"
1384 refute Restarter.Pleroma.need_reboot?()
1388 test "need_reboot flag", %{conn: conn} do
1390 |> get("/api/pleroma/admin/need_reboot")
1391 |> json_response(200) == %{"need_reboot" => false}
1393 Restarter.Pleroma.need_reboot()
1396 |> get("/api/pleroma/admin/need_reboot")
1397 |> json_response(200) == %{"need_reboot" => true}
1399 on_exit(fn -> Restarter.Pleroma.refresh() end)
1402 describe "GET /api/pleroma/admin/users/:nickname/statuses" do
1404 user = insert(:user)
1406 date1 = (DateTime.to_unix(DateTime.utc_now()) + 2000) |> DateTime.from_unix!()
1407 date2 = (DateTime.to_unix(DateTime.utc_now()) + 1000) |> DateTime.from_unix!()
1408 date3 = (DateTime.to_unix(DateTime.utc_now()) + 3000) |> DateTime.from_unix!()
1410 insert(:note_activity, user: user, published: date1)
1411 insert(:note_activity, user: user, published: date2)
1412 insert(:note_activity, user: user, published: date3)
1417 test "renders user's statuses", %{conn: conn, user: user} do
1418 conn = get(conn, "/api/pleroma/admin/users/#{user.nickname}/statuses")
1420 assert json_response(conn, 200) |> length() == 3
1423 test "renders user's statuses with a limit", %{conn: conn, user: user} do
1424 conn = get(conn, "/api/pleroma/admin/users/#{user.nickname}/statuses?page_size=2")
1426 assert json_response(conn, 200) |> length() == 2
1429 test "doesn't return private statuses by default", %{conn: conn, user: user} do
1430 {:ok, _private_status} = CommonAPI.post(user, %{status: "private", visibility: "private"})
1432 {:ok, _public_status} = CommonAPI.post(user, %{status: "public", visibility: "public"})
1434 conn = get(conn, "/api/pleroma/admin/users/#{user.nickname}/statuses")
1436 assert json_response(conn, 200) |> length() == 4
1439 test "returns private statuses with godmode on", %{conn: conn, user: user} do
1440 {:ok, _private_status} = CommonAPI.post(user, %{status: "private", visibility: "private"})
1442 {:ok, _public_status} = CommonAPI.post(user, %{status: "public", visibility: "public"})
1444 conn = get(conn, "/api/pleroma/admin/users/#{user.nickname}/statuses?godmode=true")
1446 assert json_response(conn, 200) |> length() == 5
1449 test "excludes reblogs by default", %{conn: conn, user: user} do
1450 other_user = insert(:user)
1451 {:ok, activity} = CommonAPI.post(user, %{status: "."})
1452 {:ok, %Activity{}} = CommonAPI.repeat(activity.id, other_user)
1454 conn_res = get(conn, "/api/pleroma/admin/users/#{other_user.nickname}/statuses")
1455 assert json_response(conn_res, 200) |> length() == 0
1458 get(conn, "/api/pleroma/admin/users/#{other_user.nickname}/statuses?with_reblogs=true")
1460 assert json_response(conn_res, 200) |> length() == 1
1464 describe "GET /api/pleroma/admin/moderation_log" do
1466 moderator = insert(:user, is_moderator: true)
1468 %{moderator: moderator}
1471 test "returns the log", %{conn: conn, admin: admin} do
1472 Repo.insert(%ModerationLog{
1476 "nickname" => admin.nickname,
1479 action: "relay_follow",
1480 target: "https://example.org/relay"
1482 inserted_at: NaiveDateTime.truncate(~N[2017-08-15 15:47:06.597036], :second)
1485 Repo.insert(%ModerationLog{
1489 "nickname" => admin.nickname,
1492 action: "relay_unfollow",
1493 target: "https://example.org/relay"
1495 inserted_at: NaiveDateTime.truncate(~N[2017-08-16 15:47:06.597036], :second)
1498 conn = get(conn, "/api/pleroma/admin/moderation_log")
1500 response = json_response(conn, 200)
1501 [first_entry, second_entry] = response["items"]
1503 assert response["total"] == 2
1504 assert first_entry["data"]["action"] == "relay_unfollow"
1506 assert first_entry["message"] ==
1507 "@#{admin.nickname} unfollowed relay: https://example.org/relay"
1509 assert second_entry["data"]["action"] == "relay_follow"
1511 assert second_entry["message"] ==
1512 "@#{admin.nickname} followed relay: https://example.org/relay"
1515 test "returns the log with pagination", %{conn: conn, admin: admin} do
1516 Repo.insert(%ModerationLog{
1520 "nickname" => admin.nickname,
1523 action: "relay_follow",
1524 target: "https://example.org/relay"
1526 inserted_at: NaiveDateTime.truncate(~N[2017-08-15 15:47:06.597036], :second)
1529 Repo.insert(%ModerationLog{
1533 "nickname" => admin.nickname,
1536 action: "relay_unfollow",
1537 target: "https://example.org/relay"
1539 inserted_at: NaiveDateTime.truncate(~N[2017-08-16 15:47:06.597036], :second)
1542 conn1 = get(conn, "/api/pleroma/admin/moderation_log?page_size=1&page=1")
1544 response1 = json_response(conn1, 200)
1545 [first_entry] = response1["items"]
1547 assert response1["total"] == 2
1548 assert response1["items"] |> length() == 1
1549 assert first_entry["data"]["action"] == "relay_unfollow"
1551 assert first_entry["message"] ==
1552 "@#{admin.nickname} unfollowed relay: https://example.org/relay"
1554 conn2 = get(conn, "/api/pleroma/admin/moderation_log?page_size=1&page=2")
1556 response2 = json_response(conn2, 200)
1557 [second_entry] = response2["items"]
1559 assert response2["total"] == 2
1560 assert response2["items"] |> length() == 1
1561 assert second_entry["data"]["action"] == "relay_follow"
1563 assert second_entry["message"] ==
1564 "@#{admin.nickname} followed relay: https://example.org/relay"
1567 test "filters log by date", %{conn: conn, admin: admin} do
1568 first_date = "2017-08-15T15:47:06Z"
1569 second_date = "2017-08-20T15:47:06Z"
1571 Repo.insert(%ModerationLog{
1575 "nickname" => admin.nickname,
1578 action: "relay_follow",
1579 target: "https://example.org/relay"
1581 inserted_at: NaiveDateTime.from_iso8601!(first_date)
1584 Repo.insert(%ModerationLog{
1588 "nickname" => admin.nickname,
1591 action: "relay_unfollow",
1592 target: "https://example.org/relay"
1594 inserted_at: NaiveDateTime.from_iso8601!(second_date)
1600 "/api/pleroma/admin/moderation_log?start_date=#{second_date}"
1603 response1 = json_response(conn1, 200)
1604 [first_entry] = response1["items"]
1606 assert response1["total"] == 1
1607 assert first_entry["data"]["action"] == "relay_unfollow"
1609 assert first_entry["message"] ==
1610 "@#{admin.nickname} unfollowed relay: https://example.org/relay"
1613 test "returns log filtered by user", %{conn: conn, admin: admin, moderator: moderator} do
1614 Repo.insert(%ModerationLog{
1618 "nickname" => admin.nickname,
1621 action: "relay_follow",
1622 target: "https://example.org/relay"
1626 Repo.insert(%ModerationLog{
1629 "id" => moderator.id,
1630 "nickname" => moderator.nickname,
1633 action: "relay_unfollow",
1634 target: "https://example.org/relay"
1638 conn1 = get(conn, "/api/pleroma/admin/moderation_log?user_id=#{moderator.id}")
1640 response1 = json_response(conn1, 200)
1641 [first_entry] = response1["items"]
1643 assert response1["total"] == 1
1644 assert get_in(first_entry, ["data", "actor", "id"]) == moderator.id
1647 test "returns log filtered by search", %{conn: conn, moderator: moderator} do
1648 ModerationLog.insert_log(%{
1650 action: "relay_follow",
1651 target: "https://example.org/relay"
1654 ModerationLog.insert_log(%{
1656 action: "relay_unfollow",
1657 target: "https://example.org/relay"
1660 conn1 = get(conn, "/api/pleroma/admin/moderation_log?search=unfo")
1662 response1 = json_response(conn1, 200)
1663 [first_entry] = response1["items"]
1665 assert response1["total"] == 1
1667 assert get_in(first_entry, ["data", "message"]) ==
1668 "@#{moderator.nickname} unfollowed relay: https://example.org/relay"
1672 test "gets a remote users when [:instance, :limit_to_local_content] is set to :unauthenticated",
1674 clear_config(Pleroma.Config.get([:instance, :limit_to_local_content]), :unauthenticated)
1675 user = insert(:user, %{local: false, nickname: "u@peer1.com"})
1676 conn = get(conn, "/api/pleroma/admin/users/#{user.nickname}/credentials")
1678 assert json_response(conn, 200)
1681 describe "GET /users/:nickname/credentials" do
1682 test "gets the user credentials", %{conn: conn} do
1683 user = insert(:user)
1684 conn = get(conn, "/api/pleroma/admin/users/#{user.nickname}/credentials")
1686 response = assert json_response(conn, 200)
1687 assert response["email"] == user.email
1690 test "returns 403 if requested by a non-admin" do
1691 user = insert(:user)
1695 |> assign(:user, user)
1696 |> get("/api/pleroma/admin/users/#{user.nickname}/credentials")
1698 assert json_response(conn, :forbidden)
1702 describe "PATCH /users/:nickname/credentials" do
1704 user = insert(:user)
1708 test "changes password and email", %{conn: conn, admin: admin, user: user} do
1709 assert user.password_reset_pending == false
1712 patch(conn, "/api/pleroma/admin/users/#{user.nickname}/credentials", %{
1713 "password" => "new_password",
1714 "email" => "new_email@example.com",
1715 "name" => "new_name"
1718 assert json_response(conn, 200) == %{"status" => "success"}
1720 ObanHelpers.perform_all()
1722 updated_user = User.get_by_id(user.id)
1724 assert updated_user.email == "new_email@example.com"
1725 assert updated_user.name == "new_name"
1726 assert updated_user.password_hash != user.password_hash
1727 assert updated_user.password_reset_pending == true
1729 [log_entry2, log_entry1] = ModerationLog |> Repo.all() |> Enum.sort()
1731 assert ModerationLog.get_log_entry_message(log_entry1) ==
1732 "@#{admin.nickname} updated users: @#{user.nickname}"
1734 assert ModerationLog.get_log_entry_message(log_entry2) ==
1735 "@#{admin.nickname} forced password reset for users: @#{user.nickname}"
1738 test "returns 403 if requested by a non-admin", %{user: user} do
1741 |> assign(:user, user)
1742 |> patch("/api/pleroma/admin/users/#{user.nickname}/credentials", %{
1743 "password" => "new_password",
1744 "email" => "new_email@example.com",
1745 "name" => "new_name"
1748 assert json_response(conn, :forbidden)
1751 test "changes actor type from permitted list", %{conn: conn, user: user} do
1752 assert user.actor_type == "Person"
1754 assert patch(conn, "/api/pleroma/admin/users/#{user.nickname}/credentials", %{
1755 "actor_type" => "Service"
1757 |> json_response(200) == %{"status" => "success"}
1759 updated_user = User.get_by_id(user.id)
1761 assert updated_user.actor_type == "Service"
1763 assert patch(conn, "/api/pleroma/admin/users/#{user.nickname}/credentials", %{
1764 "actor_type" => "Application"
1766 |> json_response(400) == %{"errors" => %{"actor_type" => "is invalid"}}
1769 test "update non existing user", %{conn: conn} do
1770 assert patch(conn, "/api/pleroma/admin/users/non-existing/credentials", %{
1771 "password" => "new_password"
1773 |> json_response(404) == %{"error" => "Not found"}
1777 describe "PATCH /users/:nickname/force_password_reset" do
1778 test "sets password_reset_pending to true", %{conn: conn} do
1779 user = insert(:user)
1780 assert user.password_reset_pending == false
1783 patch(conn, "/api/pleroma/admin/users/force_password_reset", %{nicknames: [user.nickname]})
1785 assert empty_json_response(conn) == ""
1787 ObanHelpers.perform_all()
1789 assert User.get_by_id(user.id).password_reset_pending == true
1793 describe "instances" do
1794 test "GET /instances/:instance/statuses", %{conn: conn} do
1795 user = insert(:user, local: false, nickname: "archaeme@archae.me")
1796 user2 = insert(:user, local: false, nickname: "test@test.com")
1797 insert_pair(:note_activity, user: user)
1798 activity = insert(:note_activity, user: user2)
1800 ret_conn = get(conn, "/api/pleroma/admin/instances/archae.me/statuses")
1802 response = json_response(ret_conn, 200)
1804 assert length(response) == 2
1806 ret_conn = get(conn, "/api/pleroma/admin/instances/test.com/statuses")
1808 response = json_response(ret_conn, 200)
1810 assert length(response) == 1
1812 ret_conn = get(conn, "/api/pleroma/admin/instances/nonexistent.com/statuses")
1814 response = json_response(ret_conn, 200)
1816 assert Enum.empty?(response)
1818 CommonAPI.repeat(activity.id, user)
1820 ret_conn = get(conn, "/api/pleroma/admin/instances/archae.me/statuses")
1821 response = json_response(ret_conn, 200)
1822 assert length(response) == 2
1824 ret_conn = get(conn, "/api/pleroma/admin/instances/archae.me/statuses?with_reblogs=true")
1825 response = json_response(ret_conn, 200)
1826 assert length(response) == 3
1830 describe "PATCH /confirm_email" do
1831 test "it confirms emails of two users", %{conn: conn, admin: admin} do
1832 [first_user, second_user] = insert_pair(:user, confirmation_pending: true)
1834 assert first_user.confirmation_pending == true
1835 assert second_user.confirmation_pending == true
1838 patch(conn, "/api/pleroma/admin/users/confirm_email", %{
1840 first_user.nickname,
1841 second_user.nickname
1845 assert ret_conn.status == 200
1847 assert first_user.confirmation_pending == true
1848 assert second_user.confirmation_pending == true
1850 log_entry = Repo.one(ModerationLog)
1852 assert ModerationLog.get_log_entry_message(log_entry) ==
1853 "@#{admin.nickname} confirmed email for users: @#{first_user.nickname}, @#{
1854 second_user.nickname
1859 describe "PATCH /resend_confirmation_email" do
1860 test "it resend emails for two users", %{conn: conn, admin: admin} do
1861 [first_user, second_user] = insert_pair(:user, confirmation_pending: true)
1864 patch(conn, "/api/pleroma/admin/users/resend_confirmation_email", %{
1866 first_user.nickname,
1867 second_user.nickname
1871 assert ret_conn.status == 200
1873 log_entry = Repo.one(ModerationLog)
1875 assert ModerationLog.get_log_entry_message(log_entry) ==
1876 "@#{admin.nickname} re-sent confirmation email for users: @#{first_user.nickname}, @#{
1877 second_user.nickname
1880 ObanHelpers.perform_all()
1881 assert_email_sent(Pleroma.Emails.UserEmail.account_confirmation_email(first_user))
1885 describe "/api/pleroma/admin/stats" do
1886 test "status visibility count", %{conn: conn} do
1887 admin = insert(:user, is_admin: true)
1888 user = insert(:user)
1889 CommonAPI.post(user, %{visibility: "public", status: "hey"})
1890 CommonAPI.post(user, %{visibility: "unlisted", status: "hey"})
1891 CommonAPI.post(user, %{visibility: "unlisted", status: "hey"})
1895 |> assign(:user, admin)
1896 |> get("/api/pleroma/admin/stats")
1897 |> json_response(200)
1899 assert %{"direct" => 0, "private" => 0, "public" => 1, "unlisted" => 2} =
1900 response["status_visibility"]
1903 test "by instance", %{conn: conn} do
1904 admin = insert(:user, is_admin: true)
1905 user1 = insert(:user)
1906 instance2 = "instance2.tld"
1907 user2 = insert(:user, %{ap_id: "https://#{instance2}/@actor"})
1909 CommonAPI.post(user1, %{visibility: "public", status: "hey"})
1910 CommonAPI.post(user2, %{visibility: "unlisted", status: "hey"})
1911 CommonAPI.post(user2, %{visibility: "private", status: "hey"})
1915 |> assign(:user, admin)
1916 |> get("/api/pleroma/admin/stats", instance: instance2)
1917 |> json_response(200)
1919 assert %{"direct" => 0, "private" => 1, "public" => 0, "unlisted" => 1} =
1920 response["status_visibility"]
1925 # Needed for testing
1926 defmodule Pleroma.Web.Endpoint.NotReal do
1929 defmodule Pleroma.Captcha.NotReal do