Add last priviliges
I still had three endpoints I didn't really know what to do with them. I added them under separate tags * :instance_delete * :moderation_log_read * :stats_read I also checked and these are the last changes done by MR https://git.pleroma.social/pleroma/pleroma/-/merge_requests/3480/diffs this is trying to fix
This commit is contained in:
parent
ecd42a2ce1
commit
c842e62675
3 changed files with 57 additions and 2 deletions
|
@ -155,6 +155,21 @@ defmodule Pleroma.Web.Router do
|
||||||
plug(Pleroma.Web.Plugs.EnsurePrivilegedPlug, :emoji_management)
|
plug(Pleroma.Web.Plugs.EnsurePrivilegedPlug, :emoji_management)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
pipeline :require_privileged_role_instance_delete do
|
||||||
|
plug(:admin_api)
|
||||||
|
plug(Pleroma.Web.Plugs.EnsurePrivilegedPlug, :instance_delete)
|
||||||
|
end
|
||||||
|
|
||||||
|
pipeline :require_privileged_role_moderation_log_read do
|
||||||
|
plug(:admin_api)
|
||||||
|
plug(Pleroma.Web.Plugs.EnsurePrivilegedPlug, :moderation_log_read)
|
||||||
|
end
|
||||||
|
|
||||||
|
pipeline :require_privileged_role_stats_read do
|
||||||
|
plug(:admin_api)
|
||||||
|
plug(Pleroma.Web.Plugs.EnsurePrivilegedPlug, :stats_read)
|
||||||
|
end
|
||||||
|
|
||||||
pipeline :pleroma_html do
|
pipeline :pleroma_html do
|
||||||
plug(:browser)
|
plug(:browser)
|
||||||
plug(:authenticate)
|
plug(:authenticate)
|
||||||
|
@ -372,13 +387,23 @@ defmodule Pleroma.Web.Router do
|
||||||
post("/reload_emoji", AdminAPIController, :reload_emoji)
|
post("/reload_emoji", AdminAPIController, :reload_emoji)
|
||||||
end
|
end
|
||||||
|
|
||||||
# AdminAPI: admins and mods (staff) can perform these actions
|
# AdminAPI: admins and mods (staff) can perform these actions (if privileged by role)
|
||||||
scope "/api/v1/pleroma/admin", Pleroma.Web.AdminAPI do
|
scope "/api/v1/pleroma/admin", Pleroma.Web.AdminAPI do
|
||||||
pipe_through(:admin_api)
|
pipe_through(:require_privileged_role_instance_delete)
|
||||||
|
|
||||||
delete("/instances/:instance", InstanceController, :delete)
|
delete("/instances/:instance", InstanceController, :delete)
|
||||||
|
end
|
||||||
|
|
||||||
|
# AdminAPI: admins and mods (staff) can perform these actions (if privileged by role)
|
||||||
|
scope "/api/v1/pleroma/admin", Pleroma.Web.AdminAPI do
|
||||||
|
pipe_through(:require_privileged_role_moderation_log_read)
|
||||||
|
|
||||||
get("/moderation_log", AdminAPIController, :list_log)
|
get("/moderation_log", AdminAPIController, :list_log)
|
||||||
|
end
|
||||||
|
|
||||||
|
# AdminAPI: admins and mods (staff) can perform these actions (if privileged by role)
|
||||||
|
scope "/api/v1/pleroma/admin", Pleroma.Web.AdminAPI do
|
||||||
|
pipe_through(:require_privileged_role_stats_read)
|
||||||
|
|
||||||
get("/stats", AdminAPIController, :stats)
|
get("/stats", AdminAPIController, :stats)
|
||||||
end
|
end
|
||||||
|
|
|
@ -558,6 +558,7 @@ test "returns 403", %{conn: conn, user: user} do
|
||||||
|
|
||||||
describe "GET /api/pleroma/admin/moderation_log" do
|
describe "GET /api/pleroma/admin/moderation_log" do
|
||||||
setup do
|
setup do
|
||||||
|
clear_config([:instance, :admin_privileges], [:moderation_log_read])
|
||||||
moderator = insert(:user, is_moderator: true)
|
moderator = insert(:user, is_moderator: true)
|
||||||
|
|
||||||
%{moderator: moderator}
|
%{moderator: moderator}
|
||||||
|
@ -762,6 +763,15 @@ test "returns log filtered by search", %{conn: conn, moderator: moderator} do
|
||||||
assert get_in(first_entry, ["data", "message"]) ==
|
assert get_in(first_entry, ["data", "message"]) ==
|
||||||
"@#{moderator.nickname} unfollowed relay: https://example.org/relay"
|
"@#{moderator.nickname} unfollowed relay: https://example.org/relay"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "it requires privileged role :moderation_log_read", %{conn: conn} do
|
||||||
|
clear_config([:instance, :admin_privileges], [])
|
||||||
|
|
||||||
|
assert conn
|
||||||
|
|> put_req_header("content-type", "multipart/form-data")
|
||||||
|
|> get("/api/pleroma/admin/moderation_log")
|
||||||
|
|> json_response(:forbidden)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test "gets a remote users when [:instance, :limit_to_local_content] is set to :unauthenticated",
|
test "gets a remote users when [:instance, :limit_to_local_content] is set to :unauthenticated",
|
||||||
|
@ -960,6 +970,10 @@ test "it resend emails for two users", %{conn: conn, admin: admin} do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "/api/pleroma/admin/stats" do
|
describe "/api/pleroma/admin/stats" do
|
||||||
|
setup do
|
||||||
|
clear_config([:instance, :admin_privileges], [:stats_read])
|
||||||
|
end
|
||||||
|
|
||||||
test "status visibility count", %{conn: conn} do
|
test "status visibility count", %{conn: conn} do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
CommonAPI.post(user, %{visibility: "public", status: "hey"})
|
CommonAPI.post(user, %{visibility: "public", status: "hey"})
|
||||||
|
@ -992,6 +1006,14 @@ test "by instance", %{conn: conn} do
|
||||||
assert %{"direct" => 0, "private" => 1, "public" => 0, "unlisted" => 1} =
|
assert %{"direct" => 0, "private" => 1, "public" => 0, "unlisted" => 1} =
|
||||||
response["status_visibility"]
|
response["status_visibility"]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "it requires privileged role :stats_read", %{conn: conn} do
|
||||||
|
clear_config([:instance, :admin_privileges], [])
|
||||||
|
|
||||||
|
assert conn
|
||||||
|
|> get("/api/pleroma/admin/stats", instance: "lain.wired")
|
||||||
|
|> json_response(:forbidden)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "/api/pleroma/backups" do
|
describe "/api/pleroma/backups" do
|
||||||
|
|
|
@ -68,6 +68,7 @@ test "GET /instances/:instance/statuses", %{conn: conn} do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "DELETE /instances/:instance", %{conn: conn} do
|
test "DELETE /instances/:instance", %{conn: conn} do
|
||||||
|
clear_config([:instance, :admin_privileges], [:instance_delete])
|
||||||
user = insert(:user, nickname: "lain@lain.com")
|
user = insert(:user, nickname: "lain@lain.com")
|
||||||
post = insert(:note_activity, user: user)
|
post = insert(:note_activity, user: user)
|
||||||
|
|
||||||
|
@ -81,5 +82,12 @@ test "DELETE /instances/:instance", %{conn: conn} do
|
||||||
assert response == "lain.com"
|
assert response == "lain.com"
|
||||||
refute Repo.reload(user).is_active
|
refute Repo.reload(user).is_active
|
||||||
refute Repo.reload(post)
|
refute Repo.reload(post)
|
||||||
|
|
||||||
|
clear_config([:instance, :admin_privileges], [])
|
||||||
|
|
||||||
|
response =
|
||||||
|
conn
|
||||||
|
|> delete("/api/pleroma/admin/instances/lain.com")
|
||||||
|
|> json_response(:forbidden)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue