mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2024-12-22 16:16:34 +00:00
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}"
|
||||
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
|
||||
nicknames
|
||||
|> Enum.map(&"@#{&1}")
|
||||
|
|
|
@ -686,7 +686,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
|
|||
def create_backup(%{assigns: %{user: admin}} = conn, %{"nickname" => nickname}) do
|
||||
with %User{} = user <- User.get_by_nickname(nickname),
|
||||
{: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, "")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2027,9 +2027,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
describe "/api/pleroma/backups" 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)
|
||||
user = insert(:user)
|
||||
user = %{id: user_id, nickname: user_nickname} = insert(:user)
|
||||
|
||||
assert "" ==
|
||||
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_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
|
||||
|
||||
test "it doesn't limit admins", %{conn: conn} do
|
||||
|
|
Loading…
Reference in a new issue