fix oauth scopes for AdminApi#reports_update
authorMaksim Pechnikov <parallel588@gmail.com>
Tue, 24 Dec 2019 17:45:46 +0000 (20:45 +0300)
committerMaksim Pechnikov <parallel588@gmail.com>
Tue, 24 Dec 2019 17:51:52 +0000 (20:51 +0300)
lib/pleroma/web/admin_api/admin_api_controller.ex
test/web/admin_api/admin_api_controller_test.exs

index c8abeff06f922dee857709221b725c2c5f59d460..ddae139c657b9cc9c7c62073da75a3565e3a87d6 100644 (file)
@@ -66,7 +66,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
   plug(
     OAuthScopesPlug,
     %{scopes: ["write:reports"], admin: true}
-    when action in [:report_update_state, :report_respond]
+    when action in [:reports_update]
   )
 
   plug(
index 49ff005b66fe2002f012e4f955c81129a47e93bc..4156ef50daea65f17b7a64b68e03b7d40e6fecf4 100644 (file)
@@ -1418,6 +1418,30 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
       }
     end
 
+    test "requires write:reports scope", %{conn: conn, id: id, admin: admin} do
+      read_token = insert(:oauth_token, user: admin, scopes: ["read"])
+      write_token = insert(:oauth_token, user: admin, scopes: ["write:reports"])
+
+      response =
+        conn
+        |> assign(:token, read_token)
+        |> patch("/api/pleroma/admin/reports", %{
+          "reports" => [%{"state" => "resolved", "id" => id}]
+        })
+        |> json_response(403)
+
+      assert response == %{
+               "error" => "Insufficient permissions: admin:write:reports | write:reports."
+             }
+
+      conn
+      |> assign(:token, write_token)
+      |> patch("/api/pleroma/admin/reports", %{
+        "reports" => [%{"state" => "resolved", "id" => id}]
+      })
+      |> json_response(:no_content)
+    end
+
     test "mark report as resolved", %{conn: conn, id: id, admin: admin} do
       conn
       |> patch("/api/pleroma/admin/reports", %{