logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma
commit: c814f22030c1341ec337bdd1c446536597e683e2
parent: e8759cb5baba85709607b167d27bd54cf4822366
Author: lain <lain@soykaf.club>
Date:   Mon, 20 Jan 2020 12:07:12 +0000

Merge branch 'fix-admin-api-scope' into 'develop'

fix oauth scopes for AdminApi#reports_update

See merge request pleroma/pleroma!2087

Diffstat:

Mlib/pleroma/web/admin_api/admin_api_controller.ex2+-
Mtest/web/admin_api/admin_api_controller_test.exs24++++++++++++++++++++++++
2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/lib/pleroma/web/admin_api/admin_api_controller.ex b/lib/pleroma/web/admin_api/admin_api_controller.ex @@ -75,7 +75,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( diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs @@ -1363,6 +1363,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", %{