Use ModerationLog instead of Logger
This commit is contained in:
parent
8545d533dd
commit
bc3db72403
3 changed files with 33 additions and 3 deletions
|
@ -651,6 +651,16 @@ defmodule Pleroma.ModerationLog do
|
||||||
"@#{actor_nickname} deleted chat message ##{subject_id}"
|
"@#{actor_nickname} deleted chat message ##{subject_id}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_log_entry_message(%ModerationLog{
|
||||||
|
data: %{
|
||||||
|
"actor" => %{"nickname" => actor_nickname},
|
||||||
|
"action" => "create_backup",
|
||||||
|
"subject" => %{"nickname" => user_nickname}
|
||||||
|
}
|
||||||
|
}) do
|
||||||
|
"@#{actor_nickname} requested account backup for @#{user_nickname}"
|
||||||
|
end
|
||||||
|
|
||||||
defp nicknames_to_string(nicknames) do
|
defp nicknames_to_string(nicknames) do
|
||||||
nicknames
|
nicknames
|
||||||
|> Enum.map(&"@#{&1}")
|
|> Enum.map(&"@#{&1}")
|
||||||
|
|
|
@ -686,7 +686,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
|
||||||
def create_backup(%{assigns: %{user: admin}} = conn, %{"nickname" => nickname}) do
|
def create_backup(%{assigns: %{user: admin}} = conn, %{"nickname" => nickname}) do
|
||||||
with %User{} = user <- User.get_by_nickname(nickname),
|
with %User{} = user <- User.get_by_nickname(nickname),
|
||||||
{:ok, _} <- Pleroma.Backup.create(user, admin.id) do
|
{:ok, _} <- Pleroma.Backup.create(user, admin.id) do
|
||||||
Logger.info("Admin @#{admin.nickname} requested account backup for @{nickname}")
|
ModerationLog.insert_log(%{actor: admin, subject: user, action: "create_backup"})
|
||||||
|
|
||||||
json(conn, "")
|
json(conn, "")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2027,9 +2027,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
||||||
|
|
||||||
describe "/api/pleroma/backups" do
|
describe "/api/pleroma/backups" do
|
||||||
test "it creates a backup", %{conn: conn} do
|
test "it creates a backup", %{conn: conn} do
|
||||||
admin = insert(:user, is_admin: true)
|
admin = %{id: admin_id, nickname: admin_nickname} = insert(:user, is_admin: true)
|
||||||
token = insert(:oauth_admin_token, user: admin)
|
token = insert(:oauth_admin_token, user: admin)
|
||||||
user = insert(:user)
|
user = %{id: user_id, nickname: user_nickname} = insert(:user)
|
||||||
|
|
||||||
assert "" ==
|
assert "" ==
|
||||||
conn
|
conn
|
||||||
|
@ -2046,6 +2046,25 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
||||||
|
|
||||||
assert String.contains?(email.html_body, "Admin @#{admin.nickname} requested a full backup")
|
assert String.contains?(email.html_body, "Admin @#{admin.nickname} requested a full backup")
|
||||||
assert_email_sent(to: {user.name, user.email}, html_body: email.html_body)
|
assert_email_sent(to: {user.name, user.email}, html_body: email.html_body)
|
||||||
|
|
||||||
|
log_message = "@#{admin_nickname} requested account backup for @#{user_nickname}"
|
||||||
|
|
||||||
|
assert [
|
||||||
|
%{
|
||||||
|
data: %{
|
||||||
|
"action" => "create_backup",
|
||||||
|
"actor" => %{
|
||||||
|
"id" => ^admin_id,
|
||||||
|
"nickname" => ^admin_nickname
|
||||||
|
},
|
||||||
|
"message" => ^log_message,
|
||||||
|
"subject" => %{
|
||||||
|
"id" => ^user_id,
|
||||||
|
"nickname" => ^user_nickname
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
] = Pleroma.ModerationLog |> Repo.all()
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it doesn't limit admins", %{conn: conn} do
|
test "it doesn't limit admins", %{conn: conn} do
|
||||||
|
|
Loading…
Reference in a new issue