Merge branch 'develop' into feature/report-notes
authorMaxim Filippov <colixer@gmail.com>
Wed, 11 Dec 2019 23:16:23 +0000 (02:16 +0300)
committerMaxim Filippov <colixer@gmail.com>
Wed, 11 Dec 2019 23:16:23 +0000 (02:16 +0300)
1  2 
CHANGELOG.md
docs/API/admin_api.md
lib/pleroma/activity.ex
lib/pleroma/pagination.ex
lib/pleroma/web/activity_pub/activity_pub.ex
lib/pleroma/web/activity_pub/utils.ex
lib/pleroma/web/admin_api/admin_api_controller.ex
lib/pleroma/web/admin_api/views/report_view.ex
lib/pleroma/web/router.ex
test/web/admin_api/admin_api_controller_test.exs

diff --cc CHANGELOG.md
Simple merge
Simple merge
Simple merge
index 183ef770e77c869ba5a8bace9c7e1eccdcfbc4ae,6321c26007582d47c539297921ce5505e2a12a90..4535ca7c5c2b65d3d68b9acf469996ccfec8da51
@@@ -34,11 -37,8 +37,11 @@@ defmodule Pleroma.Pagination d
      |> enforce_order(options)
    end
  
-   def fetch_paginated(query, %{"total" => true} = params, :offset) do
+   def fetch_paginated(query, %{"total" => true} = params, :offset, table_binding) do
 -    total = Repo.aggregate(query, :count, :id)
 +    total =
 +      query
 +      |> Ecto.Query.exclude(:left_join)
 +      |> Repo.aggregate(:count, :id)
  
      %{
        total: total,
Simple merge
Simple merge
index fda47300cc6a257c2a6d1ca7b43e76bd85d1db8f,23ca7f110d1d41c400e13d0708e55407ca6dea26..49ff005b66fe2002f012e4f955c81129a47e93bc
@@@ -1709,8 -1765,127 +1766,72 @@@ defmodule Pleroma.Web.AdminAPI.AdminAPI
        assert Enum.map(third_group["reports"], & &1["id"]) --
                 Enum.map(third_status_reports, & &1.id) == []
      end
+     test "reopened report renders status data", %{
+       conn: conn,
+       first_report: first_report,
+       first_status: first_status
+     } do
+       {:ok, _} = CommonAPI.update_report_state(first_report.id, "resolved")
+       response =
+         conn
+         |> get("/api/pleroma/admin/grouped_reports")
+         |> json_response(:ok)
+       first_group = Enum.find(response["reports"], &(&1["status"]["id"] == first_status.id))
+       assert first_group["status"] ==
+                Map.put(
+                  stringify_keys(StatusView.render("show.json", %{activity: first_status})),
+                  "deleted",
+                  false
+                )
+     end
+     test "reopened report does not render status data if status has been deleted", %{
+       conn: conn,
+       first_report: first_report,
+       first_status: first_status,
+       target_user: target_user
+     } do
+       {:ok, _} = CommonAPI.update_report_state(first_report.id, "resolved")
+       {:ok, _} = CommonAPI.delete(first_status.id, target_user)
+       refute Activity.get_by_ap_id(first_status.id)
+       response =
+         conn
+         |> get("/api/pleroma/admin/grouped_reports")
+         |> json_response(:ok)
+       assert Enum.find(response["reports"], &(&1["status"]["deleted"] == true))["status"][
+                "deleted"
+              ] == true
+       assert length(Enum.filter(response["reports"], &(&1["status"]["deleted"] == false))) == 2
+     end
+     test "account not empty if status was deleted", %{
+       conn: conn,
+       first_report: first_report,
+       first_status: first_status,
+       target_user: target_user
+     } do
+       {:ok, _} = CommonAPI.update_report_state(first_report.id, "resolved")
+       {:ok, _} = CommonAPI.delete(first_status.id, target_user)
+       refute Activity.get_by_ap_id(first_status.id)
+       response =
+         conn
+         |> get("/api/pleroma/admin/grouped_reports")
+         |> json_response(:ok)
+       assert Enum.find(response["reports"], &(&1["status"]["deleted"] == true))["account"]
+     end
    end
  
 -  describe "POST /api/pleroma/admin/reports/:id/respond" do
 -    setup %{conn: conn} do
 -      admin = insert(:user, is_admin: true)
 -
 -      %{conn: assign(conn, :user, admin), admin: admin}
 -    end
 -
 -    test "returns created dm", %{conn: conn, admin: admin} do
 -      [reporter, target_user] = insert_pair(:user)
 -      activity = insert(:note_activity, user: target_user)
 -
 -      {:ok, %{id: report_id}} =
 -        CommonAPI.report(reporter, %{
 -          "account_id" => target_user.id,
 -          "comment" => "I feel offended",
 -          "status_ids" => [activity.id]
 -        })
 -
 -      response =
 -        conn
 -        |> post("/api/pleroma/admin/reports/#{report_id}/respond", %{
 -          "status" => "I will check it out"
 -        })
 -        |> json_response(:ok)
 -
 -      recipients = Enum.map(response["mentions"], & &1["username"])
 -
 -      assert reporter.nickname in recipients
 -      assert response["content"] == "I will check it out"
 -      assert response["visibility"] == "direct"
 -
 -      log_entry = Repo.one(ModerationLog)
 -
 -      assert ModerationLog.get_log_entry_message(log_entry) ==
 -               "@#{admin.nickname} responded with 'I will check it out' to report ##{
 -                 response["id"]
 -               }"
 -    end
 -
 -    test "returns 400 when status is missing", %{conn: conn} do
 -      conn = post(conn, "/api/pleroma/admin/reports/test/respond")
 -
 -      assert json_response(conn, :bad_request) == "Invalid parameters"
 -    end
 -
 -    test "returns 404 when report id is invalid", %{conn: conn} do
 -      conn =
 -        post(conn, "/api/pleroma/admin/reports/test/respond", %{
 -          "status" => "foo"
 -        })
 -
 -      assert json_response(conn, :not_found) == "Not found"
 -    end
 -  end
 -
    describe "PUT /api/pleroma/admin/statuses/:id" do
      setup %{conn: conn} do
        admin = insert(:user, is_admin: true)