2018-12-23 15:11:29 -05:00
|
|
|
# Pleroma: A lightweight social networking server
|
2020-03-02 00:08:45 -05:00
|
|
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
2018-12-23 15:11:29 -05:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2018-11-17 16:11:18 -05:00
|
|
|
defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|
|
|
use Pleroma.Web.ConnCase
|
2019-09-22 09:08:07 -04:00
|
|
|
use Oban.Testing, repo: Pleroma.Repo
|
2018-11-17 16:11:18 -05:00
|
|
|
|
2020-02-08 04:55:37 -05:00
|
|
|
import ExUnit.CaptureLog
|
2020-05-01 08:30:39 -04:00
|
|
|
import Mock
|
|
|
|
import Pleroma.Factory
|
2020-07-11 00:20:35 -04:00
|
|
|
import Swoosh.TestAssertions
|
2020-02-08 04:55:37 -05:00
|
|
|
|
2019-05-16 15:09:18 -04:00
|
|
|
alias Pleroma.Activity
|
2020-02-08 04:55:37 -05:00
|
|
|
alias Pleroma.Config
|
2019-06-28 08:27:18 -04:00
|
|
|
alias Pleroma.HTML
|
2020-05-07 04:14:54 -04:00
|
|
|
alias Pleroma.MFA
|
2019-08-25 15:39:37 -04:00
|
|
|
alias Pleroma.ModerationLog
|
|
|
|
alias Pleroma.Repo
|
2019-09-22 09:08:07 -04:00
|
|
|
alias Pleroma.Tests.ObanHelpers
|
2019-02-10 16:57:38 -05:00
|
|
|
alias Pleroma.User
|
2020-05-01 09:31:05 -04:00
|
|
|
alias Pleroma.Web
|
2019-10-30 19:26:02 -04:00
|
|
|
alias Pleroma.Web.ActivityPub.Relay
|
2019-05-16 15:09:18 -04:00
|
|
|
alias Pleroma.Web.CommonAPI
|
2019-06-28 08:15:32 -04:00
|
|
|
alias Pleroma.Web.MediaProxy
|
2018-11-17 16:11:18 -05:00
|
|
|
|
2019-10-11 12:12:29 -04:00
|
|
|
setup_all do
|
|
|
|
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
|
|
|
|
|
|
|
:ok
|
|
|
|
end
|
|
|
|
|
2019-12-15 14:32:42 -05:00
|
|
|
setup do
|
|
|
|
admin = insert(:user, is_admin: true)
|
|
|
|
token = insert(:oauth_admin_token, user: admin)
|
|
|
|
|
|
|
|
conn =
|
|
|
|
build_conn()
|
|
|
|
|> assign(:user, admin)
|
|
|
|
|> assign(:token, token)
|
|
|
|
|
|
|
|
{:ok, %{admin: admin, token: token, conn: conn}}
|
2019-12-06 12:33:47 -05:00
|
|
|
end
|
|
|
|
|
2020-07-19 14:35:57 -04:00
|
|
|
test "with valid `admin_token` query parameter, skips OAuth scopes check" do
|
|
|
|
clear_config([:admin_token], "password123")
|
|
|
|
|
|
|
|
user = insert(:user)
|
|
|
|
|
|
|
|
conn = get(build_conn(), "/api/pleroma/admin/users/#{user.nickname}?admin_token=password123")
|
|
|
|
|
|
|
|
assert json_response(conn, 200)
|
|
|
|
end
|
|
|
|
|
2019-12-06 12:33:47 -05:00
|
|
|
describe "with [:auth, :enforce_oauth_admin_scope_usage]," do
|
2020-03-20 11:33:00 -04:00
|
|
|
setup do: clear_config([:auth, :enforce_oauth_admin_scope_usage], true)
|
2019-12-06 12:33:47 -05:00
|
|
|
|
2019-12-15 14:32:42 -05:00
|
|
|
test "GET /api/pleroma/admin/users/:nickname requires admin:read:accounts or broader scope",
|
|
|
|
%{admin: admin} do
|
2019-12-06 12:33:47 -05:00
|
|
|
user = insert(:user)
|
2019-12-07 09:49:53 -05:00
|
|
|
url = "/api/pleroma/admin/users/#{user.nickname}"
|
2019-12-06 12:33:47 -05:00
|
|
|
|
|
|
|
good_token1 = insert(:oauth_token, user: admin, scopes: ["admin"])
|
|
|
|
good_token2 = insert(:oauth_token, user: admin, scopes: ["admin:read"])
|
|
|
|
good_token3 = insert(:oauth_token, user: admin, scopes: ["admin:read:accounts"])
|
|
|
|
|
|
|
|
bad_token1 = insert(:oauth_token, user: admin, scopes: ["read:accounts"])
|
|
|
|
bad_token2 = insert(:oauth_token, user: admin, scopes: ["admin:read:accounts:partial"])
|
|
|
|
bad_token3 = nil
|
|
|
|
|
|
|
|
for good_token <- [good_token1, good_token2, good_token3] do
|
|
|
|
conn =
|
|
|
|
build_conn()
|
|
|
|
|> assign(:user, admin)
|
|
|
|
|> assign(:token, good_token)
|
2019-12-07 09:49:53 -05:00
|
|
|
|> get(url)
|
2019-12-06 12:33:47 -05:00
|
|
|
|
|
|
|
assert json_response(conn, 200)
|
|
|
|
end
|
|
|
|
|
2019-12-07 09:49:53 -05:00
|
|
|
for good_token <- [good_token1, good_token2, good_token3] do
|
|
|
|
conn =
|
|
|
|
build_conn()
|
|
|
|
|> assign(:user, nil)
|
|
|
|
|> assign(:token, good_token)
|
|
|
|
|> get(url)
|
|
|
|
|
|
|
|
assert json_response(conn, :forbidden)
|
|
|
|
end
|
|
|
|
|
2019-12-06 12:33:47 -05:00
|
|
|
for bad_token <- [bad_token1, bad_token2, bad_token3] do
|
|
|
|
conn =
|
|
|
|
build_conn()
|
|
|
|
|> assign(:user, admin)
|
|
|
|
|> assign(:token, bad_token)
|
2019-12-07 09:49:53 -05:00
|
|
|
|> get(url)
|
2019-12-06 12:33:47 -05:00
|
|
|
|
|
|
|
assert json_response(conn, :forbidden)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-15 14:32:42 -05:00
|
|
|
describe "unless [:auth, :enforce_oauth_admin_scope_usage]," do
|
2020-03-20 11:33:00 -04:00
|
|
|
setup do: clear_config([:auth, :enforce_oauth_admin_scope_usage], false)
|
2019-12-15 14:32:42 -05:00
|
|
|
|
|
|
|
test "GET /api/pleroma/admin/users/:nickname requires " <>
|
|
|
|
"read:accounts or admin:read:accounts or broader scope",
|
|
|
|
%{admin: admin} do
|
|
|
|
user = insert(:user)
|
|
|
|
url = "/api/pleroma/admin/users/#{user.nickname}"
|
|
|
|
|
|
|
|
good_token1 = insert(:oauth_token, user: admin, scopes: ["admin"])
|
|
|
|
good_token2 = insert(:oauth_token, user: admin, scopes: ["admin:read"])
|
|
|
|
good_token3 = insert(:oauth_token, user: admin, scopes: ["admin:read:accounts"])
|
|
|
|
good_token4 = insert(:oauth_token, user: admin, scopes: ["read:accounts"])
|
|
|
|
good_token5 = insert(:oauth_token, user: admin, scopes: ["read"])
|
|
|
|
|
|
|
|
good_tokens = [good_token1, good_token2, good_token3, good_token4, good_token5]
|
|
|
|
|
|
|
|
bad_token1 = insert(:oauth_token, user: admin, scopes: ["read:accounts:partial"])
|
|
|
|
bad_token2 = insert(:oauth_token, user: admin, scopes: ["admin:read:accounts:partial"])
|
|
|
|
bad_token3 = nil
|
|
|
|
|
|
|
|
for good_token <- good_tokens do
|
|
|
|
conn =
|
|
|
|
build_conn()
|
|
|
|
|> assign(:user, admin)
|
|
|
|
|> assign(:token, good_token)
|
|
|
|
|> get(url)
|
|
|
|
|
|
|
|
assert json_response(conn, 200)
|
|
|
|
end
|
|
|
|
|
|
|
|
for good_token <- good_tokens do
|
|
|
|
conn =
|
|
|
|
build_conn()
|
|
|
|
|> assign(:user, nil)
|
|
|
|
|> assign(:token, good_token)
|
|
|
|
|> get(url)
|
|
|
|
|
|
|
|
assert json_response(conn, :forbidden)
|
|
|
|
end
|
|
|
|
|
|
|
|
for bad_token <- [bad_token1, bad_token2, bad_token3] do
|
|
|
|
conn =
|
|
|
|
build_conn()
|
|
|
|
|> assign(:user, admin)
|
|
|
|
|> assign(:token, bad_token)
|
|
|
|
|> get(url)
|
|
|
|
|
|
|
|
assert json_response(conn, :forbidden)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-10-15 11:33:29 -04:00
|
|
|
describe "DELETE /api/pleroma/admin/users" do
|
2019-12-15 14:32:42 -05:00
|
|
|
test "single user", %{admin: admin, conn: conn} do
|
2018-11-17 16:11:18 -05:00
|
|
|
user = insert(:user)
|
2020-05-21 07:16:21 -04:00
|
|
|
clear_config([:instance, :federating], true)
|
2018-11-17 16:11:18 -05:00
|
|
|
|
2020-05-01 08:30:39 -04:00
|
|
|
with_mock Pleroma.Web.Federator,
|
|
|
|
publish: fn _ -> nil end do
|
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> put_req_header("accept", "application/json")
|
|
|
|
|> delete("/api/pleroma/admin/users?nickname=#{user.nickname}")
|
2018-11-17 16:11:18 -05:00
|
|
|
|
2020-05-01 08:30:39 -04:00
|
|
|
ObanHelpers.perform_all()
|
2019-08-25 15:39:37 -04:00
|
|
|
|
2020-05-03 07:01:19 -04:00
|
|
|
assert User.get_by_nickname(user.nickname).deactivated
|
2020-05-01 08:30:39 -04:00
|
|
|
|
|
|
|
log_entry = Repo.one(ModerationLog)
|
2019-08-25 15:39:37 -04:00
|
|
|
|
2020-05-01 08:30:39 -04:00
|
|
|
assert ModerationLog.get_log_entry_message(log_entry) ==
|
|
|
|
"@#{admin.nickname} deleted users: @#{user.nickname}"
|
2019-08-25 15:39:37 -04:00
|
|
|
|
2020-05-01 08:30:39 -04:00
|
|
|
assert json_response(conn, 200) == [user.nickname]
|
|
|
|
|
|
|
|
assert called(Pleroma.Web.Federator.publish(:_))
|
|
|
|
end
|
2018-11-17 16:11:18 -05:00
|
|
|
end
|
|
|
|
|
2019-12-15 14:32:42 -05:00
|
|
|
test "multiple users", %{admin: admin, conn: conn} do
|
2019-10-15 11:33:29 -04:00
|
|
|
user_one = insert(:user)
|
|
|
|
user_two = insert(:user)
|
|
|
|
|
|
|
|
conn =
|
2019-12-15 14:32:42 -05:00
|
|
|
conn
|
2019-10-15 11:33:29 -04:00
|
|
|
|> put_req_header("accept", "application/json")
|
|
|
|
|> delete("/api/pleroma/admin/users", %{
|
|
|
|
nicknames: [user_one.nickname, user_two.nickname]
|
|
|
|
})
|
|
|
|
|
|
|
|
log_entry = Repo.one(ModerationLog)
|
|
|
|
|
|
|
|
assert ModerationLog.get_log_entry_message(log_entry) ==
|
|
|
|
"@#{admin.nickname} deleted users: @#{user_one.nickname}, @#{user_two.nickname}"
|
|
|
|
|
|
|
|
response = json_response(conn, 200)
|
|
|
|
assert response -- [user_one.nickname, user_two.nickname] == []
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "/api/pleroma/admin/users" do
|
2019-12-15 14:32:42 -05:00
|
|
|
test "Create", %{conn: conn} do
|
2018-11-17 16:11:18 -05:00
|
|
|
conn =
|
2019-12-15 14:32:42 -05:00
|
|
|
conn
|
2018-11-17 16:11:18 -05:00
|
|
|
|> put_req_header("accept", "application/json")
|
2019-05-11 04:32:04 -04:00
|
|
|
|> post("/api/pleroma/admin/users", %{
|
2019-05-17 02:35:31 -04:00
|
|
|
"users" => [
|
|
|
|
%{
|
|
|
|
"nickname" => "lain",
|
|
|
|
"email" => "lain@example.org",
|
|
|
|
"password" => "test"
|
2019-06-01 01:32:53 -04:00
|
|
|
},
|
|
|
|
%{
|
|
|
|
"nickname" => "lain2",
|
|
|
|
"email" => "lain2@example.org",
|
|
|
|
"password" => "test"
|
2019-05-17 02:35:31 -04:00
|
|
|
}
|
|
|
|
]
|
2018-11-17 16:11:18 -05:00
|
|
|
})
|
|
|
|
|
2019-06-02 00:03:45 -04:00
|
|
|
response = json_response(conn, 200) |> Enum.map(&Map.get(&1, "type"))
|
|
|
|
assert response == ["success", "success"]
|
2019-08-25 15:39:37 -04:00
|
|
|
|
|
|
|
log_entry = Repo.one(ModerationLog)
|
|
|
|
|
2019-08-26 10:24:22 -04:00
|
|
|
assert ["lain", "lain2"] -- Enum.map(log_entry.data["subjects"], & &1["nickname"]) == []
|
2019-05-17 02:35:31 -04:00
|
|
|
end
|
|
|
|
|
2019-12-15 14:32:42 -05:00
|
|
|
test "Cannot create user with existing email", %{conn: conn} do
|
2019-05-17 02:35:31 -04:00
|
|
|
user = insert(:user)
|
|
|
|
|
|
|
|
conn =
|
2019-12-15 14:32:42 -05:00
|
|
|
conn
|
2019-05-17 02:35:31 -04:00
|
|
|
|> put_req_header("accept", "application/json")
|
|
|
|
|> post("/api/pleroma/admin/users", %{
|
|
|
|
"users" => [
|
|
|
|
%{
|
|
|
|
"nickname" => "lain",
|
|
|
|
"email" => user.email,
|
|
|
|
"password" => "test"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
|
|
|
|
2019-06-01 01:32:53 -04:00
|
|
|
assert json_response(conn, 409) == [
|
2019-05-17 02:35:31 -04:00
|
|
|
%{
|
|
|
|
"code" => 409,
|
|
|
|
"data" => %{
|
|
|
|
"email" => user.email,
|
|
|
|
"nickname" => "lain"
|
|
|
|
},
|
|
|
|
"error" => "email has already been taken",
|
|
|
|
"type" => "error"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
2019-12-15 14:32:42 -05:00
|
|
|
test "Cannot create user with existing nickname", %{conn: conn} do
|
2019-05-17 02:35:31 -04:00
|
|
|
user = insert(:user)
|
|
|
|
|
|
|
|
conn =
|
2019-12-15 14:32:42 -05:00
|
|
|
conn
|
2019-05-17 02:35:31 -04:00
|
|
|
|> put_req_header("accept", "application/json")
|
|
|
|
|> post("/api/pleroma/admin/users", %{
|
|
|
|
"users" => [
|
|
|
|
%{
|
|
|
|
"nickname" => user.nickname,
|
|
|
|
"email" => "someuser@plerama.social",
|
|
|
|
"password" => "test"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
|
|
|
|
2019-06-01 01:32:53 -04:00
|
|
|
assert json_response(conn, 409) == [
|
2019-05-17 02:35:31 -04:00
|
|
|
%{
|
|
|
|
"code" => 409,
|
|
|
|
"data" => %{
|
|
|
|
"email" => "someuser@plerama.social",
|
|
|
|
"nickname" => user.nickname
|
|
|
|
},
|
|
|
|
"error" => "nickname has already been taken",
|
|
|
|
"type" => "error"
|
|
|
|
}
|
|
|
|
]
|
2018-11-17 16:11:18 -05:00
|
|
|
end
|
2019-06-01 01:32:53 -04:00
|
|
|
|
2019-12-15 14:32:42 -05:00
|
|
|
test "Multiple user creation works in transaction", %{conn: conn} do
|
2019-06-01 01:32:53 -04:00
|
|
|
user = insert(:user)
|
|
|
|
|
|
|
|
conn =
|
2019-12-15 14:32:42 -05:00
|
|
|
conn
|
2019-06-01 01:32:53 -04:00
|
|
|
|> put_req_header("accept", "application/json")
|
|
|
|
|> post("/api/pleroma/admin/users", %{
|
|
|
|
"users" => [
|
|
|
|
%{
|
|
|
|
"nickname" => "newuser",
|
|
|
|
"email" => "newuser@pleroma.social",
|
|
|
|
"password" => "test"
|
|
|
|
},
|
|
|
|
%{
|
|
|
|
"nickname" => "lain",
|
|
|
|
"email" => user.email,
|
|
|
|
"password" => "test"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
|
|
|
|
|
|
|
assert json_response(conn, 409) == [
|
|
|
|
%{
|
|
|
|
"code" => 409,
|
|
|
|
"data" => %{
|
|
|
|
"email" => user.email,
|
|
|
|
"nickname" => "lain"
|
|
|
|
},
|
|
|
|
"error" => "email has already been taken",
|
|
|
|
"type" => "error"
|
|
|
|
},
|
|
|
|
%{
|
|
|
|
"code" => 409,
|
|
|
|
"data" => %{
|
|
|
|
"email" => "newuser@pleroma.social",
|
|
|
|
"nickname" => "newuser"
|
|
|
|
},
|
|
|
|
"error" => "",
|
|
|
|
"type" => "error"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
assert User.get_by_nickname("newuser") === nil
|
2018-11-17 16:11:18 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-03-27 14:19:00 -04:00
|
|
|
describe "/api/pleroma/admin/users/:nickname" do
|
|
|
|
test "Show", %{conn: conn} do
|
|
|
|
user = insert(:user)
|
|
|
|
|
2019-12-15 14:32:42 -05:00
|
|
|
conn = get(conn, "/api/pleroma/admin/users/#{user.nickname}")
|
2019-03-27 14:19:00 -04:00
|
|
|
|
|
|
|
expected = %{
|
|
|
|
"deactivated" => false,
|
|
|
|
"id" => to_string(user.id),
|
|
|
|
"local" => true,
|
|
|
|
"nickname" => user.nickname,
|
|
|
|
"roles" => %{"admin" => false, "moderator" => false},
|
2019-06-28 08:15:32 -04:00
|
|
|
"tags" => [],
|
|
|
|
"avatar" => User.avatar_url(user) |> MediaProxy.url(),
|
2019-11-19 08:50:24 -05:00
|
|
|
"display_name" => HTML.strip_tags(user.name || user.nickname),
|
2020-06-08 14:08:57 -04:00
|
|
|
"confirmation_pending" => false,
|
2020-07-14 14:47:05 -04:00
|
|
|
"approval_pending" => false,
|
2020-07-14 14:04:57 -04:00
|
|
|
"url" => user.ap_id,
|
|
|
|
"registration_reason" => nil
|
2019-03-27 14:19:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
assert expected == json_response(conn, 200)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "when the user doesn't exist", %{conn: conn} do
|
|
|
|
user = build(:user)
|
|
|
|
|
2019-12-15 14:32:42 -05:00
|
|
|
conn = get(conn, "/api/pleroma/admin/users/#{user.nickname}")
|
2019-03-27 14:19:00 -04:00
|
|
|
|
2020-05-21 06:03:38 -04:00
|
|
|
assert %{"error" => "Not found"} == json_response(conn, 404)
|
2019-03-27 14:19:00 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-05-11 04:32:04 -04:00
|
|
|
describe "/api/pleroma/admin/users/follow" do
|
2019-12-15 14:32:42 -05:00
|
|
|
test "allows to force-follow another user", %{admin: admin, conn: conn} do
|
2018-12-16 10:41:56 -05:00
|
|
|
user = insert(:user)
|
|
|
|
follower = insert(:user)
|
|
|
|
|
2019-12-15 14:32:42 -05:00
|
|
|
conn
|
2019-04-08 05:32:55 -04:00
|
|
|
|> put_req_header("accept", "application/json")
|
2019-05-11 04:32:04 -04:00
|
|
|
|> post("/api/pleroma/admin/users/follow", %{
|
2019-04-08 05:32:55 -04:00
|
|
|
"follower" => follower.nickname,
|
|
|
|
"followed" => user.nickname
|
|
|
|
})
|
2018-12-16 10:41:56 -05:00
|
|
|
|
2019-04-22 03:20:43 -04:00
|
|
|
user = User.get_cached_by_id(user.id)
|
|
|
|
follower = User.get_cached_by_id(follower.id)
|
2018-12-16 10:41:56 -05:00
|
|
|
|
|
|
|
assert User.following?(follower, user)
|
2019-08-25 15:39:37 -04:00
|
|
|
|
|
|
|
log_entry = Repo.one(ModerationLog)
|
|
|
|
|
|
|
|
assert ModerationLog.get_log_entry_message(log_entry) ==
|
|
|
|
"@#{admin.nickname} made @#{follower.nickname} follow @#{user.nickname}"
|
2018-12-16 10:41:56 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-05-11 04:32:04 -04:00
|
|
|
describe "/api/pleroma/admin/users/unfollow" do
|
2019-12-15 14:32:42 -05:00
|
|
|
test "allows to force-unfollow another user", %{admin: admin, conn: conn} do
|
2018-12-16 10:41:56 -05:00
|
|
|
user = insert(:user)
|
|
|
|
follower = insert(:user)
|
|
|
|
|
|
|
|
User.follow(follower, user)
|
|
|
|
|
2019-12-15 14:32:42 -05:00
|
|
|
conn
|
2019-04-08 05:32:55 -04:00
|
|
|
|> put_req_header("accept", "application/json")
|
2019-05-11 04:32:04 -04:00
|
|
|
|> post("/api/pleroma/admin/users/unfollow", %{
|
2019-04-08 05:32:55 -04:00
|
|
|
"follower" => follower.nickname,
|
|
|
|
"followed" => user.nickname
|
|
|
|
})
|
2018-12-16 10:41:56 -05:00
|
|
|
|
2019-04-22 03:20:43 -04:00
|
|
|
user = User.get_cached_by_id(user.id)
|
|
|
|
follower = User.get_cached_by_id(follower.id)
|
2018-12-16 10:41:56 -05:00
|
|
|
|
|
|
|
refute User.following?(follower, user)
|
2019-08-25 15:39:37 -04:00
|
|
|
|
|
|
|
log_entry = Repo.one(ModerationLog)
|
|
|
|
|
|
|
|
assert ModerationLog.get_log_entry_message(log_entry) ==
|
|
|
|
"@#{admin.nickname} made @#{follower.nickname} unfollow @#{user.nickname}"
|
2018-12-16 10:41:56 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-12-07 03:04:39 -05:00
|
|
|
describe "PUT /api/pleroma/admin/users/tag" do
|
2019-12-15 14:32:42 -05:00
|
|
|
setup %{conn: conn} do
|
2018-12-06 12:06:50 -05:00
|
|
|
user1 = insert(:user, %{tags: ["x"]})
|
|
|
|
user2 = insert(:user, %{tags: ["y"]})
|
|
|
|
user3 = insert(:user, %{tags: ["unchanged"]})
|
|
|
|
|
|
|
|
conn =
|
2019-12-15 14:32:42 -05:00
|
|
|
conn
|
2018-12-06 12:06:50 -05:00
|
|
|
|> put_req_header("accept", "application/json")
|
2018-12-06 12:13:07 -05:00
|
|
|
|> put(
|
2019-12-15 14:32:42 -05:00
|
|
|
"/api/pleroma/admin/users/tag?nicknames[]=#{user1.nickname}&nicknames[]=" <>
|
|
|
|
"#{user2.nickname}&tags[]=foo&tags[]=bar"
|
2018-12-06 12:13:07 -05:00
|
|
|
)
|
2018-12-06 12:06:50 -05:00
|
|
|
|
2019-12-15 14:32:42 -05:00
|
|
|
%{conn: conn, user1: user1, user2: user2, user3: user3}
|
2018-12-06 12:06:50 -05:00
|
|
|
end
|
|
|
|
|
2018-12-06 12:13:07 -05:00
|
|
|
test "it appends specified tags to users with specified nicknames", %{
|
|
|
|
conn: conn,
|
2019-08-25 15:39:37 -04:00
|
|
|
admin: admin,
|
2018-12-06 12:13:07 -05:00
|
|
|
user1: user1,
|
|
|
|
user2: user2
|
|
|
|
} do
|
2018-12-06 12:06:50 -05:00
|
|
|
assert json_response(conn, :no_content)
|
2019-04-22 03:20:43 -04:00
|
|
|
assert User.get_cached_by_id(user1.id).tags == ["x", "foo", "bar"]
|
|
|
|
assert User.get_cached_by_id(user2.id).tags == ["y", "foo", "bar"]
|
2019-08-25 15:39:37 -04:00
|
|
|
|
|
|
|
log_entry = Repo.one(ModerationLog)
|
|
|
|
|
|
|
|
users =
|
|
|
|
[user1.nickname, user2.nickname]
|
|
|
|
|> Enum.map(&"@#{&1}")
|
|
|
|
|> Enum.join(", ")
|
|
|
|
|
|
|
|
tags = ["foo", "bar"] |> Enum.join(", ")
|
|
|
|
|
|
|
|
assert ModerationLog.get_log_entry_message(log_entry) ==
|
|
|
|
"@#{admin.nickname} added tags: #{tags} to users: #{users}"
|
2018-12-06 12:06:50 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
test "it does not modify tags of not specified users", %{conn: conn, user3: user3} do
|
|
|
|
assert json_response(conn, :no_content)
|
2019-04-22 03:20:43 -04:00
|
|
|
assert User.get_cached_by_id(user3.id).tags == ["unchanged"]
|
2018-12-06 12:06:50 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-12-07 03:04:39 -05:00
|
|
|
describe "DELETE /api/pleroma/admin/users/tag" do
|
2019-12-15 14:32:42 -05:00
|
|
|
setup %{conn: conn} do
|
2018-12-06 12:06:50 -05:00
|
|
|
user1 = insert(:user, %{tags: ["x"]})
|
|
|
|
user2 = insert(:user, %{tags: ["y", "z"]})
|
|
|
|
user3 = insert(:user, %{tags: ["unchanged"]})
|
|
|
|
|
|
|
|
conn =
|
2019-12-15 14:32:42 -05:00
|
|
|
conn
|
2018-12-06 12:06:50 -05:00
|
|
|
|> put_req_header("accept", "application/json")
|
2018-12-07 03:04:39 -05:00
|
|
|
|> delete(
|
2019-12-15 14:32:42 -05:00
|
|
|
"/api/pleroma/admin/users/tag?nicknames[]=#{user1.nickname}&nicknames[]=" <>
|
|
|
|
"#{user2.nickname}&tags[]=x&tags[]=z"
|
2018-12-06 12:13:07 -05:00
|
|
|
)
|
2018-12-06 12:06:50 -05:00
|
|
|
|
2019-12-15 14:32:42 -05:00
|
|
|
%{conn: conn, user1: user1, user2: user2, user3: user3}
|
2018-12-06 12:06:50 -05:00
|
|
|
end
|
|
|
|
|
2018-12-06 12:13:07 -05:00
|
|
|
test "it removes specified tags from users with specified nicknames", %{
|
|
|
|
conn: conn,
|
2019-08-25 15:39:37 -04:00
|
|
|
admin: admin,
|
2018-12-06 12:13:07 -05:00
|
|
|
user1: user1,
|
|
|
|
user2: user2
|
|
|
|
} do
|
2018-12-06 12:06:50 -05:00
|
|
|
assert json_response(conn, :no_content)
|
2019-04-22 03:20:43 -04:00
|
|
|
assert User.get_cached_by_id(user1.id).tags == []
|
|
|
|
assert User.get_cached_by_id(user2.id).tags == ["y"]
|
2019-08-25 15:39:37 -04:00
|
|
|
|
|
|
|
log_entry = Repo.one(ModerationLog)
|
|
|
|
|
|
|
|
users =
|
|
|
|
[user1.nickname, user2.nickname]
|
|
|
|
|> Enum.map(&"@#{&1}")
|
|
|
|
|> Enum.join(", ")
|
|
|
|
|
|
|
|
tags = ["x", "z"] |> Enum.join(", ")
|
|
|
|
|
|
|
|
assert ModerationLog.get_log_entry_message(log_entry) ==
|
|
|
|
"@#{admin.nickname} removed tags: #{tags} from users: #{users}"
|
2018-12-06 12:06:50 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
test "it does not modify tags of not specified users", %{conn: conn, user3: user3} do
|
|
|
|
assert json_response(conn, :no_content)
|
2019-04-22 03:20:43 -04:00
|
|
|
assert User.get_cached_by_id(user3.id).tags == ["unchanged"]
|
2018-12-06 12:06:50 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-05-11 04:32:04 -04:00
|
|
|
describe "/api/pleroma/admin/users/:nickname/permission_group" do
|
2019-12-15 14:32:42 -05:00
|
|
|
test "GET is giving user_info", %{admin: admin, conn: conn} do
|
2018-11-17 16:11:18 -05:00
|
|
|
conn =
|
2019-12-15 14:32:42 -05:00
|
|
|
conn
|
2018-11-17 16:11:18 -05:00
|
|
|
|> put_req_header("accept", "application/json")
|
2019-05-11 04:32:04 -04:00
|
|
|
|> get("/api/pleroma/admin/users/#{admin.nickname}/permission_group/")
|
2018-11-17 16:11:18 -05:00
|
|
|
|
2018-12-01 03:03:16 -05:00
|
|
|
assert json_response(conn, 200) == %{
|
|
|
|
"is_admin" => true,
|
|
|
|
"is_moderator" => false
|
|
|
|
}
|
2018-11-17 16:11:18 -05:00
|
|
|
end
|
|
|
|
|
2019-12-15 14:32:42 -05:00
|
|
|
test "/:right POST, can add to a permission group", %{admin: admin, conn: conn} do
|
2018-11-17 16:11:18 -05:00
|
|
|
user = insert(:user)
|
|
|
|
|
|
|
|
conn =
|
2019-12-15 14:32:42 -05:00
|
|
|
conn
|
2018-11-17 16:11:18 -05:00
|
|
|
|> put_req_header("accept", "application/json")
|
2019-05-11 04:32:04 -04:00
|
|
|
|> post("/api/pleroma/admin/users/#{user.nickname}/permission_group/admin")
|
2018-11-17 16:11:18 -05:00
|
|
|
|
2018-12-01 03:03:16 -05:00
|
|
|
assert json_response(conn, 200) == %{
|
|
|
|
"is_admin" => true
|
|
|
|
}
|
2019-08-25 15:39:37 -04:00
|
|
|
|
|
|
|
log_entry = Repo.one(ModerationLog)
|
|
|
|
|
|
|
|
assert ModerationLog.get_log_entry_message(log_entry) ==
|
|
|
|
"@#{admin.nickname} made @#{user.nickname} admin"
|
2018-11-17 16:11:18 -05:00
|
|
|
end
|
|
|
|
|
2019-12-15 14:32:42 -05:00
|
|
|
test "/:right POST, can add to a permission group (multiple)", %{admin: admin, conn: conn} do
|
2019-10-09 10:03:54 -04:00
|
|
|
user_one = insert(:user)
|
|
|
|
user_two = insert(:user)
|
2018-11-17 16:11:18 -05:00
|
|
|
|
|
|
|
conn =
|
2019-12-15 14:32:42 -05:00
|
|
|
conn
|
2018-11-17 16:11:18 -05:00
|
|
|
|> put_req_header("accept", "application/json")
|
2019-10-09 10:03:54 -04:00
|
|
|
|> post("/api/pleroma/admin/users/permission_group/admin", %{
|
|
|
|
nicknames: [user_one.nickname, user_two.nickname]
|
|
|
|
})
|
2018-11-17 16:11:18 -05:00
|
|
|
|
2019-12-15 14:32:42 -05:00
|
|
|
assert json_response(conn, 200) == %{"is_admin" => true}
|
2019-08-25 15:39:37 -04:00
|
|
|
|
|
|
|
log_entry = Repo.one(ModerationLog)
|
|
|
|
|
|
|
|
assert ModerationLog.get_log_entry_message(log_entry) ==
|
2019-10-09 10:03:54 -04:00
|
|
|
"@#{admin.nickname} made @#{user_one.nickname}, @#{user_two.nickname} admin"
|
2018-11-17 16:11:18 -05:00
|
|
|
end
|
|
|
|
|
2019-12-15 14:32:42 -05:00
|
|
|
test "/:right DELETE, can remove from a permission group", %{admin: admin, conn: conn} do
|
2019-10-20 13:43:18 -04:00
|
|
|
user = insert(:user, is_admin: true)
|
2019-02-19 10:40:57 -05:00
|
|
|
|
|
|
|
conn =
|
2019-12-15 14:32:42 -05:00
|
|
|
conn
|
2019-02-19 10:40:57 -05:00
|
|
|
|> put_req_header("accept", "application/json")
|
2019-10-11 08:58:45 -04:00
|
|
|
|> delete("/api/pleroma/admin/users/#{user.nickname}/permission_group/admin")
|
2019-02-19 10:40:57 -05:00
|
|
|
|
2019-12-15 14:32:42 -05:00
|
|
|
assert json_response(conn, 200) == %{"is_admin" => false}
|
2019-08-25 15:39:37 -04:00
|
|
|
|
|
|
|
log_entry = Repo.one(ModerationLog)
|
|
|
|
|
|
|
|
assert ModerationLog.get_log_entry_message(log_entry) ==
|
2019-10-11 08:58:45 -04:00
|
|
|
"@#{admin.nickname} revoked admin role from @#{user.nickname}"
|
2019-02-19 10:40:57 -05:00
|
|
|
end
|
|
|
|
|
2019-12-15 14:32:42 -05:00
|
|
|
test "/:right DELETE, can remove from a permission group (multiple)", %{
|
|
|
|
admin: admin,
|
|
|
|
conn: conn
|
|
|
|
} do
|
2019-10-20 13:43:18 -04:00
|
|
|
user_one = insert(:user, is_admin: true)
|
|
|
|
user_two = insert(:user, is_admin: true)
|
2019-02-19 10:40:57 -05:00
|
|
|
|
|
|
|
conn =
|
2019-12-15 14:32:42 -05:00
|
|
|
conn
|
2018-11-17 16:11:18 -05:00
|
|
|
|> put_req_header("accept", "application/json")
|
2019-10-09 10:03:54 -04:00
|
|
|
|> delete("/api/pleroma/admin/users/permission_group/admin", %{
|
|
|
|
nicknames: [user_one.nickname, user_two.nickname]
|
|
|
|
})
|
2019-02-19 10:40:57 -05:00
|
|
|
|
2019-12-15 14:32:42 -05:00
|
|
|
assert json_response(conn, 200) == %{"is_admin" => false}
|
2019-08-25 15:39:37 -04:00
|
|
|
|
|
|
|
log_entry = Repo.one(ModerationLog)
|
|
|
|
|
|
|
|
assert ModerationLog.get_log_entry_message(log_entry) ==
|
2019-10-09 10:03:54 -04:00
|
|
|
"@#{admin.nickname} revoked admin role from @#{user_one.nickname}, @#{
|
|
|
|
user_two.nickname
|
|
|
|
}"
|
2019-02-19 10:40:57 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-15 14:32:42 -05:00
|
|
|
test "/api/pleroma/admin/users/:nickname/password_reset", %{conn: conn} do
|
2018-12-01 03:03:16 -05:00
|
|
|
user = insert(:user)
|
2018-11-17 16:11:18 -05:00
|
|
|
|
|
|
|
conn =
|
2019-12-15 14:32:42 -05:00
|
|
|
conn
|
2018-11-17 16:11:18 -05:00
|
|
|
|> put_req_header("accept", "application/json")
|
2019-05-11 04:32:04 -04:00
|
|
|
|> get("/api/pleroma/admin/users/#{user.nickname}/password_reset")
|
2018-11-17 16:11:18 -05:00
|
|
|
|
2019-09-22 09:36:59 -04:00
|
|
|
resp = json_response(conn, 200)
|
|
|
|
|
|
|
|
assert Regex.match?(~r/(http:\/\/|https:\/\/)/, resp["link"])
|
2018-11-17 16:11:18 -05:00
|
|
|
end
|
2019-02-26 19:08:03 -05:00
|
|
|
|
2019-02-28 09:54:02 -05:00
|
|
|
describe "GET /api/pleroma/admin/users" do
|
2019-05-08 10:34:36 -04:00
|
|
|
test "renders users array for the first page", %{conn: conn, admin: admin} do
|
2020-07-14 14:47:05 -04:00
|
|
|
user = insert(:user, local: false, tags: ["foo", "bar"])
|
|
|
|
user2 = insert(:user, approval_pending: true, registration_reason: "I'm a chill dude")
|
2020-07-14 14:04:57 -04:00
|
|
|
|
2019-05-08 10:34:36 -04:00
|
|
|
conn = get(conn, "/api/pleroma/admin/users?page=1")
|
2019-02-28 09:54:02 -05:00
|
|
|
|
2019-05-29 10:04:58 -04:00
|
|
|
users =
|
|
|
|
[
|
|
|
|
%{
|
2019-10-16 14:59:21 -04:00
|
|
|
"deactivated" => admin.deactivated,
|
2019-05-29 10:04:58 -04:00
|
|
|
"id" => admin.id,
|
|
|
|
"nickname" => admin.nickname,
|
|
|
|
"roles" => %{"admin" => true, "moderator" => false},
|
|
|
|
"local" => true,
|
2019-06-28 08:15:32 -04:00
|
|
|
"tags" => [],
|
|
|
|
"avatar" => User.avatar_url(admin) |> MediaProxy.url(),
|
2019-11-19 08:50:24 -05:00
|
|
|
"display_name" => HTML.strip_tags(admin.name || admin.nickname),
|
2020-06-08 14:08:57 -04:00
|
|
|
"confirmation_pending" => false,
|
2020-07-14 14:47:05 -04:00
|
|
|
"approval_pending" => false,
|
2020-07-14 14:04:57 -04:00
|
|
|
"url" => admin.ap_id,
|
|
|
|
"registration_reason" => nil
|
2019-05-29 10:04:58 -04:00
|
|
|
},
|
|
|
|
%{
|
2019-10-16 14:59:21 -04:00
|
|
|
"deactivated" => user.deactivated,
|
2019-05-29 10:04:58 -04:00
|
|
|
"id" => user.id,
|
|
|
|
"nickname" => user.nickname,
|
|
|
|
"roles" => %{"admin" => false, "moderator" => false},
|
|
|
|
"local" => false,
|
2019-06-28 08:15:32 -04:00
|
|
|
"tags" => ["foo", "bar"],
|
|
|
|
"avatar" => User.avatar_url(user) |> MediaProxy.url(),
|
2019-11-19 08:50:24 -05:00
|
|
|
"display_name" => HTML.strip_tags(user.name || user.nickname),
|
2020-06-08 14:08:57 -04:00
|
|
|
"confirmation_pending" => false,
|
2020-07-14 14:47:05 -04:00
|
|
|
"approval_pending" => false,
|
2020-07-14 14:04:57 -04:00
|
|
|
"url" => user.ap_id,
|
2020-07-14 14:47:05 -04:00
|
|
|
"registration_reason" => nil
|
|
|
|
},
|
|
|
|
%{
|
|
|
|
"deactivated" => user2.deactivated,
|
|
|
|
"id" => user2.id,
|
|
|
|
"nickname" => user2.nickname,
|
|
|
|
"roles" => %{"admin" => false, "moderator" => false},
|
|
|
|
"local" => true,
|
|
|
|
"tags" => [],
|
|
|
|
"avatar" => User.avatar_url(user2) |> MediaProxy.url(),
|
|
|
|
"display_name" => HTML.strip_tags(user2.name || user2.nickname),
|
|
|
|
"confirmation_pending" => false,
|
|
|
|
"approval_pending" => true,
|
|
|
|
"url" => user2.ap_id,
|
2020-07-14 14:04:57 -04:00
|
|
|
"registration_reason" => "I'm a chill dude"
|
2019-05-29 10:04:58 -04:00
|
|
|
}
|
|
|
|
]
|
|
|
|
|> Enum.sort_by(& &1["nickname"])
|
|
|
|
|
2019-02-28 09:54:02 -05:00
|
|
|
assert json_response(conn, 200) == %{
|
2020-07-14 14:47:05 -04:00
|
|
|
"count" => 3,
|
2019-02-28 09:54:02 -05:00
|
|
|
"page_size" => 50,
|
2019-05-29 10:04:58 -04:00
|
|
|
"users" => users
|
2019-02-28 09:54:02 -05:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2020-05-01 07:31:24 -04:00
|
|
|
test "pagination works correctly with service users", %{conn: conn} do
|
2020-06-01 15:18:20 -04:00
|
|
|
service1 = User.get_or_create_service_actor_by_ap_id(Web.base_url() <> "/meido", "meido")
|
|
|
|
|
2020-05-01 07:31:24 -04:00
|
|
|
insert_list(25, :user)
|
|
|
|
|
|
|
|
assert %{"count" => 26, "page_size" => 10, "users" => users1} =
|
|
|
|
conn
|
|
|
|
|> get("/api/pleroma/admin/users?page=1&filters=", %{page_size: "10"})
|
|
|
|
|> json_response(200)
|
|
|
|
|
|
|
|
assert Enum.count(users1) == 10
|
2020-06-01 15:18:20 -04:00
|
|
|
assert service1 not in users1
|
2020-05-01 07:31:24 -04:00
|
|
|
|
|
|
|
assert %{"count" => 26, "page_size" => 10, "users" => users2} =
|
|
|
|
conn
|
|
|
|
|> get("/api/pleroma/admin/users?page=2&filters=", %{page_size: "10"})
|
|
|
|
|> json_response(200)
|
|
|
|
|
|
|
|
assert Enum.count(users2) == 10
|
2020-06-01 15:18:20 -04:00
|
|
|
assert service1 not in users2
|
2020-05-01 07:31:24 -04:00
|
|
|
|
|
|
|
assert %{"count" => 26, "page_size" => 10, "users" => users3} =
|
|
|
|
conn
|
|
|
|
|> get("/api/pleroma/admin/users?page=3&filters=", %{page_size: "10"})
|
|
|
|
|> json_response(200)
|
|
|
|
|
|
|
|
assert Enum.count(users3) == 6
|
2020-06-01 15:18:20 -04:00
|
|
|
assert service1 not in users3
|
2020-05-01 07:31:24 -04:00
|
|
|
end
|
|
|
|
|
2019-05-08 10:34:36 -04:00
|
|
|
test "renders empty array for the second page", %{conn: conn} do
|
2019-02-28 11:04:47 -05:00
|
|
|
insert(:user)
|
2019-02-28 09:54:02 -05:00
|
|
|
|
2019-05-08 10:34:36 -04:00
|
|
|
conn = get(conn, "/api/pleroma/admin/users?page=2")
|
2019-02-28 09:54:02 -05:00
|
|
|
|
|
|
|
assert json_response(conn, 200) == %{
|
2019-03-02 09:21:18 -05:00
|
|
|
"count" => 2,
|
2019-02-28 09:54:02 -05:00
|
|
|
"page_size" => 50,
|
|
|
|
"users" => []
|
|
|
|
}
|
|
|
|
end
|
2019-02-26 19:08:03 -05:00
|
|
|
|
2019-05-08 10:34:36 -04:00
|
|
|
test "regular search", %{conn: conn} do
|
2019-03-01 12:13:02 -05:00
|
|
|
user = insert(:user, nickname: "bob")
|
2019-02-28 11:04:47 -05:00
|
|
|
|
2019-05-08 10:34:36 -04:00
|
|
|
conn = get(conn, "/api/pleroma/admin/users?query=bo")
|
2019-03-01 12:13:02 -05:00
|
|
|
|
|
|
|
assert json_response(conn, 200) == %{
|
2019-03-01 12:23:03 -05:00
|
|
|
"count" => 1,
|
|
|
|
"page_size" => 50,
|
|
|
|
"users" => [
|
|
|
|
%{
|
2019-10-16 14:59:21 -04:00
|
|
|
"deactivated" => user.deactivated,
|
2019-03-01 12:23:03 -05:00
|
|
|
"id" => user.id,
|
2019-03-12 15:15:28 -04:00
|
|
|
"nickname" => user.nickname,
|
2019-03-13 09:04:44 -04:00
|
|
|
"roles" => %{"admin" => false, "moderator" => false},
|
2019-03-13 18:52:24 -04:00
|
|
|
"local" => true,
|
2019-06-28 08:15:32 -04:00
|
|
|
"tags" => [],
|
|
|
|
"avatar" => User.avatar_url(user) |> MediaProxy.url(),
|
2019-11-19 08:50:24 -05:00
|
|
|
"display_name" => HTML.strip_tags(user.name || user.nickname),
|
2020-06-08 14:08:57 -04:00
|
|
|
"confirmation_pending" => false,
|
2020-07-14 14:47:05 -04:00
|
|
|
"approval_pending" => false,
|
2020-07-14 14:04:57 -04:00
|
|
|
"url" => user.ap_id,
|
|
|
|
"registration_reason" => nil
|
2019-03-01 12:23:03 -05:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2019-03-01 12:13:02 -05:00
|
|
|
end
|
|
|
|
|
2019-05-08 10:34:36 -04:00
|
|
|
test "search by domain", %{conn: conn} do
|
|
|
|
user = insert(:user, nickname: "nickname@domain.com")
|
|
|
|
insert(:user)
|
|
|
|
|
|
|
|
conn = get(conn, "/api/pleroma/admin/users?query=domain.com")
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == %{
|
|
|
|
"count" => 1,
|
|
|
|
"page_size" => 50,
|
|
|
|
"users" => [
|
|
|
|
%{
|
2019-10-16 14:59:21 -04:00
|
|
|
"deactivated" => user.deactivated,
|
2019-05-08 10:34:36 -04:00
|
|
|
"id" => user.id,
|
|
|
|
"nickname" => user.nickname,
|
|
|
|
"roles" => %{"admin" => false, "moderator" => false},
|
|
|
|
"local" => true,
|
2019-06-28 08:15:32 -04:00
|
|
|
"tags" => [],
|
|
|
|
"avatar" => User.avatar_url(user) |> MediaProxy.url(),
|
2019-11-19 08:50:24 -05:00
|
|
|
"display_name" => HTML.strip_tags(user.name || user.nickname),
|
2020-06-08 14:08:57 -04:00
|
|
|
"confirmation_pending" => false,
|
2020-07-14 14:47:05 -04:00
|
|
|
"approval_pending" => false,
|
2020-07-14 14:04:57 -04:00
|
|
|
"url" => user.ap_id,
|
|
|
|
"registration_reason" => nil
|
2019-05-08 10:34:36 -04:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "search by full nickname", %{conn: conn} do
|
|
|
|
user = insert(:user, nickname: "nickname@domain.com")
|
|
|
|
insert(:user)
|
|
|
|
|
|
|
|
conn = get(conn, "/api/pleroma/admin/users?query=nickname@domain.com")
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == %{
|
|
|
|
"count" => 1,
|
|
|
|
"page_size" => 50,
|
|
|
|
"users" => [
|
|
|
|
%{
|
2019-10-16 14:59:21 -04:00
|
|
|
"deactivated" => user.deactivated,
|
2019-05-08 10:34:36 -04:00
|
|
|
"id" => user.id,
|
|
|
|
"nickname" => user.nickname,
|
|
|
|
"roles" => %{"admin" => false, "moderator" => false},
|
|
|
|
"local" => true,
|
2019-06-28 08:15:32 -04:00
|
|
|
"tags" => [],
|
|
|
|
"avatar" => User.avatar_url(user) |> MediaProxy.url(),
|
2019-11-19 08:50:24 -05:00
|
|
|
"display_name" => HTML.strip_tags(user.name || user.nickname),
|
2020-06-08 14:08:57 -04:00
|
|
|
"confirmation_pending" => false,
|
2020-07-14 14:47:05 -04:00
|
|
|
"approval_pending" => false,
|
2020-07-14 14:04:57 -04:00
|
|
|
"url" => user.ap_id,
|
|
|
|
"registration_reason" => nil
|
2019-05-08 10:34:36 -04:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "search by display name", %{conn: conn} do
|
|
|
|
user = insert(:user, name: "Display name")
|
|
|
|
insert(:user)
|
|
|
|
|
|
|
|
conn = get(conn, "/api/pleroma/admin/users?name=display")
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == %{
|
|
|
|
"count" => 1,
|
|
|
|
"page_size" => 50,
|
|
|
|
"users" => [
|
|
|
|
%{
|
2019-10-16 14:59:21 -04:00
|
|
|
"deactivated" => user.deactivated,
|
2019-05-08 10:34:36 -04:00
|
|
|
"id" => user.id,
|
|
|
|
"nickname" => user.nickname,
|
|
|
|
"roles" => %{"admin" => false, "moderator" => false},
|
|
|
|
"local" => true,
|
2019-06-28 08:15:32 -04:00
|
|
|
"tags" => [],
|
|
|
|
"avatar" => User.avatar_url(user) |> MediaProxy.url(),
|
2019-11-19 08:50:24 -05:00
|
|
|
"display_name" => HTML.strip_tags(user.name || user.nickname),
|
2020-06-08 14:08:57 -04:00
|
|
|
"confirmation_pending" => false,
|
2020-07-14 14:47:05 -04:00
|
|
|
"approval_pending" => false,
|
2020-07-14 14:04:57 -04:00
|
|
|
"url" => user.ap_id,
|
|
|
|
"registration_reason" => nil
|
2019-05-08 10:34:36 -04:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "search by email", %{conn: conn} do
|
|
|
|
user = insert(:user, email: "email@example.com")
|
|
|
|
insert(:user)
|
|
|
|
|
|
|
|
conn = get(conn, "/api/pleroma/admin/users?email=email@example.com")
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == %{
|
|
|
|
"count" => 1,
|
|
|
|
"page_size" => 50,
|
|
|
|
"users" => [
|
|
|
|
%{
|
2019-10-16 14:59:21 -04:00
|
|
|
"deactivated" => user.deactivated,
|
2019-05-08 10:34:36 -04:00
|
|
|
"id" => user.id,
|
|
|
|
"nickname" => user.nickname,
|
|
|
|
"roles" => %{"admin" => false, "moderator" => false},
|
|
|
|
"local" => true,
|
2019-06-28 08:15:32 -04:00
|
|
|
"tags" => [],
|
|
|
|
"avatar" => User.avatar_url(user) |> MediaProxy.url(),
|
2019-11-19 08:50:24 -05:00
|
|
|
"display_name" => HTML.strip_tags(user.name || user.nickname),
|
2020-06-08 14:08:57 -04:00
|
|
|
"confirmation_pending" => false,
|
2020-07-14 14:47:05 -04:00
|
|
|
"approval_pending" => false,
|
2020-07-14 14:04:57 -04:00
|
|
|
"url" => user.ap_id,
|
|
|
|
"registration_reason" => nil
|
2019-05-08 10:34:36 -04:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "regular search with page size", %{conn: conn} do
|
2019-03-26 18:51:59 -04:00
|
|
|
user = insert(:user, nickname: "aalice")
|
|
|
|
user2 = insert(:user, nickname: "alice")
|
2019-03-02 09:21:18 -05:00
|
|
|
|
2019-05-08 10:34:36 -04:00
|
|
|
conn1 = get(conn, "/api/pleroma/admin/users?query=a&page_size=1&page=1")
|
2019-03-02 09:21:18 -05:00
|
|
|
|
2019-05-08 10:34:36 -04:00
|
|
|
assert json_response(conn1, 200) == %{
|
2019-03-02 09:21:18 -05:00
|
|
|
"count" => 2,
|
|
|
|
"page_size" => 1,
|
|
|
|
"users" => [
|
|
|
|
%{
|
2019-10-16 14:59:21 -04:00
|
|
|
"deactivated" => user.deactivated,
|
2019-03-02 09:21:18 -05:00
|
|
|
"id" => user.id,
|
2019-03-12 15:15:28 -04:00
|
|
|
"nickname" => user.nickname,
|
2019-03-13 09:04:44 -04:00
|
|
|
"roles" => %{"admin" => false, "moderator" => false},
|
2019-03-13 18:52:24 -04:00
|
|
|
"local" => true,
|
2019-06-28 08:15:32 -04:00
|
|
|
"tags" => [],
|
|
|
|
"avatar" => User.avatar_url(user) |> MediaProxy.url(),
|
2019-11-19 08:50:24 -05:00
|
|
|
"display_name" => HTML.strip_tags(user.name || user.nickname),
|
2020-06-08 14:08:57 -04:00
|
|
|
"confirmation_pending" => false,
|
2020-07-14 14:47:05 -04:00
|
|
|
"approval_pending" => false,
|
2020-07-14 14:04:57 -04:00
|
|
|
"url" => user.ap_id,
|
|
|
|
"registration_reason" => nil
|
2019-03-02 09:21:18 -05:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2019-05-08 10:34:36 -04:00
|
|
|
conn2 = get(conn, "/api/pleroma/admin/users?query=a&page_size=1&page=2")
|
2019-03-02 09:21:18 -05:00
|
|
|
|
2019-05-08 10:34:36 -04:00
|
|
|
assert json_response(conn2, 200) == %{
|
2019-03-02 09:21:18 -05:00
|
|
|
"count" => 2,
|
|
|
|
"page_size" => 1,
|
|
|
|
"users" => [
|
|
|
|
%{
|
2019-10-16 14:59:21 -04:00
|
|
|
"deactivated" => user2.deactivated,
|
2019-03-02 09:21:18 -05:00
|
|
|
"id" => user2.id,
|
2019-03-12 15:15:28 -04:00
|
|
|
"nickname" => user2.nickname,
|
2019-03-13 09:04:44 -04:00
|
|
|
"roles" => %{"admin" => false, "moderator" => false},
|
2019-03-13 18:52:24 -04:00
|
|
|
"local" => true,
|
2019-06-28 08:15:32 -04:00
|
|
|
"tags" => [],
|
|
|
|
"avatar" => User.avatar_url(user2) |> MediaProxy.url(),
|
2019-11-19 08:50:24 -05:00
|
|
|
"display_name" => HTML.strip_tags(user2.name || user2.nickname),
|
2020-06-08 14:08:57 -04:00
|
|
|
"confirmation_pending" => false,
|
2020-07-14 14:47:05 -04:00
|
|
|
"approval_pending" => false,
|
2020-07-14 14:04:57 -04:00
|
|
|
"url" => user2.ap_id,
|
|
|
|
"registration_reason" => nil
|
2019-03-02 09:21:18 -05:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "only local users" do
|
2019-10-16 14:59:21 -04:00
|
|
|
admin = insert(:user, is_admin: true, nickname: "john")
|
2019-12-15 14:32:42 -05:00
|
|
|
token = insert(:oauth_admin_token, user: admin)
|
2019-03-02 09:21:18 -05:00
|
|
|
user = insert(:user, nickname: "bob")
|
2019-03-01 12:13:02 -05:00
|
|
|
|
|
|
|
insert(:user, nickname: "bobb", local: false)
|
|
|
|
|
|
|
|
conn =
|
|
|
|
build_conn()
|
|
|
|
|> assign(:user, admin)
|
2019-12-15 14:32:42 -05:00
|
|
|
|> assign(:token, token)
|
2019-03-26 18:51:59 -04:00
|
|
|
|> get("/api/pleroma/admin/users?query=bo&filters=local")
|
2019-03-01 12:13:02 -05:00
|
|
|
|
|
|
|
assert json_response(conn, 200) == %{
|
2019-03-01 12:23:03 -05:00
|
|
|
"count" => 1,
|
|
|
|
"page_size" => 50,
|
|
|
|
"users" => [
|
|
|
|
%{
|
2019-10-16 14:59:21 -04:00
|
|
|
"deactivated" => user.deactivated,
|
2019-03-01 12:23:03 -05:00
|
|
|
"id" => user.id,
|
2019-03-12 15:15:28 -04:00
|
|
|
"nickname" => user.nickname,
|
2019-03-13 09:04:44 -04:00
|
|
|
"roles" => %{"admin" => false, "moderator" => false},
|
2019-03-13 18:52:24 -04:00
|
|
|
"local" => true,
|
2019-06-28 08:15:32 -04:00
|
|
|
"tags" => [],
|
|
|
|
"avatar" => User.avatar_url(user) |> MediaProxy.url(),
|
2019-11-19 08:50:24 -05:00
|
|
|
"display_name" => HTML.strip_tags(user.name || user.nickname),
|
2020-06-08 14:08:57 -04:00
|
|
|
"confirmation_pending" => false,
|
2020-07-14 14:47:05 -04:00
|
|
|
"approval_pending" => false,
|
2020-07-14 14:04:57 -04:00
|
|
|
"url" => user.ap_id,
|
|
|
|
"registration_reason" => nil
|
2019-03-01 12:23:03 -05:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2019-03-01 12:13:02 -05:00
|
|
|
end
|
2019-03-04 13:26:32 -05:00
|
|
|
|
2019-12-15 14:32:42 -05:00
|
|
|
test "only local users with no query", %{conn: conn, admin: old_admin} do
|
2019-10-16 14:59:21 -04:00
|
|
|
admin = insert(:user, is_admin: true, nickname: "john")
|
2019-03-04 13:26:32 -05:00
|
|
|
user = insert(:user, nickname: "bob")
|
|
|
|
|
|
|
|
insert(:user, nickname: "bobb", local: false)
|
|
|
|
|
2019-12-15 14:32:42 -05:00
|
|
|
conn = get(conn, "/api/pleroma/admin/users?filters=local")
|
2019-03-04 13:26:32 -05:00
|
|
|
|
2019-05-29 10:04:58 -04:00
|
|
|
users =
|
|
|
|
[
|
|
|
|
%{
|
2019-10-16 14:59:21 -04:00
|
|
|
"deactivated" => user.deactivated,
|
2019-05-29 10:04:58 -04:00
|
|
|
"id" => user.id,
|
|
|
|
"nickname" => user.nickname,
|
|
|
|
"roles" => %{"admin" => false, "moderator" => false},
|
|
|
|
"local" => true,
|
2019-06-28 08:15:32 -04:00
|
|
|
"tags" => [],
|
|
|
|
"avatar" => User.avatar_url(user) |> MediaProxy.url(),
|
2019-11-19 08:50:24 -05:00
|
|
|
"display_name" => HTML.strip_tags(user.name || user.nickname),
|
2020-06-08 14:08:57 -04:00
|
|
|
"confirmation_pending" => false,
|
2020-07-14 14:47:05 -04:00
|
|
|
"approval_pending" => false,
|
2020-07-14 14:04:57 -04:00
|
|
|
"url" => user.ap_id,
|
|
|
|
"registration_reason" => nil
|
2019-05-29 10:04:58 -04:00
|
|
|
},
|
|
|
|
%{
|
2019-10-16 14:59:21 -04:00
|
|
|
"deactivated" => admin.deactivated,
|
2019-05-29 10:04:58 -04:00
|
|
|
"id" => admin.id,
|
|
|
|
"nickname" => admin.nickname,
|
|
|
|
"roles" => %{"admin" => true, "moderator" => false},
|
|
|
|
"local" => true,
|
2019-06-28 08:15:32 -04:00
|
|
|
"tags" => [],
|
|
|
|
"avatar" => User.avatar_url(admin) |> MediaProxy.url(),
|
2019-11-19 08:50:24 -05:00
|
|
|
"display_name" => HTML.strip_tags(admin.name || admin.nickname),
|
2020-06-08 14:08:57 -04:00
|
|
|
"confirmation_pending" => false,
|
2020-07-14 14:47:05 -04:00
|
|
|
"approval_pending" => false,
|
2020-07-14 14:04:57 -04:00
|
|
|
"url" => admin.ap_id,
|
|
|
|
"registration_reason" => nil
|
2019-05-29 10:04:58 -04:00
|
|
|
},
|
|
|
|
%{
|
|
|
|
"deactivated" => false,
|
|
|
|
"id" => old_admin.id,
|
|
|
|
"local" => true,
|
|
|
|
"nickname" => old_admin.nickname,
|
|
|
|
"roles" => %{"admin" => true, "moderator" => false},
|
2019-06-28 08:15:32 -04:00
|
|
|
"tags" => [],
|
|
|
|
"avatar" => User.avatar_url(old_admin) |> MediaProxy.url(),
|
2019-11-19 08:50:24 -05:00
|
|
|
"display_name" => HTML.strip_tags(old_admin.name || old_admin.nickname),
|
2020-06-08 14:08:57 -04:00
|
|
|
"confirmation_pending" => false,
|
2020-07-14 14:47:05 -04:00
|
|
|
"approval_pending" => false,
|
2020-07-14 14:04:57 -04:00
|
|
|
"url" => old_admin.ap_id,
|
|
|
|
"registration_reason" => nil
|
2019-05-29 10:04:58 -04:00
|
|
|
}
|
|
|
|
]
|
|
|
|
|> Enum.sort_by(& &1["nickname"])
|
|
|
|
|
2019-03-04 13:26:32 -05:00
|
|
|
assert json_response(conn, 200) == %{
|
2019-05-08 10:34:36 -04:00
|
|
|
"count" => 3,
|
2019-03-04 13:26:32 -05:00
|
|
|
"page_size" => 50,
|
2019-05-29 10:04:58 -04:00
|
|
|
"users" => users
|
2019-05-08 10:34:36 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2020-07-14 15:14:43 -04:00
|
|
|
test "only unapproved users", %{conn: conn} do
|
|
|
|
user =
|
|
|
|
insert(:user,
|
|
|
|
nickname: "sadboy",
|
|
|
|
approval_pending: true,
|
|
|
|
registration_reason: "Plz let me in!"
|
|
|
|
)
|
|
|
|
|
|
|
|
insert(:user, nickname: "happyboy", approval_pending: false)
|
|
|
|
|
|
|
|
conn = get(conn, "/api/pleroma/admin/users?filters=need_approval")
|
|
|
|
|
|
|
|
users =
|
|
|
|
[
|
|
|
|
%{
|
|
|
|
"deactivated" => user.deactivated,
|
|
|
|
"id" => user.id,
|
|
|
|
"nickname" => user.nickname,
|
|
|
|
"roles" => %{"admin" => false, "moderator" => false},
|
|
|
|
"local" => true,
|
|
|
|
"tags" => [],
|
|
|
|
"avatar" => User.avatar_url(user) |> MediaProxy.url(),
|
|
|
|
"display_name" => HTML.strip_tags(user.name || user.nickname),
|
|
|
|
"confirmation_pending" => false,
|
|
|
|
"approval_pending" => true,
|
|
|
|
"url" => user.ap_id,
|
|
|
|
"registration_reason" => "Plz let me in!"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|> Enum.sort_by(& &1["nickname"])
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == %{
|
|
|
|
"count" => 1,
|
|
|
|
"page_size" => 50,
|
|
|
|
"users" => users
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2019-05-08 10:34:36 -04:00
|
|
|
test "load only admins", %{conn: conn, admin: admin} do
|
2019-10-16 14:59:21 -04:00
|
|
|
second_admin = insert(:user, is_admin: true)
|
2019-05-08 10:34:36 -04:00
|
|
|
insert(:user)
|
|
|
|
insert(:user)
|
|
|
|
|
|
|
|
conn = get(conn, "/api/pleroma/admin/users?filters=is_admin")
|
|
|
|
|
2019-05-29 10:04:58 -04:00
|
|
|
users =
|
|
|
|
[
|
|
|
|
%{
|
|
|
|
"deactivated" => false,
|
|
|
|
"id" => admin.id,
|
|
|
|
"nickname" => admin.nickname,
|
|
|
|
"roles" => %{"admin" => true, "moderator" => false},
|
|
|
|
"local" => admin.local,
|
2019-06-28 08:15:32 -04:00
|
|
|
"tags" => [],
|
|
|
|
"avatar" => User.avatar_url(admin) |> MediaProxy.url(),
|
2019-11-19 08:50:24 -05:00
|
|
|
"display_name" => HTML.strip_tags(admin.name || admin.nickname),
|
2020-06-08 14:08:57 -04:00
|
|
|
"confirmation_pending" => false,
|
2020-07-14 14:47:05 -04:00
|
|
|
"approval_pending" => false,
|
2020-07-14 14:04:57 -04:00
|
|
|
"url" => admin.ap_id,
|
|
|
|
"registration_reason" => nil
|
2019-05-29 10:04:58 -04:00
|
|
|
},
|
|
|
|
%{
|
|
|
|
"deactivated" => false,
|
|
|
|
"id" => second_admin.id,
|
|
|
|
"nickname" => second_admin.nickname,
|
|
|
|
"roles" => %{"admin" => true, "moderator" => false},
|
|
|
|
"local" => second_admin.local,
|
2019-06-28 08:15:32 -04:00
|
|
|
"tags" => [],
|
|
|
|
"avatar" => User.avatar_url(second_admin) |> MediaProxy.url(),
|
2019-11-19 08:50:24 -05:00
|
|
|
"display_name" => HTML.strip_tags(second_admin.name || second_admin.nickname),
|
2020-06-08 14:08:57 -04:00
|
|
|
"confirmation_pending" => false,
|
2020-07-14 14:47:05 -04:00
|
|
|
"approval_pending" => false,
|
2020-07-14 14:04:57 -04:00
|
|
|
"url" => second_admin.ap_id,
|
|
|
|
"registration_reason" => nil
|
2019-05-29 10:04:58 -04:00
|
|
|
}
|
|
|
|
]
|
|
|
|
|> Enum.sort_by(& &1["nickname"])
|
|
|
|
|
2019-05-08 10:34:36 -04:00
|
|
|
assert json_response(conn, 200) == %{
|
|
|
|
"count" => 2,
|
|
|
|
"page_size" => 50,
|
2019-05-29 10:04:58 -04:00
|
|
|
"users" => users
|
2019-05-08 10:34:36 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "load only moderators", %{conn: conn} do
|
2019-10-16 14:59:21 -04:00
|
|
|
moderator = insert(:user, is_moderator: true)
|
2019-05-08 10:34:36 -04:00
|
|
|
insert(:user)
|
|
|
|
insert(:user)
|
|
|
|
|
|
|
|
conn = get(conn, "/api/pleroma/admin/users?filters=is_moderator")
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == %{
|
|
|
|
"count" => 1,
|
|
|
|
"page_size" => 50,
|
|
|
|
"users" => [
|
|
|
|
%{
|
|
|
|
"deactivated" => false,
|
|
|
|
"id" => moderator.id,
|
|
|
|
"nickname" => moderator.nickname,
|
|
|
|
"roles" => %{"admin" => false, "moderator" => true},
|
|
|
|
"local" => moderator.local,
|
2019-06-28 08:15:32 -04:00
|
|
|
"tags" => [],
|
|
|
|
"avatar" => User.avatar_url(moderator) |> MediaProxy.url(),
|
2019-11-19 08:50:24 -05:00
|
|
|
"display_name" => HTML.strip_tags(moderator.name || moderator.nickname),
|
2020-06-08 14:08:57 -04:00
|
|
|
"confirmation_pending" => false,
|
2020-07-14 14:47:05 -04:00
|
|
|
"approval_pending" => false,
|
2020-07-14 14:04:57 -04:00
|
|
|
"url" => moderator.ap_id,
|
|
|
|
"registration_reason" => nil
|
2019-05-08 10:34:36 -04:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "load users with tags list", %{conn: conn} do
|
|
|
|
user1 = insert(:user, tags: ["first"])
|
|
|
|
user2 = insert(:user, tags: ["second"])
|
|
|
|
insert(:user)
|
|
|
|
insert(:user)
|
|
|
|
|
|
|
|
conn = get(conn, "/api/pleroma/admin/users?tags[]=first&tags[]=second")
|
|
|
|
|
2019-05-29 10:04:58 -04:00
|
|
|
users =
|
|
|
|
[
|
|
|
|
%{
|
|
|
|
"deactivated" => false,
|
|
|
|
"id" => user1.id,
|
|
|
|
"nickname" => user1.nickname,
|
|
|
|
"roles" => %{"admin" => false, "moderator" => false},
|
|
|
|
"local" => user1.local,
|
2019-06-28 08:15:32 -04:00
|
|
|
"tags" => ["first"],
|
|
|
|
"avatar" => User.avatar_url(user1) |> MediaProxy.url(),
|
2019-11-19 08:50:24 -05:00
|
|
|
"display_name" => HTML.strip_tags(user1.name || user1.nickname),
|
2020-06-08 14:08:57 -04:00
|
|
|
"confirmation_pending" => false,
|
2020-07-14 14:47:05 -04:00
|
|
|
"approval_pending" => false,
|
2020-07-14 14:04:57 -04:00
|
|
|
"url" => user1.ap_id,
|
|
|
|
"registration_reason" => nil
|
2019-05-29 10:04:58 -04:00
|
|
|
},
|
|
|
|
%{
|
|
|
|
"deactivated" => false,
|
|
|
|
"id" => user2.id,
|
|
|
|
"nickname" => user2.nickname,
|
|
|
|
"roles" => %{"admin" => false, "moderator" => false},
|
|
|
|
"local" => user2.local,
|
2019-06-28 08:15:32 -04:00
|
|
|
"tags" => ["second"],
|
|
|
|
"avatar" => User.avatar_url(user2) |> MediaProxy.url(),
|
2019-11-19 08:50:24 -05:00
|
|
|
"display_name" => HTML.strip_tags(user2.name || user2.nickname),
|
2020-06-08 14:08:57 -04:00
|
|
|
"confirmation_pending" => false,
|
2020-07-14 14:47:05 -04:00
|
|
|
"approval_pending" => false,
|
2020-07-14 14:04:57 -04:00
|
|
|
"url" => user2.ap_id,
|
|
|
|
"registration_reason" => nil
|
2019-05-29 10:04:58 -04:00
|
|
|
}
|
|
|
|
]
|
|
|
|
|> Enum.sort_by(& &1["nickname"])
|
|
|
|
|
2019-05-08 10:34:36 -04:00
|
|
|
assert json_response(conn, 200) == %{
|
|
|
|
"count" => 2,
|
|
|
|
"page_size" => 50,
|
2019-05-29 10:04:58 -04:00
|
|
|
"users" => users
|
2019-03-04 13:26:32 -05:00
|
|
|
}
|
|
|
|
end
|
2019-03-26 18:51:59 -04:00
|
|
|
|
|
|
|
test "it works with multiple filters" do
|
2019-10-16 14:59:21 -04:00
|
|
|
admin = insert(:user, nickname: "john", is_admin: true)
|
2019-12-15 14:32:42 -05:00
|
|
|
token = insert(:oauth_admin_token, user: admin)
|
2019-10-16 14:59:21 -04:00
|
|
|
user = insert(:user, nickname: "bob", local: false, deactivated: true)
|
2019-03-26 18:51:59 -04:00
|
|
|
|
2019-10-16 14:59:21 -04:00
|
|
|
insert(:user, nickname: "ken", local: true, deactivated: true)
|
|
|
|
insert(:user, nickname: "bobb", local: false, deactivated: false)
|
2019-03-26 18:51:59 -04:00
|
|
|
|
|
|
|
conn =
|
|
|
|
build_conn()
|
|
|
|
|> assign(:user, admin)
|
2019-12-15 14:32:42 -05:00
|
|
|
|> assign(:token, token)
|
2019-03-26 18:51:59 -04:00
|
|
|
|> get("/api/pleroma/admin/users?filters=deactivated,external")
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == %{
|
|
|
|
"count" => 1,
|
|
|
|
"page_size" => 50,
|
|
|
|
"users" => [
|
|
|
|
%{
|
2019-10-16 14:59:21 -04:00
|
|
|
"deactivated" => user.deactivated,
|
2019-03-26 18:51:59 -04:00
|
|
|
"id" => user.id,
|
|
|
|
"nickname" => user.nickname,
|
|
|
|
"roles" => %{"admin" => false, "moderator" => false},
|
|
|
|
"local" => user.local,
|
2019-06-28 08:15:32 -04:00
|
|
|
"tags" => [],
|
|
|
|
"avatar" => User.avatar_url(user) |> MediaProxy.url(),
|
2019-11-19 08:50:24 -05:00
|
|
|
"display_name" => HTML.strip_tags(user.name || user.nickname),
|
2020-06-08 14:08:57 -04:00
|
|
|
"confirmation_pending" => false,
|
2020-07-14 14:47:05 -04:00
|
|
|
"approval_pending" => false,
|
2020-07-14 14:04:57 -04:00
|
|
|
"url" => user.ap_id,
|
|
|
|
"registration_reason" => nil
|
2019-03-26 18:51:59 -04:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
end
|
2019-10-30 19:26:02 -04:00
|
|
|
|
2019-12-15 14:32:42 -05:00
|
|
|
test "it omits relay user", %{admin: admin, conn: conn} do
|
2019-10-30 19:26:02 -04:00
|
|
|
assert %User{} = Relay.get_actor()
|
|
|
|
|
2019-12-15 14:32:42 -05:00
|
|
|
conn = get(conn, "/api/pleroma/admin/users")
|
2019-10-30 19:26:02 -04:00
|
|
|
|
|
|
|
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(),
|
2019-11-19 08:50:24 -05:00
|
|
|
"display_name" => HTML.strip_tags(admin.name || admin.nickname),
|
2020-06-08 14:08:57 -04:00
|
|
|
"confirmation_pending" => false,
|
2020-07-14 14:47:05 -04:00
|
|
|
"approval_pending" => false,
|
2020-07-14 14:04:57 -04:00
|
|
|
"url" => admin.ap_id,
|
|
|
|
"registration_reason" => nil
|
2019-10-30 19:26:02 -04:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
end
|
2019-03-04 13:26:32 -05:00
|
|
|
end
|
|
|
|
|
2019-12-15 14:32:42 -05:00
|
|
|
test "PATCH /api/pleroma/admin/users/activate", %{admin: admin, conn: conn} do
|
2019-10-20 13:43:18 -04:00
|
|
|
user_one = insert(:user, deactivated: true)
|
|
|
|
user_two = insert(:user, deactivated: true)
|
2019-03-04 13:26:32 -05:00
|
|
|
|
|
|
|
conn =
|
2019-12-15 14:32:42 -05:00
|
|
|
patch(
|
|
|
|
conn,
|
2019-10-09 10:03:54 -04:00
|
|
|
"/api/pleroma/admin/users/activate",
|
|
|
|
%{nicknames: [user_one.nickname, user_two.nickname]}
|
|
|
|
)
|
|
|
|
|
|
|
|
response = json_response(conn, 200)
|
|
|
|
assert Enum.map(response["users"], & &1["deactivated"]) == [false, false]
|
|
|
|
|
|
|
|
log_entry = Repo.one(ModerationLog)
|
|
|
|
|
|
|
|
assert ModerationLog.get_log_entry_message(log_entry) ==
|
|
|
|
"@#{admin.nickname} activated users: @#{user_one.nickname}, @#{user_two.nickname}"
|
|
|
|
end
|
|
|
|
|
2019-12-15 14:32:42 -05:00
|
|
|
test "PATCH /api/pleroma/admin/users/deactivate", %{admin: admin, conn: conn} do
|
2019-10-20 13:43:18 -04:00
|
|
|
user_one = insert(:user, deactivated: false)
|
|
|
|
user_two = insert(:user, deactivated: false)
|
2019-10-09 10:03:54 -04:00
|
|
|
|
|
|
|
conn =
|
2019-12-15 14:32:42 -05:00
|
|
|
patch(
|
|
|
|
conn,
|
2019-10-09 10:03:54 -04:00
|
|
|
"/api/pleroma/admin/users/deactivate",
|
|
|
|
%{nicknames: [user_one.nickname, user_two.nickname]}
|
|
|
|
)
|
|
|
|
|
|
|
|
response = json_response(conn, 200)
|
|
|
|
assert Enum.map(response["users"], & &1["deactivated"]) == [true, true]
|
2019-08-25 15:39:37 -04:00
|
|
|
|
|
|
|
log_entry = Repo.one(ModerationLog)
|
|
|
|
|
|
|
|
assert ModerationLog.get_log_entry_message(log_entry) ==
|
2019-10-09 10:03:54 -04:00
|
|
|
"@#{admin.nickname} deactivated users: @#{user_one.nickname}, @#{user_two.nickname}"
|
2019-02-28 11:04:47 -05:00
|
|
|
end
|
2019-04-06 09:25:19 -04:00
|
|
|
|
2020-07-14 19:02:44 -04:00
|
|
|
test "PATCH /api/pleroma/admin/users/approve", %{admin: admin, conn: conn} do
|
|
|
|
user_one = insert(:user, approval_pending: true)
|
|
|
|
user_two = insert(:user, approval_pending: true)
|
|
|
|
|
|
|
|
conn =
|
|
|
|
patch(
|
|
|
|
conn,
|
|
|
|
"/api/pleroma/admin/users/approve",
|
|
|
|
%{nicknames: [user_one.nickname, user_two.nickname]}
|
|
|
|
)
|
|
|
|
|
|
|
|
response = json_response(conn, 200)
|
|
|
|
assert Enum.map(response["users"], & &1["approval_pending"]) == [false, false]
|
|
|
|
|
|
|
|
log_entry = Repo.one(ModerationLog)
|
|
|
|
|
|
|
|
assert ModerationLog.get_log_entry_message(log_entry) ==
|
|
|
|
"@#{admin.nickname} approved users: @#{user_one.nickname}, @#{user_two.nickname}"
|
|
|
|
end
|
|
|
|
|
2019-12-15 14:32:42 -05:00
|
|
|
test "PATCH /api/pleroma/admin/users/:nickname/toggle_activation", %{admin: admin, conn: conn} do
|
2019-03-04 13:26:32 -05:00
|
|
|
user = insert(:user)
|
|
|
|
|
2019-12-15 14:32:42 -05:00
|
|
|
conn = patch(conn, "/api/pleroma/admin/users/#{user.nickname}/toggle_activation")
|
2019-03-04 13:26:32 -05:00
|
|
|
|
|
|
|
assert json_response(conn, 200) ==
|
|
|
|
%{
|
2019-10-16 14:59:21 -04:00
|
|
|
"deactivated" => !user.deactivated,
|
2019-03-04 13:26:32 -05:00
|
|
|
"id" => user.id,
|
2019-03-12 15:15:28 -04:00
|
|
|
"nickname" => user.nickname,
|
2019-03-13 09:04:44 -04:00
|
|
|
"roles" => %{"admin" => false, "moderator" => false},
|
2019-03-13 18:52:24 -04:00
|
|
|
"local" => true,
|
2019-06-28 08:15:32 -04:00
|
|
|
"tags" => [],
|
|
|
|
"avatar" => User.avatar_url(user) |> MediaProxy.url(),
|
2019-11-19 08:50:24 -05:00
|
|
|
"display_name" => HTML.strip_tags(user.name || user.nickname),
|
2020-06-08 14:08:57 -04:00
|
|
|
"confirmation_pending" => false,
|
2020-07-14 14:47:05 -04:00
|
|
|
"approval_pending" => false,
|
2020-07-14 14:04:57 -04:00
|
|
|
"url" => user.ap_id,
|
|
|
|
"registration_reason" => nil
|
2019-03-04 13:26:32 -05:00
|
|
|
}
|
2019-08-25 15:39:37 -04:00
|
|
|
|
|
|
|
log_entry = Repo.one(ModerationLog)
|
|
|
|
|
|
|
|
assert ModerationLog.get_log_entry_message(log_entry) ==
|
2019-10-10 17:24:31 -04:00
|
|
|
"@#{admin.nickname} deactivated users: @#{user.nickname}"
|
2019-02-28 11:04:47 -05:00
|
|
|
end
|
2019-04-06 09:25:19 -04:00
|
|
|
|
2020-05-07 04:14:54 -04:00
|
|
|
describe "PUT disable_mfa" do
|
|
|
|
test "returns 200 and disable 2fa", %{conn: conn} do
|
|
|
|
user =
|
|
|
|
insert(:user,
|
|
|
|
multi_factor_authentication_settings: %MFA.Settings{
|
|
|
|
enabled: true,
|
|
|
|
totp: %MFA.Settings.TOTP{secret: "otp_secret", confirmed: true}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
response =
|
|
|
|
conn
|
|
|
|
|> put("/api/pleroma/admin/users/disable_mfa", %{nickname: user.nickname})
|
|
|
|
|> json_response(200)
|
|
|
|
|
|
|
|
assert response == user.nickname
|
|
|
|
mfa_settings = refresh_record(user).multi_factor_authentication_settings
|
|
|
|
|
|
|
|
refute mfa_settings.enabled
|
|
|
|
refute mfa_settings.totp.confirmed
|
|
|
|
end
|
|
|
|
|
|
|
|
test "returns 404 if user not found", %{conn: conn} do
|
|
|
|
response =
|
|
|
|
conn
|
|
|
|
|> put("/api/pleroma/admin/users/disable_mfa", %{nickname: "nickname"})
|
|
|
|
|> json_response(404)
|
|
|
|
|
2020-05-21 06:03:38 -04:00
|
|
|
assert response == %{"error" => "Not found"}
|
2020-05-07 04:14:54 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-01-25 10:42:04 -05:00
|
|
|
describe "GET /api/pleroma/admin/restart" do
|
2020-03-20 11:33:00 -04:00
|
|
|
setup do: clear_config(:configurable_from_database, true)
|
2020-01-25 10:42:04 -05:00
|
|
|
|
|
|
|
test "pleroma restarts", %{conn: conn} do
|
2020-02-08 04:55:37 -05:00
|
|
|
capture_log(fn ->
|
2020-01-25 10:42:04 -05:00
|
|
|
assert conn |> get("/api/pleroma/admin/restart") |> json_response(200) == %{}
|
|
|
|
end) =~ "pleroma restarted"
|
2020-02-08 04:55:37 -05:00
|
|
|
|
|
|
|
refute Restarter.Pleroma.need_reboot?()
|
2020-01-25 10:42:04 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-13 07:07:23 -04:00
|
|
|
test "need_reboot flag", %{conn: conn} do
|
|
|
|
assert conn
|
|
|
|
|> get("/api/pleroma/admin/need_reboot")
|
|
|
|
|> json_response(200) == %{"need_reboot" => false}
|
|
|
|
|
|
|
|
Restarter.Pleroma.need_reboot()
|
|
|
|
|
|
|
|
assert conn
|
|
|
|
|> get("/api/pleroma/admin/need_reboot")
|
|
|
|
|> json_response(200) == %{"need_reboot" => true}
|
|
|
|
|
|
|
|
on_exit(fn -> Restarter.Pleroma.refresh() end)
|
|
|
|
end
|
|
|
|
|
2019-07-13 17:37:19 -04:00
|
|
|
describe "GET /api/pleroma/admin/users/:nickname/statuses" do
|
|
|
|
setup do
|
|
|
|
user = insert(:user)
|
|
|
|
|
|
|
|
date1 = (DateTime.to_unix(DateTime.utc_now()) + 2000) |> DateTime.from_unix!()
|
|
|
|
date2 = (DateTime.to_unix(DateTime.utc_now()) + 1000) |> DateTime.from_unix!()
|
|
|
|
date3 = (DateTime.to_unix(DateTime.utc_now()) + 3000) |> DateTime.from_unix!()
|
|
|
|
|
|
|
|
insert(:note_activity, user: user, published: date1)
|
|
|
|
insert(:note_activity, user: user, published: date2)
|
|
|
|
insert(:note_activity, user: user, published: date3)
|
|
|
|
|
2019-12-15 14:32:42 -05:00
|
|
|
%{user: user}
|
2019-07-13 17:37:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test "renders user's statuses", %{conn: conn, user: user} do
|
|
|
|
conn = get(conn, "/api/pleroma/admin/users/#{user.nickname}/statuses")
|
|
|
|
|
|
|
|
assert json_response(conn, 200) |> length() == 3
|
|
|
|
end
|
|
|
|
|
|
|
|
test "renders user's statuses with a limit", %{conn: conn, user: user} do
|
|
|
|
conn = get(conn, "/api/pleroma/admin/users/#{user.nickname}/statuses?page_size=2")
|
|
|
|
|
|
|
|
assert json_response(conn, 200) |> length() == 2
|
|
|
|
end
|
2019-07-23 18:50:09 -04:00
|
|
|
|
|
|
|
test "doesn't return private statuses by default", %{conn: conn, user: user} do
|
2020-05-12 15:59:26 -04:00
|
|
|
{:ok, _private_status} = CommonAPI.post(user, %{status: "private", visibility: "private"})
|
2019-07-23 18:50:09 -04:00
|
|
|
|
2020-05-12 15:59:26 -04:00
|
|
|
{:ok, _public_status} = CommonAPI.post(user, %{status: "public", visibility: "public"})
|
2019-07-23 18:50:09 -04:00
|
|
|
|
|
|
|
conn = get(conn, "/api/pleroma/admin/users/#{user.nickname}/statuses")
|
|
|
|
|
|
|
|
assert json_response(conn, 200) |> length() == 4
|
|
|
|
end
|
|
|
|
|
|
|
|
test "returns private statuses with godmode on", %{conn: conn, user: user} do
|
2020-05-12 15:59:26 -04:00
|
|
|
{:ok, _private_status} = CommonAPI.post(user, %{status: "private", visibility: "private"})
|
2019-07-23 18:50:09 -04:00
|
|
|
|
2020-05-12 15:59:26 -04:00
|
|
|
{:ok, _public_status} = CommonAPI.post(user, %{status: "public", visibility: "public"})
|
2019-07-23 18:50:09 -04:00
|
|
|
|
|
|
|
conn = get(conn, "/api/pleroma/admin/users/#{user.nickname}/statuses?godmode=true")
|
|
|
|
|
|
|
|
assert json_response(conn, 200) |> length() == 5
|
|
|
|
end
|
2020-02-26 06:47:19 -05:00
|
|
|
|
|
|
|
test "excludes reblogs by default", %{conn: conn, user: user} do
|
|
|
|
other_user = insert(:user)
|
2020-05-12 15:59:26 -04:00
|
|
|
{:ok, activity} = CommonAPI.post(user, %{status: "."})
|
2020-05-21 07:16:21 -04:00
|
|
|
{:ok, %Activity{}} = CommonAPI.repeat(activity.id, other_user)
|
2020-02-26 06:47:19 -05:00
|
|
|
|
|
|
|
conn_res = get(conn, "/api/pleroma/admin/users/#{other_user.nickname}/statuses")
|
|
|
|
assert json_response(conn_res, 200) |> length() == 0
|
|
|
|
|
|
|
|
conn_res =
|
|
|
|
get(conn, "/api/pleroma/admin/users/#{other_user.nickname}/statuses?with_reblogs=true")
|
|
|
|
|
|
|
|
assert json_response(conn_res, 200) |> length() == 1
|
|
|
|
end
|
2019-07-13 17:37:19 -04:00
|
|
|
end
|
2019-08-25 15:39:37 -04:00
|
|
|
|
|
|
|
describe "GET /api/pleroma/admin/moderation_log" do
|
2019-12-15 14:32:42 -05:00
|
|
|
setup do
|
2019-10-16 14:59:21 -04:00
|
|
|
moderator = insert(:user, is_moderator: true)
|
2019-08-25 15:39:37 -04:00
|
|
|
|
2019-12-15 14:32:42 -05:00
|
|
|
%{moderator: moderator}
|
2019-08-25 15:39:37 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test "returns the log", %{conn: conn, admin: admin} do
|
|
|
|
Repo.insert(%ModerationLog{
|
|
|
|
data: %{
|
|
|
|
actor: %{
|
|
|
|
"id" => admin.id,
|
|
|
|
"nickname" => admin.nickname,
|
|
|
|
"type" => "user"
|
|
|
|
},
|
|
|
|
action: "relay_follow",
|
|
|
|
target: "https://example.org/relay"
|
|
|
|
},
|
|
|
|
inserted_at: NaiveDateTime.truncate(~N[2017-08-15 15:47:06.597036], :second)
|
|
|
|
})
|
|
|
|
|
|
|
|
Repo.insert(%ModerationLog{
|
|
|
|
data: %{
|
|
|
|
actor: %{
|
|
|
|
"id" => admin.id,
|
|
|
|
"nickname" => admin.nickname,
|
|
|
|
"type" => "user"
|
|
|
|
},
|
|
|
|
action: "relay_unfollow",
|
|
|
|
target: "https://example.org/relay"
|
|
|
|
},
|
|
|
|
inserted_at: NaiveDateTime.truncate(~N[2017-08-16 15:47:06.597036], :second)
|
|
|
|
})
|
|
|
|
|
|
|
|
conn = get(conn, "/api/pleroma/admin/moderation_log")
|
|
|
|
|
|
|
|
response = json_response(conn, 200)
|
2019-09-01 14:38:15 -04:00
|
|
|
[first_entry, second_entry] = response["items"]
|
2019-08-25 15:39:37 -04:00
|
|
|
|
2019-09-01 14:38:15 -04:00
|
|
|
assert response["total"] == 2
|
2019-08-25 15:39:37 -04:00
|
|
|
assert first_entry["data"]["action"] == "relay_unfollow"
|
|
|
|
|
|
|
|
assert first_entry["message"] ==
|
|
|
|
"@#{admin.nickname} unfollowed relay: https://example.org/relay"
|
|
|
|
|
|
|
|
assert second_entry["data"]["action"] == "relay_follow"
|
|
|
|
|
|
|
|
assert second_entry["message"] ==
|
|
|
|
"@#{admin.nickname} followed relay: https://example.org/relay"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "returns the log with pagination", %{conn: conn, admin: admin} do
|
|
|
|
Repo.insert(%ModerationLog{
|
|
|
|
data: %{
|
|
|
|
actor: %{
|
|
|
|
"id" => admin.id,
|
|
|
|
"nickname" => admin.nickname,
|
|
|
|
"type" => "user"
|
|
|
|
},
|
|
|
|
action: "relay_follow",
|
|
|
|
target: "https://example.org/relay"
|
|
|
|
},
|
|
|
|
inserted_at: NaiveDateTime.truncate(~N[2017-08-15 15:47:06.597036], :second)
|
|
|
|
})
|
|
|
|
|
|
|
|
Repo.insert(%ModerationLog{
|
|
|
|
data: %{
|
|
|
|
actor: %{
|
|
|
|
"id" => admin.id,
|
|
|
|
"nickname" => admin.nickname,
|
|
|
|
"type" => "user"
|
|
|
|
},
|
|
|
|
action: "relay_unfollow",
|
|
|
|
target: "https://example.org/relay"
|
|
|
|
},
|
|
|
|
inserted_at: NaiveDateTime.truncate(~N[2017-08-16 15:47:06.597036], :second)
|
|
|
|
})
|
|
|
|
|
|
|
|
conn1 = get(conn, "/api/pleroma/admin/moderation_log?page_size=1&page=1")
|
|
|
|
|
|
|
|
response1 = json_response(conn1, 200)
|
2019-09-01 14:38:15 -04:00
|
|
|
[first_entry] = response1["items"]
|
2019-08-25 15:39:37 -04:00
|
|
|
|
2019-09-01 14:38:15 -04:00
|
|
|
assert response1["total"] == 2
|
|
|
|
assert response1["items"] |> length() == 1
|
2019-08-25 15:39:37 -04:00
|
|
|
assert first_entry["data"]["action"] == "relay_unfollow"
|
|
|
|
|
|
|
|
assert first_entry["message"] ==
|
|
|
|
"@#{admin.nickname} unfollowed relay: https://example.org/relay"
|
|
|
|
|
|
|
|
conn2 = get(conn, "/api/pleroma/admin/moderation_log?page_size=1&page=2")
|
|
|
|
|
|
|
|
response2 = json_response(conn2, 200)
|
2019-09-01 14:38:15 -04:00
|
|
|
[second_entry] = response2["items"]
|
2019-08-25 15:39:37 -04:00
|
|
|
|
2019-09-01 14:38:15 -04:00
|
|
|
assert response2["total"] == 2
|
|
|
|
assert response2["items"] |> length() == 1
|
2019-08-25 15:39:37 -04:00
|
|
|
assert second_entry["data"]["action"] == "relay_follow"
|
|
|
|
|
|
|
|
assert second_entry["message"] ==
|
|
|
|
"@#{admin.nickname} followed relay: https://example.org/relay"
|
|
|
|
end
|
2019-08-27 13:48:16 -04:00
|
|
|
|
|
|
|
test "filters log by date", %{conn: conn, admin: admin} do
|
|
|
|
first_date = "2017-08-15T15:47:06Z"
|
|
|
|
second_date = "2017-08-20T15:47:06Z"
|
|
|
|
|
|
|
|
Repo.insert(%ModerationLog{
|
|
|
|
data: %{
|
|
|
|
actor: %{
|
|
|
|
"id" => admin.id,
|
|
|
|
"nickname" => admin.nickname,
|
|
|
|
"type" => "user"
|
|
|
|
},
|
|
|
|
action: "relay_follow",
|
|
|
|
target: "https://example.org/relay"
|
|
|
|
},
|
|
|
|
inserted_at: NaiveDateTime.from_iso8601!(first_date)
|
|
|
|
})
|
|
|
|
|
|
|
|
Repo.insert(%ModerationLog{
|
|
|
|
data: %{
|
|
|
|
actor: %{
|
|
|
|
"id" => admin.id,
|
|
|
|
"nickname" => admin.nickname,
|
|
|
|
"type" => "user"
|
|
|
|
},
|
|
|
|
action: "relay_unfollow",
|
|
|
|
target: "https://example.org/relay"
|
|
|
|
},
|
|
|
|
inserted_at: NaiveDateTime.from_iso8601!(second_date)
|
|
|
|
})
|
|
|
|
|
|
|
|
conn1 =
|
|
|
|
get(
|
|
|
|
conn,
|
|
|
|
"/api/pleroma/admin/moderation_log?start_date=#{second_date}"
|
|
|
|
)
|
|
|
|
|
|
|
|
response1 = json_response(conn1, 200)
|
2019-09-01 14:38:15 -04:00
|
|
|
[first_entry] = response1["items"]
|
2019-08-27 13:48:16 -04:00
|
|
|
|
2019-09-01 14:38:15 -04:00
|
|
|
assert response1["total"] == 1
|
2019-08-27 13:48:16 -04:00
|
|
|
assert first_entry["data"]["action"] == "relay_unfollow"
|
|
|
|
|
|
|
|
assert first_entry["message"] ==
|
|
|
|
"@#{admin.nickname} unfollowed relay: https://example.org/relay"
|
|
|
|
end
|
2019-08-30 17:57:15 -04:00
|
|
|
|
|
|
|
test "returns log filtered by user", %{conn: conn, admin: admin, moderator: moderator} do
|
|
|
|
Repo.insert(%ModerationLog{
|
|
|
|
data: %{
|
|
|
|
actor: %{
|
|
|
|
"id" => admin.id,
|
|
|
|
"nickname" => admin.nickname,
|
|
|
|
"type" => "user"
|
|
|
|
},
|
|
|
|
action: "relay_follow",
|
|
|
|
target: "https://example.org/relay"
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
Repo.insert(%ModerationLog{
|
|
|
|
data: %{
|
|
|
|
actor: %{
|
|
|
|
"id" => moderator.id,
|
|
|
|
"nickname" => moderator.nickname,
|
|
|
|
"type" => "user"
|
|
|
|
},
|
|
|
|
action: "relay_unfollow",
|
|
|
|
target: "https://example.org/relay"
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
conn1 = get(conn, "/api/pleroma/admin/moderation_log?user_id=#{moderator.id}")
|
|
|
|
|
|
|
|
response1 = json_response(conn1, 200)
|
2019-09-01 14:38:15 -04:00
|
|
|
[first_entry] = response1["items"]
|
2019-08-30 17:57:15 -04:00
|
|
|
|
2019-09-01 14:38:15 -04:00
|
|
|
assert response1["total"] == 1
|
2019-08-30 17:57:15 -04:00
|
|
|
assert get_in(first_entry, ["data", "actor", "id"]) == moderator.id
|
|
|
|
end
|
|
|
|
|
|
|
|
test "returns log filtered by search", %{conn: conn, moderator: moderator} do
|
|
|
|
ModerationLog.insert_log(%{
|
|
|
|
actor: moderator,
|
|
|
|
action: "relay_follow",
|
|
|
|
target: "https://example.org/relay"
|
|
|
|
})
|
|
|
|
|
|
|
|
ModerationLog.insert_log(%{
|
|
|
|
actor: moderator,
|
|
|
|
action: "relay_unfollow",
|
|
|
|
target: "https://example.org/relay"
|
|
|
|
})
|
|
|
|
|
|
|
|
conn1 = get(conn, "/api/pleroma/admin/moderation_log?search=unfo")
|
|
|
|
|
|
|
|
response1 = json_response(conn1, 200)
|
2019-09-01 14:38:15 -04:00
|
|
|
[first_entry] = response1["items"]
|
2019-08-30 17:57:15 -04:00
|
|
|
|
2019-09-01 14:38:15 -04:00
|
|
|
assert response1["total"] == 1
|
2019-08-30 17:57:15 -04:00
|
|
|
|
|
|
|
assert get_in(first_entry, ["data", "message"]) ==
|
|
|
|
"@#{moderator.nickname} unfollowed relay: https://example.org/relay"
|
|
|
|
end
|
2019-08-25 15:39:37 -04:00
|
|
|
end
|
2019-09-22 09:08:07 -04:00
|
|
|
|
2020-05-18 15:56:09 -04:00
|
|
|
test "gets a remote users when [:instance, :limit_to_local_content] is set to :unauthenticated",
|
|
|
|
%{conn: conn} do
|
|
|
|
clear_config(Pleroma.Config.get([:instance, :limit_to_local_content]), :unauthenticated)
|
|
|
|
user = insert(:user, %{local: false, nickname: "u@peer1.com"})
|
|
|
|
conn = get(conn, "/api/pleroma/admin/users/#{user.nickname}/credentials")
|
|
|
|
|
|
|
|
assert json_response(conn, 200)
|
|
|
|
end
|
|
|
|
|
2020-01-31 13:07:46 -05:00
|
|
|
describe "GET /users/:nickname/credentials" do
|
|
|
|
test "gets the user credentials", %{conn: conn} do
|
|
|
|
user = insert(:user)
|
|
|
|
conn = get(conn, "/api/pleroma/admin/users/#{user.nickname}/credentials")
|
|
|
|
|
|
|
|
response = assert json_response(conn, 200)
|
|
|
|
assert response["email"] == user.email
|
|
|
|
end
|
|
|
|
|
|
|
|
test "returns 403 if requested by a non-admin" do
|
|
|
|
user = insert(:user)
|
|
|
|
|
|
|
|
conn =
|
|
|
|
build_conn()
|
|
|
|
|> assign(:user, user)
|
|
|
|
|> get("/api/pleroma/admin/users/#{user.nickname}/credentials")
|
|
|
|
|
|
|
|
assert json_response(conn, :forbidden)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "PATCH /users/:nickname/credentials" do
|
2020-05-27 02:42:28 -04:00
|
|
|
setup do
|
2020-01-28 01:47:59 -05:00
|
|
|
user = insert(:user)
|
2020-05-27 02:42:28 -04:00
|
|
|
[user: user]
|
|
|
|
end
|
|
|
|
|
|
|
|
test "changes password and email", %{conn: conn, admin: admin, user: user} do
|
2020-01-28 01:47:59 -05:00
|
|
|
assert user.password_reset_pending == false
|
|
|
|
|
|
|
|
conn =
|
2020-01-31 13:07:46 -05:00
|
|
|
patch(conn, "/api/pleroma/admin/users/#{user.nickname}/credentials", %{
|
|
|
|
"password" => "new_password",
|
|
|
|
"email" => "new_email@example.com",
|
|
|
|
"name" => "new_name"
|
2020-01-28 01:47:59 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == %{"status" => "success"}
|
|
|
|
|
|
|
|
ObanHelpers.perform_all()
|
|
|
|
|
2020-01-31 13:07:46 -05:00
|
|
|
updated_user = User.get_by_id(user.id)
|
2020-01-28 01:47:59 -05:00
|
|
|
|
2020-01-31 13:07:46 -05:00
|
|
|
assert updated_user.email == "new_email@example.com"
|
|
|
|
assert updated_user.name == "new_name"
|
|
|
|
assert updated_user.password_hash != user.password_hash
|
|
|
|
assert updated_user.password_reset_pending == true
|
|
|
|
|
|
|
|
[log_entry2, log_entry1] = ModerationLog |> Repo.all() |> Enum.sort()
|
2020-01-28 01:47:59 -05:00
|
|
|
|
|
|
|
assert ModerationLog.get_log_entry_message(log_entry1) ==
|
2020-01-31 13:07:46 -05:00
|
|
|
"@#{admin.nickname} updated users: @#{user.nickname}"
|
2020-01-28 01:47:59 -05:00
|
|
|
|
|
|
|
assert ModerationLog.get_log_entry_message(log_entry2) ==
|
|
|
|
"@#{admin.nickname} forced password reset for users: @#{user.nickname}"
|
|
|
|
end
|
2020-01-31 13:07:46 -05:00
|
|
|
|
2020-05-27 02:42:28 -04:00
|
|
|
test "returns 403 if requested by a non-admin", %{user: user} do
|
2020-01-31 13:07:46 -05:00
|
|
|
conn =
|
|
|
|
build_conn()
|
|
|
|
|> assign(:user, user)
|
|
|
|
|> patch("/api/pleroma/admin/users/#{user.nickname}/credentials", %{
|
|
|
|
"password" => "new_password",
|
|
|
|
"email" => "new_email@example.com",
|
|
|
|
"name" => "new_name"
|
|
|
|
})
|
|
|
|
|
|
|
|
assert json_response(conn, :forbidden)
|
|
|
|
end
|
2020-05-27 02:42:28 -04:00
|
|
|
|
|
|
|
test "changes actor type from permitted list", %{conn: conn, user: user} do
|
|
|
|
assert user.actor_type == "Person"
|
|
|
|
|
|
|
|
assert patch(conn, "/api/pleroma/admin/users/#{user.nickname}/credentials", %{
|
|
|
|
"actor_type" => "Service"
|
|
|
|
})
|
|
|
|
|> json_response(200) == %{"status" => "success"}
|
|
|
|
|
|
|
|
updated_user = User.get_by_id(user.id)
|
|
|
|
|
|
|
|
assert updated_user.actor_type == "Service"
|
|
|
|
|
|
|
|
assert patch(conn, "/api/pleroma/admin/users/#{user.nickname}/credentials", %{
|
|
|
|
"actor_type" => "Application"
|
|
|
|
})
|
2020-06-20 06:53:57 -04:00
|
|
|
|> json_response(400) == %{"errors" => %{"actor_type" => "is invalid"}}
|
2020-05-27 02:42:28 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test "update non existing user", %{conn: conn} do
|
|
|
|
assert patch(conn, "/api/pleroma/admin/users/non-existing/credentials", %{
|
|
|
|
"password" => "new_password"
|
|
|
|
})
|
2020-06-20 06:53:57 -04:00
|
|
|
|> json_response(404) == %{"error" => "Not found"}
|
2020-05-27 02:42:28 -04:00
|
|
|
end
|
2020-01-28 01:47:59 -05:00
|
|
|
end
|
|
|
|
|
2019-09-22 09:08:07 -04:00
|
|
|
describe "PATCH /users/:nickname/force_password_reset" do
|
2019-12-15 14:32:42 -05:00
|
|
|
test "sets password_reset_pending to true", %{conn: conn} do
|
2019-09-22 09:08:07 -04:00
|
|
|
user = insert(:user)
|
2019-10-16 14:59:21 -04:00
|
|
|
assert user.password_reset_pending == false
|
2019-09-22 09:08:07 -04:00
|
|
|
|
|
|
|
conn =
|
2019-12-15 14:32:42 -05:00
|
|
|
patch(conn, "/api/pleroma/admin/users/force_password_reset", %{nicknames: [user.nickname]})
|
2019-09-22 09:08:07 -04:00
|
|
|
|
|
|
|
assert json_response(conn, 204) == ""
|
|
|
|
|
|
|
|
ObanHelpers.perform_all()
|
|
|
|
|
2019-10-16 14:59:21 -04:00
|
|
|
assert User.get_by_id(user.id).password_reset_pending == true
|
2019-09-22 09:08:07 -04:00
|
|
|
end
|
|
|
|
end
|
2019-10-11 12:12:29 -04:00
|
|
|
|
2019-11-14 09:44:07 -05:00
|
|
|
describe "instances" do
|
2019-12-15 14:32:42 -05:00
|
|
|
test "GET /instances/:instance/statuses", %{conn: conn} do
|
2019-11-14 09:44:07 -05:00
|
|
|
user = insert(:user, local: false, nickname: "archaeme@archae.me")
|
|
|
|
user2 = insert(:user, local: false, nickname: "test@test.com")
|
|
|
|
insert_pair(:note_activity, user: user)
|
2020-02-26 06:47:19 -05:00
|
|
|
activity = insert(:note_activity, user: user2)
|
2019-11-14 09:44:07 -05:00
|
|
|
|
2019-12-15 14:32:42 -05:00
|
|
|
ret_conn = get(conn, "/api/pleroma/admin/instances/archae.me/statuses")
|
2019-11-14 09:44:07 -05:00
|
|
|
|
2019-12-15 14:32:42 -05:00
|
|
|
response = json_response(ret_conn, 200)
|
2019-11-14 09:44:07 -05:00
|
|
|
|
|
|
|
assert length(response) == 2
|
|
|
|
|
2019-12-15 14:32:42 -05:00
|
|
|
ret_conn = get(conn, "/api/pleroma/admin/instances/test.com/statuses")
|
2019-11-14 09:44:07 -05:00
|
|
|
|
2019-12-15 14:32:42 -05:00
|
|
|
response = json_response(ret_conn, 200)
|
2019-11-14 09:44:07 -05:00
|
|
|
|
|
|
|
assert length(response) == 1
|
|
|
|
|
2019-12-15 14:32:42 -05:00
|
|
|
ret_conn = get(conn, "/api/pleroma/admin/instances/nonexistent.com/statuses")
|
2019-11-14 09:44:07 -05:00
|
|
|
|
2019-12-15 14:32:42 -05:00
|
|
|
response = json_response(ret_conn, 200)
|
2019-11-14 09:44:07 -05:00
|
|
|
|
2020-01-20 05:53:14 -05:00
|
|
|
assert Enum.empty?(response)
|
2020-02-26 06:47:19 -05:00
|
|
|
|
|
|
|
CommonAPI.repeat(activity.id, user)
|
|
|
|
|
|
|
|
ret_conn = get(conn, "/api/pleroma/admin/instances/archae.me/statuses")
|
|
|
|
response = json_response(ret_conn, 200)
|
|
|
|
assert length(response) == 2
|
|
|
|
|
|
|
|
ret_conn = get(conn, "/api/pleroma/admin/instances/archae.me/statuses?with_reblogs=true")
|
|
|
|
response = json_response(ret_conn, 200)
|
|
|
|
assert length(response) == 3
|
2019-11-14 09:44:07 -05:00
|
|
|
end
|
|
|
|
end
|
2019-11-24 11:46:18 -05:00
|
|
|
|
2019-11-19 06:14:02 -05:00
|
|
|
describe "PATCH /confirm_email" do
|
2019-12-15 14:32:42 -05:00
|
|
|
test "it confirms emails of two users", %{conn: conn, admin: admin} do
|
2019-11-19 06:14:02 -05:00
|
|
|
[first_user, second_user] = insert_pair(:user, confirmation_pending: true)
|
|
|
|
|
|
|
|
assert first_user.confirmation_pending == true
|
|
|
|
assert second_user.confirmation_pending == true
|
|
|
|
|
2019-12-15 14:32:42 -05:00
|
|
|
ret_conn =
|
|
|
|
patch(conn, "/api/pleroma/admin/users/confirm_email", %{
|
|
|
|
nicknames: [
|
|
|
|
first_user.nickname,
|
|
|
|
second_user.nickname
|
|
|
|
]
|
|
|
|
})
|
|
|
|
|
|
|
|
assert ret_conn.status == 200
|
2019-11-19 06:14:02 -05:00
|
|
|
|
|
|
|
assert first_user.confirmation_pending == true
|
|
|
|
assert second_user.confirmation_pending == true
|
|
|
|
|
|
|
|
log_entry = Repo.one(ModerationLog)
|
|
|
|
|
|
|
|
assert ModerationLog.get_log_entry_message(log_entry) ==
|
|
|
|
"@#{admin.nickname} confirmed email for users: @#{first_user.nickname}, @#{
|
|
|
|
second_user.nickname
|
|
|
|
}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "PATCH /resend_confirmation_email" do
|
2019-12-15 14:32:42 -05:00
|
|
|
test "it resend emails for two users", %{conn: conn, admin: admin} do
|
2019-11-19 06:14:02 -05:00
|
|
|
[first_user, second_user] = insert_pair(:user, confirmation_pending: true)
|
|
|
|
|
2019-12-15 14:32:42 -05:00
|
|
|
ret_conn =
|
|
|
|
patch(conn, "/api/pleroma/admin/users/resend_confirmation_email", %{
|
|
|
|
nicknames: [
|
|
|
|
first_user.nickname,
|
|
|
|
second_user.nickname
|
|
|
|
]
|
|
|
|
})
|
|
|
|
|
|
|
|
assert ret_conn.status == 200
|
2019-11-19 06:14:02 -05:00
|
|
|
|
|
|
|
log_entry = Repo.one(ModerationLog)
|
|
|
|
|
|
|
|
assert ModerationLog.get_log_entry_message(log_entry) ==
|
|
|
|
"@#{admin.nickname} re-sent confirmation email for users: @#{first_user.nickname}, @#{
|
|
|
|
second_user.nickname
|
|
|
|
}"
|
2020-07-11 00:20:35 -04:00
|
|
|
|
|
|
|
ObanHelpers.perform_all()
|
|
|
|
assert_email_sent(Pleroma.Emails.UserEmail.account_confirmation_email(first_user))
|
2019-11-19 06:14:02 -05:00
|
|
|
end
|
|
|
|
end
|
2019-12-03 09:54:07 -05:00
|
|
|
|
2020-01-09 14:18:55 -05:00
|
|
|
describe "/api/pleroma/admin/stats" do
|
|
|
|
test "status visibility count", %{conn: conn} do
|
|
|
|
admin = insert(:user, is_admin: true)
|
|
|
|
user = insert(:user)
|
2020-05-12 15:59:26 -04:00
|
|
|
CommonAPI.post(user, %{visibility: "public", status: "hey"})
|
|
|
|
CommonAPI.post(user, %{visibility: "unlisted", status: "hey"})
|
|
|
|
CommonAPI.post(user, %{visibility: "unlisted", status: "hey"})
|
2020-01-09 14:18:55 -05:00
|
|
|
|
|
|
|
response =
|
|
|
|
conn
|
|
|
|
|> assign(:user, admin)
|
|
|
|
|> get("/api/pleroma/admin/stats")
|
|
|
|
|> json_response(200)
|
|
|
|
|
|
|
|
assert %{"direct" => 0, "private" => 0, "public" => 1, "unlisted" => 2} =
|
|
|
|
response["status_visibility"]
|
|
|
|
end
|
2020-06-08 12:21:07 -04:00
|
|
|
|
|
|
|
test "by instance", %{conn: conn} do
|
|
|
|
admin = insert(:user, is_admin: true)
|
|
|
|
user1 = insert(:user)
|
|
|
|
instance2 = "instance2.tld"
|
|
|
|
user2 = insert(:user, %{ap_id: "https://#{instance2}/@actor"})
|
|
|
|
|
|
|
|
CommonAPI.post(user1, %{visibility: "public", status: "hey"})
|
|
|
|
CommonAPI.post(user2, %{visibility: "unlisted", status: "hey"})
|
|
|
|
CommonAPI.post(user2, %{visibility: "private", status: "hey"})
|
|
|
|
|
|
|
|
response =
|
|
|
|
conn
|
|
|
|
|> assign(:user, admin)
|
|
|
|
|> get("/api/pleroma/admin/stats", instance: instance2)
|
|
|
|
|> json_response(200)
|
|
|
|
|
|
|
|
assert %{"direct" => 0, "private" => 1, "public" => 0, "unlisted" => 1} =
|
|
|
|
response["status_visibility"]
|
|
|
|
end
|
2020-01-09 14:18:55 -05:00
|
|
|
end
|
2018-11-17 16:11:18 -05:00
|
|
|
end
|
2019-06-22 10:30:53 -04:00
|
|
|
|
|
|
|
# Needed for testing
|
|
|
|
defmodule Pleroma.Web.Endpoint.NotReal do
|
|
|
|
end
|
|
|
|
|
|
|
|
defmodule Pleroma.Captcha.NotReal do
|
|
|
|
end
|