1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.AdminAPI.UserControllerTest do
6 use Pleroma.Web.ConnCase, async: false
7 use Oban.Testing, repo: Pleroma.Repo
10 import Pleroma.Factory
13 alias Pleroma.ModerationLog
15 alias Pleroma.Tests.ObanHelpers
17 alias Pleroma.Web.ActivityPub.Relay
18 alias Pleroma.Web.CommonAPI
19 alias Pleroma.Web.Endpoint
20 alias Pleroma.Web.MediaProxy
23 Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
29 admin = insert(:user, is_admin: true)
30 token = insert(:oauth_admin_token, user: admin)
34 |> assign(:user, admin)
35 |> assign(:token, token)
37 {:ok, %{admin: admin, token: token, conn: conn}}
40 test "with valid `admin_token` query parameter, skips OAuth scopes check" do
41 clear_config([:instance, :admin_privileges], [:users_read])
42 clear_config([:admin_token], "password123")
46 conn = get(build_conn(), "/api/pleroma/admin/users/#{user.nickname}?admin_token=password123")
48 assert json_response_and_validate_schema(conn, 200)
51 describe "DELETE /api/pleroma/admin/users" do
52 test "single user", %{admin: admin, conn: conn} do
53 clear_config([:instance, :federating], true)
54 clear_config([:instance, :admin_privileges], [:users_delete])
58 avatar: %{"url" => [%{"href" => "https://someurl"}]},
59 banner: %{"url" => [%{"href" => "https://somebanner"}]},
64 # Create some activities to check they got deleted later
65 follower = insert(:user)
66 {:ok, _} = CommonAPI.post(user, %{status: "test"})
67 {:ok, _, _, _} = CommonAPI.follow(user, follower)
68 {:ok, _, _, _} = CommonAPI.follow(follower, user)
69 user = Repo.get(User, user.id)
70 assert user.note_count == 1
71 assert user.follower_count == 1
72 assert user.following_count == 1
75 with_mock Pleroma.Web.Federator,
76 publish: fn _ -> nil end,
77 perform: fn _, _ -> nil end do
80 |> put_req_header("accept", "application/json")
81 |> delete("/api/pleroma/admin/users?nickname=#{user.nickname}")
83 ObanHelpers.perform_all()
85 refute User.get_by_nickname(user.nickname).is_active
87 log_entry = Repo.one(ModerationLog)
89 assert ModerationLog.get_log_entry_message(log_entry) ==
90 "@#{admin.nickname} deleted users: @#{user.nickname}"
92 assert json_response_and_validate_schema(conn, 200) == [user.nickname]
94 user = Repo.get(User, user.id)
97 assert user.avatar == %{}
98 assert user.banner == %{}
99 assert user.note_count == 0
100 assert user.follower_count == 0
101 assert user.following_count == 0
102 assert user.bio == ""
103 assert user.name == nil
105 assert called(Pleroma.Web.Federator.publish(:_))
109 test "multiple users", %{admin: admin, conn: conn} do
110 clear_config([:instance, :admin_privileges], [:users_delete])
112 user_one = insert(:user)
113 user_two = insert(:user)
117 |> put_req_header("accept", "application/json")
118 |> put_req_header("content-type", "application/json")
119 |> delete("/api/pleroma/admin/users", %{
120 nicknames: [user_one.nickname, user_two.nickname]
122 |> json_response_and_validate_schema(200)
124 log_entry = Repo.one(ModerationLog)
126 assert ModerationLog.get_log_entry_message(log_entry) ==
127 "@#{admin.nickname} deleted users: @#{user_one.nickname}, @#{user_two.nickname}"
129 assert response -- [user_one.nickname, user_two.nickname] == []
132 test "Needs privileged role", %{conn: conn} do
133 clear_config([:instance, :admin_privileges], [])
137 |> put_req_header("accept", "application/json")
138 |> delete("/api/pleroma/admin/users?nickname=nickname")
140 assert json_response(response, :forbidden)
144 describe "/api/pleroma/admin/users" do
145 test "Create", %{conn: conn} do
148 |> put_req_header("accept", "application/json")
149 |> put_req_header("content-type", "application/json")
150 |> post("/api/pleroma/admin/users", %{
153 "nickname" => "lain",
154 "email" => "lain@example.org",
158 "nickname" => "lain2",
159 "email" => "lain2@example.org",
164 |> json_response_and_validate_schema(200)
165 |> Enum.map(&Map.get(&1, "type"))
167 assert response == ["success", "success"]
169 log_entry = Repo.one(ModerationLog)
171 assert ["lain", "lain2"] -- Enum.map(log_entry.data["subjects"], & &1["nickname"]) == []
174 test "Cannot create user with existing email", %{conn: conn} do
179 |> put_req_header("accept", "application/json")
180 |> put_req_header("content-type", "application/json")
181 |> post("/api/pleroma/admin/users", %{
184 "nickname" => "lain",
185 "email" => user.email,
191 assert json_response_and_validate_schema(conn, 409) == [
195 "email" => user.email,
198 "error" => "email has already been taken",
204 test "Cannot create user with existing nickname", %{conn: conn} do
209 |> put_req_header("accept", "application/json")
210 |> put_req_header("content-type", "application/json")
211 |> post("/api/pleroma/admin/users", %{
214 "nickname" => user.nickname,
215 "email" => "someuser@plerama.social",
221 assert json_response_and_validate_schema(conn, 409) == [
225 "email" => "someuser@plerama.social",
226 "nickname" => user.nickname
228 "error" => "nickname has already been taken",
234 test "Multiple user creation works in transaction", %{conn: conn} do
239 |> put_req_header("accept", "application/json")
240 |> put_req_header("content-type", "application/json")
241 |> post("/api/pleroma/admin/users", %{
244 "nickname" => "newuser",
245 "email" => "newuser@pleroma.social",
249 "nickname" => "lain",
250 "email" => user.email,
256 assert json_response_and_validate_schema(conn, 409) == [
260 "email" => user.email,
263 "error" => "email has already been taken",
269 "email" => "newuser@pleroma.social",
270 "nickname" => "newuser"
277 assert User.get_by_nickname("newuser") === nil
281 describe "GET /api/pleroma/admin/users/:nickname" do
283 clear_config([:instance, :admin_privileges], [:users_read])
286 test "returns 403 if not privileged with :users_read", %{conn: conn} do
287 clear_config([:instance, :admin_privileges], [])
289 conn = get(conn, "/api/pleroma/admin/users/user.nickname")
291 assert json_response(conn, :forbidden)
294 test "Show", %{conn: conn} do
297 conn = get(conn, "/api/pleroma/admin/users/#{user.nickname}")
299 assert user_response(user) == json_response_and_validate_schema(conn, 200)
302 test "when the user doesn't exist", %{conn: conn} do
305 conn = get(conn, "/api/pleroma/admin/users/#{user.nickname}")
307 assert %{"error" => "Not found"} == json_response_and_validate_schema(conn, 404)
310 test "requires admin:read:accounts or broader scope",
313 url = "/api/pleroma/admin/users/#{user.nickname}"
315 good_token1 = insert(:oauth_token, user: admin, scopes: ["admin"])
316 good_token2 = insert(:oauth_token, user: admin, scopes: ["admin:read"])
317 good_token3 = insert(:oauth_token, user: admin, scopes: ["admin:read:accounts"])
319 bad_token1 = insert(:oauth_token, user: admin, scopes: ["read:accounts"])
320 bad_token2 = insert(:oauth_token, user: admin, scopes: ["admin:read:accounts:partial"])
323 for good_token <- [good_token1, good_token2, good_token3] do
326 |> assign(:user, admin)
327 |> assign(:token, good_token)
330 assert json_response_and_validate_schema(conn, 200)
333 for good_token <- [good_token1, good_token2, good_token3] do
336 |> assign(:user, nil)
337 |> assign(:token, good_token)
340 assert json_response(conn, :forbidden)
343 for bad_token <- [bad_token1, bad_token2, bad_token3] do
346 |> assign(:user, admin)
347 |> assign(:token, bad_token)
350 assert json_response_and_validate_schema(conn, :forbidden)
355 describe "/api/pleroma/admin/users/follow" do
356 test "allows to force-follow another user", %{admin: admin, conn: conn} do
358 follower = insert(:user)
361 |> put_req_header("accept", "application/json")
362 |> put_req_header("content-type", "application/json")
363 |> post("/api/pleroma/admin/users/follow", %{
364 "follower" => follower.nickname,
365 "followed" => user.nickname
368 user = User.get_cached_by_id(user.id)
369 follower = User.get_cached_by_id(follower.id)
371 assert User.following?(follower, user)
373 log_entry = Repo.one(ModerationLog)
375 assert ModerationLog.get_log_entry_message(log_entry) ==
376 "@#{admin.nickname} made @#{follower.nickname} follow @#{user.nickname}"
380 describe "/api/pleroma/admin/users/unfollow" do
381 test "allows to force-unfollow another user", %{admin: admin, conn: conn} do
383 follower = insert(:user)
385 User.follow(follower, user)
388 |> put_req_header("accept", "application/json")
389 |> put_req_header("content-type", "application/json")
390 |> post("/api/pleroma/admin/users/unfollow", %{
391 "follower" => follower.nickname,
392 "followed" => user.nickname
395 user = User.get_cached_by_id(user.id)
396 follower = User.get_cached_by_id(follower.id)
398 refute User.following?(follower, user)
400 log_entry = Repo.one(ModerationLog)
402 assert ModerationLog.get_log_entry_message(log_entry) ==
403 "@#{admin.nickname} made @#{follower.nickname} unfollow @#{user.nickname}"
407 describe "GET /api/pleroma/admin/users" do
409 clear_config([:instance, :admin_privileges], [:users_read])
412 test "returns 403 if not privileged with :users_read", %{conn: conn} do
413 clear_config([:instance, :admin_privileges], [])
415 conn = get(conn, "/api/pleroma/admin/users?page=1")
417 assert json_response(conn, :forbidden)
420 test "renders users array for the first page", %{conn: conn, admin: admin} do
421 user = insert(:user, local: false, tags: ["foo", "bar"])
422 user2 = insert(:user, is_approved: false, registration_reason: "I'm a chill dude")
424 conn = get(conn, "/api/pleroma/admin/users?page=1")
431 "is_approved" => false,
432 "registration_reason" => "I'm a chill dude",
433 "actor_type" => "Person"
436 user_response(user, %{"local" => false, "tags" => ["foo", "bar"]}),
439 %{"roles" => %{"admin" => true, "moderator" => false}}
443 assert json_response_and_validate_schema(conn, 200) == %{
450 test "pagination works correctly with service users", %{conn: conn} do
451 service1 = User.get_or_create_service_actor_by_ap_id(Endpoint.url() <> "/meido", "meido")
453 insert_list(25, :user)
455 assert %{"count" => 26, "page_size" => 10, "users" => users1} =
457 |> get("/api/pleroma/admin/users?page=1&filters=", %{page_size: "10"})
458 |> json_response_and_validate_schema(200)
460 assert Enum.count(users1) == 10
461 assert service1 not in users1
463 assert %{"count" => 26, "page_size" => 10, "users" => users2} =
465 |> get("/api/pleroma/admin/users?page=2&filters=", %{page_size: "10"})
466 |> json_response_and_validate_schema(200)
468 assert Enum.count(users2) == 10
469 assert service1 not in users2
471 assert %{"count" => 26, "page_size" => 10, "users" => users3} =
473 |> get("/api/pleroma/admin/users?page=3&filters=", %{page_size: "10"})
474 |> json_response_and_validate_schema(200)
476 assert Enum.count(users3) == 6
477 assert service1 not in users3
480 test "renders empty array for the second page", %{conn: conn} do
483 conn = get(conn, "/api/pleroma/admin/users?page=2")
485 assert json_response_and_validate_schema(conn, 200) == %{
492 test "regular search", %{conn: conn} do
493 user = insert(:user, nickname: "bob")
495 conn = get(conn, "/api/pleroma/admin/users?query=bo")
497 assert json_response_and_validate_schema(conn, 200) == %{
500 "users" => [user_response(user, %{"local" => true})]
504 test "search by domain", %{conn: conn} do
505 user = insert(:user, nickname: "nickname@domain.com")
508 conn = get(conn, "/api/pleroma/admin/users?query=domain.com")
510 assert json_response_and_validate_schema(conn, 200) == %{
513 "users" => [user_response(user)]
517 test "search by full nickname", %{conn: conn} do
518 user = insert(:user, nickname: "nickname@domain.com")
521 conn = get(conn, "/api/pleroma/admin/users?query=nickname@domain.com")
523 assert json_response_and_validate_schema(conn, 200) == %{
526 "users" => [user_response(user)]
530 test "search by display name", %{conn: conn} do
531 user = insert(:user, name: "Display name")
534 conn = get(conn, "/api/pleroma/admin/users?name=display")
536 assert json_response_and_validate_schema(conn, 200) == %{
539 "users" => [user_response(user)]
543 test "search by email", %{conn: conn} do
544 user = insert(:user, email: "email@example.com")
547 conn = get(conn, "/api/pleroma/admin/users?email=email@example.com")
549 assert json_response_and_validate_schema(conn, 200) == %{
552 "users" => [user_response(user)]
556 test "regular search with page size", %{conn: conn} do
557 user = insert(:user, nickname: "aalice")
558 user2 = insert(:user, nickname: "alice")
560 conn1 = get(conn, "/api/pleroma/admin/users?query=a&page_size=1&page=1")
562 assert json_response_and_validate_schema(conn1, 200) == %{
565 "users" => [user_response(user2)]
568 conn2 = get(conn, "/api/pleroma/admin/users?query=a&page_size=1&page=2")
570 assert json_response_and_validate_schema(conn2, 200) == %{
573 "users" => [user_response(user)]
577 test "only local users" do
578 admin = insert(:user, is_admin: true, nickname: "john")
579 token = insert(:oauth_admin_token, user: admin)
580 user = insert(:user, nickname: "bob")
582 insert(:user, nickname: "bobb", local: false)
586 |> assign(:user, admin)
587 |> assign(:token, token)
588 |> get("/api/pleroma/admin/users?query=bo&filters=local")
590 assert json_response_and_validate_schema(conn, 200) == %{
593 "users" => [user_response(user)]
597 test "only local users with no query", %{conn: conn, admin: old_admin} do
598 admin = insert(:user, is_admin: true, nickname: "john")
599 user = insert(:user, nickname: "bob")
601 insert(:user, nickname: "bobb", local: false)
603 conn = get(conn, "/api/pleroma/admin/users?filters=local")
607 user_response(admin, %{
608 "roles" => %{"admin" => true, "moderator" => false}
610 user_response(old_admin, %{
612 "roles" => %{"admin" => true, "moderator" => false}
616 assert json_response_and_validate_schema(conn, 200) == %{
623 test "only unconfirmed users", %{conn: conn} do
624 sad_user = insert(:user, nickname: "sadboy", is_confirmed: false)
625 old_user = insert(:user, nickname: "oldboy", is_confirmed: false)
627 insert(:user, nickname: "happyboy", is_approved: true)
628 insert(:user, is_confirmed: true)
632 |> get("/api/pleroma/admin/users?filters=unconfirmed")
633 |> json_response_and_validate_schema(200)
636 Enum.map([old_user, sad_user], fn user ->
637 user_response(user, %{
638 "is_confirmed" => false,
639 "is_approved" => true
643 assert result == %{"count" => 2, "page_size" => 50, "users" => users}
646 test "only unapproved users", %{conn: conn} do
651 registration_reason: "Plz let me in!"
654 insert(:user, nickname: "happyboy", is_approved: true)
656 conn = get(conn, "/api/pleroma/admin/users?filters=need_approval")
661 %{"is_approved" => false, "registration_reason" => "Plz let me in!"}
665 assert json_response_and_validate_schema(conn, 200) == %{
672 test "load only admins", %{conn: conn, admin: admin} do
673 second_admin = insert(:user, is_admin: true)
677 conn = get(conn, "/api/pleroma/admin/users?filters=is_admin")
680 user_response(second_admin, %{
682 "roles" => %{"admin" => true, "moderator" => false}
684 user_response(admin, %{
686 "roles" => %{"admin" => true, "moderator" => false}
690 assert json_response_and_validate_schema(conn, 200) == %{
697 test "load only moderators", %{conn: conn} do
698 moderator = insert(:user, is_moderator: true)
702 conn = get(conn, "/api/pleroma/admin/users?filters=is_moderator")
704 assert json_response_and_validate_schema(conn, 200) == %{
708 user_response(moderator, %{
710 "roles" => %{"admin" => false, "moderator" => true}
716 test "load users with actor_type is Person", %{admin: admin, conn: conn} do
717 insert(:user, actor_type: "Service")
718 insert(:user, actor_type: "Application")
720 user1 = insert(:user)
721 user2 = insert(:user)
725 |> get(user_path(conn, :index), %{actor_types: ["Person"]})
726 |> json_response_and_validate_schema(200)
729 user_response(user2),
730 user_response(user1),
731 user_response(admin, %{"roles" => %{"admin" => true, "moderator" => false}})
734 assert response == %{"count" => 3, "page_size" => 50, "users" => users}
737 test "load users with actor_type is Person and Service", %{admin: admin, conn: conn} do
738 user_service = insert(:user, actor_type: "Service")
739 insert(:user, actor_type: "Application")
741 user1 = insert(:user)
742 user2 = insert(:user)
746 |> get(user_path(conn, :index), %{actor_types: ["Person", "Service"]})
747 |> json_response_and_validate_schema(200)
750 user_response(user2),
751 user_response(user1),
752 user_response(user_service, %{"actor_type" => "Service"}),
753 user_response(admin, %{"roles" => %{"admin" => true, "moderator" => false}})
756 assert response == %{"count" => 4, "page_size" => 50, "users" => users}
759 test "load users with actor_type is Service", %{conn: conn} do
760 user_service = insert(:user, actor_type: "Service")
761 insert(:user, actor_type: "Application")
767 |> get(user_path(conn, :index), %{actor_types: ["Service"]})
768 |> json_response_and_validate_schema(200)
770 users = [user_response(user_service, %{"actor_type" => "Service"})]
772 assert response == %{"count" => 1, "page_size" => 50, "users" => users}
775 test "load users with tags list", %{conn: conn} do
776 user1 = insert(:user, tags: ["first"])
777 user2 = insert(:user, tags: ["second"])
781 conn = get(conn, "/api/pleroma/admin/users?tags[]=first&tags[]=second")
784 user_response(user2, %{"tags" => ["second"]}),
785 user_response(user1, %{"tags" => ["first"]})
788 assert json_response_and_validate_schema(conn, 200) == %{
795 test "`active` filters out users pending approval", %{token: token} do
796 insert(:user, is_approved: false)
797 %{id: user_id} = insert(:user, is_approved: true)
798 %{id: admin_id} = token.user
802 |> assign(:user, token.user)
803 |> assign(:token, token)
804 |> get("/api/pleroma/admin/users?filters=active")
813 } = json_response_and_validate_schema(conn, 200)
816 test "it works with multiple filters" do
817 admin = insert(:user, nickname: "john", is_admin: true)
818 token = insert(:oauth_admin_token, user: admin)
819 user = insert(:user, nickname: "bob", local: false, is_active: false)
821 insert(:user, nickname: "ken", local: true, is_active: false)
822 insert(:user, nickname: "bobb", local: false, is_active: true)
826 |> assign(:user, admin)
827 |> assign(:token, token)
828 |> get("/api/pleroma/admin/users?filters=deactivated,external")
830 assert json_response_and_validate_schema(conn, 200) == %{
833 "users" => [user_response(user)]
837 test "it omits relay user", %{admin: admin, conn: conn} do
838 assert %User{} = Relay.get_actor()
840 conn = get(conn, "/api/pleroma/admin/users")
842 assert json_response_and_validate_schema(conn, 200) == %{
846 user_response(admin, %{"roles" => %{"admin" => true, "moderator" => false}})
852 test "PATCH /api/pleroma/admin/users/approve", %{admin: admin, conn: conn} do
853 clear_config([:instance, :admin_privileges], [:users_manage_invites])
855 user_one = insert(:user, is_approved: false)
856 user_two = insert(:user, is_approved: false)
860 |> put_req_header("content-type", "application/json")
862 "/api/pleroma/admin/users/approve",
863 %{nicknames: [user_one.nickname, user_two.nickname]}
866 response = json_response_and_validate_schema(conn, 200)
867 assert Enum.map(response["users"], & &1["is_approved"]) == [true, true]
869 log_entry = Repo.one(ModerationLog)
871 assert ModerationLog.get_log_entry_message(log_entry) ==
872 "@#{admin.nickname} approved users: @#{user_one.nickname}, @#{user_two.nickname}"
875 test "PATCH /api/pleroma/admin/users/approve returns 403 if not privileged with :users_manage_invites",
877 clear_config([:instance, :admin_privileges], [])
881 |> put_req_header("content-type", "application/json")
883 "/api/pleroma/admin/users/approve",
884 %{nicknames: ["user_one.nickname", "user_two.nickname"]}
887 assert json_response(conn, :forbidden)
890 test "PATCH /api/pleroma/admin/users/suggest", %{admin: admin, conn: conn} do
891 user1 = insert(:user, is_suggested: false)
892 user2 = insert(:user, is_suggested: false)
896 |> put_req_header("content-type", "application/json")
898 "/api/pleroma/admin/users/suggest",
899 %{nicknames: [user1.nickname, user2.nickname]}
901 |> json_response_and_validate_schema(200)
903 assert Enum.map(response["users"], & &1["is_suggested"]) == [true, true]
904 [user1, user2] = Repo.reload!([user1, user2])
906 assert user1.is_suggested
907 assert user2.is_suggested
909 log_entry = Repo.one(ModerationLog)
911 assert ModerationLog.get_log_entry_message(log_entry) ==
912 "@#{admin.nickname} added suggested users: @#{user1.nickname}, @#{user2.nickname}"
915 test "PATCH /api/pleroma/admin/users/unsuggest", %{admin: admin, conn: conn} do
916 user1 = insert(:user, is_suggested: true)
917 user2 = insert(:user, is_suggested: true)
921 |> put_req_header("content-type", "application/json")
923 "/api/pleroma/admin/users/unsuggest",
924 %{nicknames: [user1.nickname, user2.nickname]}
926 |> json_response_and_validate_schema(200)
928 assert Enum.map(response["users"], & &1["is_suggested"]) == [false, false]
929 [user1, user2] = Repo.reload!([user1, user2])
931 refute user1.is_suggested
932 refute user2.is_suggested
934 log_entry = Repo.one(ModerationLog)
936 assert ModerationLog.get_log_entry_message(log_entry) ==
937 "@#{admin.nickname} removed suggested users: @#{user1.nickname}, @#{user2.nickname}"
940 describe "user activation" do
941 test "PATCH /api/pleroma/admin/users/activate", %{admin: admin, conn: conn} do
942 clear_config([:instance, :admin_privileges], [:users_manage_activation_state])
944 user_one = insert(:user, is_active: false)
945 user_two = insert(:user, is_active: false)
949 |> put_req_header("content-type", "application/json")
951 "/api/pleroma/admin/users/activate",
952 %{nicknames: [user_one.nickname, user_two.nickname]}
955 response = json_response_and_validate_schema(conn, 200)
956 assert Enum.map(response["users"], & &1["is_active"]) == [true, true]
958 log_entry = Repo.one(ModerationLog)
960 assert ModerationLog.get_log_entry_message(log_entry) ==
961 "@#{admin.nickname} activated users: @#{user_one.nickname}, @#{user_two.nickname}"
964 test "PATCH /api/pleroma/admin/users/deactivate", %{admin: admin, conn: conn} do
965 clear_config([:instance, :admin_privileges], [:users_manage_activation_state])
967 user_one = insert(:user, is_active: true)
968 user_two = insert(:user, is_active: true)
972 |> put_req_header("content-type", "application/json")
974 "/api/pleroma/admin/users/deactivate",
975 %{nicknames: [user_one.nickname, user_two.nickname]}
978 response = json_response_and_validate_schema(conn, 200)
979 assert Enum.map(response["users"], & &1["is_active"]) == [false, false]
981 log_entry = Repo.one(ModerationLog)
983 assert ModerationLog.get_log_entry_message(log_entry) ==
984 "@#{admin.nickname} deactivated users: @#{user_one.nickname}, @#{user_two.nickname}"
987 test "PATCH /api/pleroma/admin/users/:nickname/toggle_activation", %{admin: admin, conn: conn} do
988 clear_config([:instance, :admin_privileges], [:users_manage_activation_state])
994 |> put_req_header("content-type", "application/json")
995 |> patch("/api/pleroma/admin/users/#{user.nickname}/toggle_activation")
997 assert json_response_and_validate_schema(conn, 200) ==
1000 %{"is_active" => !user.is_active}
1003 log_entry = Repo.one(ModerationLog)
1005 assert ModerationLog.get_log_entry_message(log_entry) ==
1006 "@#{admin.nickname} deactivated users: @#{user.nickname}"
1009 test "it requires privileged role :statuses_activation to activate", %{conn: conn} do
1010 clear_config([:instance, :admin_privileges], [])
1014 |> put_req_header("content-type", "application/json")
1016 "/api/pleroma/admin/users/activate",
1017 %{nicknames: ["user_one.nickname", "user_two.nickname"]}
1020 assert json_response(conn, :forbidden)
1023 test "it requires privileged role :statuses_activation to deactivate", %{conn: conn} do
1024 clear_config([:instance, :admin_privileges], [])
1028 |> put_req_header("content-type", "application/json")
1030 "/api/pleroma/admin/users/deactivate",
1031 %{nicknames: ["user_one.nickname", "user_two.nickname"]}
1034 assert json_response(conn, :forbidden)
1037 test "it requires privileged role :statuses_activation to toggle activation", %{conn: conn} do
1038 clear_config([:instance, :admin_privileges], [])
1042 |> put_req_header("content-type", "application/json")
1043 |> patch("/api/pleroma/admin/users/user.nickname/toggle_activation")
1045 assert json_response(conn, :forbidden)
1049 defp user_response(user, attrs \\ %{}) do
1051 "is_active" => user.is_active,
1053 "email" => user.email,
1054 "nickname" => user.nickname,
1055 "roles" => %{"admin" => false, "moderator" => false},
1056 "local" => user.local,
1058 "avatar" => User.avatar_url(user) |> MediaProxy.url(),
1059 "display_name" => HTML.strip_tags(user.name || user.nickname),
1060 "is_confirmed" => true,
1061 "is_approved" => true,
1062 "is_suggested" => false,
1063 "url" => user.ap_id,
1064 "registration_reason" => nil,
1065 "actor_type" => "Person",
1066 "created_at" => CommonAPI.Utils.to_masto_date(user.inserted_at)