aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkaniini <nenolod@gmail.com>2019-02-27 07:28:10 +0000
committerkaniini <nenolod@gmail.com>2019-02-27 07:28:10 +0000
commita50a47a0114dab06205eabf5bd42369328ce80e2 (patch)
tree46dba92587e9a217c2b9f1cb4729ec97b484e54c
parent1c265b3b19bacd2e0a9ccfee0f7e53a59d83a621 (diff)
parented7fd6b47e93e0874e3d79f124b71693e43dbb2c (diff)
downloadpleroma-a50a47a0114dab06205eabf5bd42369328ce80e2.tar.gz
Merge branch 'chore/add-missing-tests-docs-to-admin-api' into 'develop'
Add missing docs and tests to Admin API See merge request pleroma/pleroma!868
-rw-r--r--docs/Admin-API.md191
-rw-r--r--test/web/admin_api/admin_api_controller_test.exs35
2 files changed, 163 insertions, 63 deletions
diff --git a/docs/Admin-API.md b/docs/Admin-API.md
index 016444d58..508981d38 100644
--- a/docs/Admin-API.md
+++ b/docs/Admin-API.md
@@ -1,108 +1,173 @@
# Admin API
+
Authentication is required and the user must be an admin.
+## `/api/pleroma/admin/users`
+
+### List users
+
+- Method `GET`
+- Response:
+
+```JSON
+[
+ {
+ "deactivated": bool,
+ "id": integer,
+ "nickname": string
+ },
+ ...
+]
+```
+
## `/api/pleroma/admin/user`
+
### Remove a user
-* Method `DELETE`
-* Params:
- * `nickname`
-* Response: User’s nickname
+
+- Method `DELETE`
+- Params:
+ - `nickname`
+- Response: User’s nickname
+
### Create a user
-* Method: `POST`
-* Params:
- * `nickname`
- * `email`
- * `password`
-* Response: User’s nickname
+
+- Method: `POST`
+- Params:
+ - `nickname`
+ - `email`
+ - `password`
+- Response: User’s nickname
+
+## `/api/pleroma/admin/users/:nickname/toggle_activation`
+
+### Toggle user activation
+
+- Method: `PATCH`
+- Params:
+ - `nickname`
+- Response: User’s object
+
+```JSON
+{
+ "deactivated": bool,
+ "id": integer,
+ "nickname": string
+}
+```
## `/api/pleroma/admin/users/tag`
+
### Tag a list of users
-* Method: `PUT`
-* Params:
- * `nickname`
- * `tags`
+
+- Method: `PUT`
+- Params:
+ - `nickname`
+ - `tags`
+
### Untag a list of users
-* Method: `DELETE`
-* Params:
- * `nickname`
- * `tags`
+
+- Method: `DELETE`
+- Params:
+ - `nickname`
+ - `tags`
## `/api/pleroma/admin/permission_group/:nickname`
+
### Get user user permission groups membership
-* Method: `GET`
-* Params: none
-* Response:
+
+- Method: `GET`
+- Params: none
+- Response:
+
```JSON
{
- "is_moderator": bool,
- "is_admin": bool
+ "is_moderator": bool,
+ "is_admin": bool
}
```
## `/api/pleroma/admin/permission_group/:nickname/:permission_group`
+
Note: Available `:permission_group` is currently moderator and admin. 404 is returned when the permission group doesn’t exist.
### Get user user permission groups membership
-* Method: `GET`
-* Params: none
-* Response:
+
+- Method: `GET`
+- Params: none
+- Response:
+
```JSON
{
- "is_moderator": bool,
- "is_admin": bool
+ "is_moderator": bool,
+ "is_admin": bool
}
```
+
### Add user in permission group
-* Method: `POST`
-* Params: none
-* Response:
- * On failure: ``{"error": "…"}``
- * On success: JSON of the ``user.info``
+
+- Method: `POST`
+- Params: none
+- Response:
+ - On failure: `{"error": "…"}`
+ - On success: JSON of the `user.info`
+
### Remove user from permission group
-* Method: `DELETE`
-* Params: none
-* Response:
- * On failure: ``{"error": "…"}``
- * On success: JSON of the ``user.info``
-* Note: An admin cannot revoke their own admin status.
+
+- Method: `DELETE`
+- Params: none
+- Response:
+ - On failure: `{"error": "…"}`
+ - On success: JSON of the `user.info`
+- Note: An admin cannot revoke their own admin status.
## `/api/pleroma/admin/activation_status/:nickname`
### Active or deactivate a user
-* Method: `PUT`
-* Params:
- * `nickname`
- * `status` BOOLEAN field, false value means deactivation.
+
+- Method: `PUT`
+- Params:
+ - `nickname`
+ - `status` BOOLEAN field, false value means deactivation.
## `/api/pleroma/admin/relay`
+
### Follow a Relay
-* Methods: `POST`
-* Params:
- * `relay_url`
-* Response:
- * On success: URL of the followed relay
+
+- Methods: `POST`
+- Params:
+ - `relay_url`
+- Response:
+ - On success: URL of the followed relay
+
### Unfollow a Relay
-* Methods: `DELETE`
-* Params:
- * `relay_url`
-* Response:
- * On success: URL of the unfollowed relay
+
+- Methods: `DELETE`
+- Params:
+ - `relay_url`
+- Response:
+ - On success: URL of the unfollowed relay
## `/api/pleroma/admin/invite_token`
+
### Get a account registeration invite token
-* Methods: `GET`
-* Params: none
-* Response: invite token (base64 string)
+
+- Methods: `GET`
+- Params: none
+- Response: invite token (base64 string)
## `/api/pleroma/admin/email_invite`
+
### Sends registration invite via email
-* Methods: `POST`
-* Params:
- * `email`
- * `name`, optionnal
+
+- Methods: `POST`
+- Params:
+ - `email`
+ - `name`, optionnal
## `/api/pleroma/admin/password_reset`
+
### Get a password reset token for a given nickname
-* Methods: `GET`
-* Params: none
-* Response: password reset token (base64 string)
+
+- Methods: `GET`
+- Params: none
+- Response: password reset token (base64 string)
diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs
index 9fbaaba39..f6ae16844 100644
--- a/test/web/admin_api/admin_api_controller_test.exs
+++ b/test/web/admin_api/admin_api_controller_test.exs
@@ -330,4 +330,39 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
assert conn.status == 200
end
+
+ test "GET /api/pleroma/admin/users" do
+ admin = insert(:user, info: %{is_admin: true})
+ user = insert(:user)
+
+ conn =
+ build_conn()
+ |> assign(:user, admin)
+ |> get("/api/pleroma/admin/users")
+
+ assert json_response(conn, 200) == [
+ %{
+ "deactivated" => user.info.deactivated,
+ "id" => user.id,
+ "nickname" => user.nickname
+ }
+ ]
+ end
+
+ test "PATCH /api/pleroma/admin/users/:nickname/toggle_activation" do
+ admin = insert(:user, info: %{is_admin: true})
+ user = insert(:user)
+
+ conn =
+ build_conn()
+ |> assign(:user, admin)
+ |> patch("/api/pleroma/admin/users/#{user.nickname}/toggle_activation")
+
+ assert json_response(conn, 200) ==
+ %{
+ "deactivated" => !user.info.deactivated,
+ "id" => user.id,
+ "nickname" => user.nickname
+ }
+ end
end