"@#{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}")
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
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
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