diff options
author | Maxim Filippov <colixer@gmail.com> | 2019-10-04 19:00:58 +0300 |
---|---|---|
committer | Maxim Filippov <colixer@gmail.com> | 2019-10-04 19:00:58 +0300 |
commit | 8dcc2f9f5ecbbc81bc026c85582695de4fbc1a0f (patch) | |
tree | cbc478b557f43d05b2df76ab76cbe7549ab16b83 /lib/pleroma/web/admin_api | |
parent | 795ea5dfc2549b50265cea2f7b7a774356a735b4 (diff) | |
download | pleroma-8dcc2f9f5ecbbc81bc026c85582695de4fbc1a0f.tar.gz |
Admin API: Allow changing the state of multiple reports at once
Diffstat (limited to 'lib/pleroma/web/admin_api')
-rw-r--r-- | lib/pleroma/web/admin_api/admin_api_controller.ex | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/lib/pleroma/web/admin_api/admin_api_controller.ex b/lib/pleroma/web/admin_api/admin_api_controller.ex index 21da8a7ff..0e8c9dac8 100644 --- a/lib/pleroma/web/admin_api/admin_api_controller.ex +++ b/lib/pleroma/web/admin_api/admin_api_controller.ex @@ -480,17 +480,26 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do end end - def report_update_state(%{assigns: %{user: admin}} = conn, %{"id" => id, "state" => state}) do - with {:ok, report} <- CommonAPI.update_report_state(id, state) do - ModerationLog.insert_log(%{ - action: "report_update", - actor: admin, - subject: report - }) + def reports_update(%{assigns: %{user: admin}} = conn, %{"reports" => reports}) do + result = + reports + |> Enum.map(fn report -> + with {:ok, activity} <- CommonAPI.update_report_state(report["id"], report["state"]) do + ModerationLog.insert_log(%{ + action: "report_update", + actor: admin, + subject: activity + }) + + activity + else + {:error, message} -> %{id: report["id"], error: message} + end + end) - conn - |> put_view(ReportView) - |> render("show.json", Report.extract_report_info(report)) + case Enum.any?(result, &Map.has_key?(&1, :error)) do + true -> json_response(conn, :bad_request, result) + false -> json_response(conn, :no_content, "") end end |