Verified Commit 54dbcfe0 authored by Alex Gleason's avatar Alex Gleason
Browse files

AdminAPI: add DELETE /instances/:instance to delete all content from a remote instance

parent f67d00d1
......@@ -319,6 +319,22 @@ Note: Available `:permission_group` is currently moderator and admin. 404 is ret
}
```
## `DELETE /api/v1/pleroma/admin/instances/:instance`
### Delete all users and activities from a remote instance
Note: this will trigger a job to remove instance content in the background.
It may take some time.
- Params:
- `instance`: remote instance host
- Response:
- The `instance` name as a string
```json
"lain.com"
```
## `GET /api/v1/pleroma/admin/statuses`
### Retrives all latest statuses
......
......@@ -7,6 +7,7 @@ defmodule Pleroma.Web.AdminAPI.InstanceController do
import Pleroma.Web.ControllerHelper, only: [fetch_integer_param: 3]
alias Pleroma.Instances.Instance
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.AdminAPI
alias Pleroma.Web.Plugs.OAuthScopesPlug
......@@ -21,6 +22,12 @@ defmodule Pleroma.Web.AdminAPI.InstanceController do
when action in [:list_instance_statuses]
)
plug(
OAuthScopesPlug,
%{scopes: ["admin:write:accounts", "admin:write:statuses"]}
when action in [:delete_instance]
)
action_fallback(AdminAPI.FallbackController)
def list_instance_statuses(conn, %{"instance" => instance} = params) do
......@@ -41,6 +48,12 @@ def list_instance_statuses(conn, %{"instance" => instance} = params) do
|> render("index.json", %{total: result[:total], activities: result[:items], as: :activity})
end
def delete_instance(conn, %{"instance" => instance}) do
with {:ok, _job} <- Instance.delete_users_and_activities(instance) do
json(conn, instance)
end
end
defp page_params(params) do
{
fetch_integer_param(params, "page", 1),
......
......@@ -210,6 +210,7 @@ defmodule Pleroma.Web.Router do
get("/users/:nickname/chats", AdminAPIController, :list_user_chats)
get("/instances/:instance/statuses", InstanceController, :list_instance_statuses)
delete("/instances/:instance", InstanceController, :delete_instance)
get("/instance_document/:name", InstanceDocumentController, :show)
patch("/instance_document/:name", InstanceDocumentController, :update)
......
......@@ -8,6 +8,8 @@ defmodule Pleroma.Web.AdminAPI.InstanceControllerTest do
import Pleroma.Factory
alias Pleroma.Repo
alias Pleroma.Tests.ObanHelpers
alias Pleroma.Web.CommonAPI
setup_all do
......@@ -61,4 +63,20 @@ test "GET /instances/:instance/statuses", %{conn: conn} do
assert length(activities) == 3
end
end
test "DELETE /instances/:instance", %{conn: conn} do
user = insert(:user, nickname: "lain@lain.com")
post = insert(:note_activity, user: user)
response =
conn
|> delete("/api/pleroma/admin/instances/lain.com")
|> json_response(200)
[:ok] = ObanHelpers.perform_all()
assert response == "lain.com"
refute Repo.reload(user).is_active
refute Repo.reload(post)
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment