added docs to docs/api/admin_api.md

code style and little renamings
This commit is contained in:
Alex S 2019-04-07 19:48:52 +07:00
parent ce8d457132
commit b810aac117
4 changed files with 65 additions and 13 deletions

View file

@ -200,11 +200,64 @@ Note: Available `:permission_group` is currently moderator and admin. 404 is ret
## `/api/pleroma/admin/invite_token`
### Get a account registeration invite token
### Get an account registration invite token
- Methods: `GET`
- Params:
- *optional* `invite` => [
- *optional* `max_use` (integer)
- *optional* `expire_at` (date string e.g. "2019-04-07")
]
- Response: invite token (base64 string)
## `/api/pleroma/admin/invites`
### Get a list of generated invites
- Methods: `GET`
- Params: none
- Response: invite token (base64 string)
- Response:
```JSON
{
"invites": [
{
"id": integer,
"token": string,
"used": boolean,
"expire_at": date,
"uses": integer,
"max_use": integer,
"invite_type": string (possible values: `one_time`, `reusable`, `date_limited`, `reusable_date_limited`)
},
...
]
}
```
## `/api/pleroma/admin/revoke_invite`
### Revoke invite by token
- Methods: `POST`
- Params:
- `token`
- Response:
```JSON
{
"id": integer,
"token": string,
"used": boolean,
"expire_at": date,
"uses": integer,
"max_use": integer,
"invite_type": string (possible values: `one_time`, `reusable`, `date_limited`, `reusable_date_limited`)
}
```
## `/api/pleroma/admin/email_invite`
@ -213,7 +266,7 @@ Note: Available `:permission_group` is currently moderator and admin. 404 is ret
- Methods: `POST`
- Params:
- `email`
- `name`, optionnal
- `name`, optional
## `/api/pleroma/admin/password_reset`

View file

@ -8,7 +8,6 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
alias Pleroma.Web.ActivityPub.Relay
alias Pleroma.Web.AdminAPI.AccountView
alias Pleroma.Web.AdminAPI.Search
alias Pleroma.UserInviteToken
import Pleroma.Web.ControllerHelper, only: [json_response: 3]
@ -255,7 +254,7 @@ def get_invite_token(conn, params) do
end
@doc "Get list of created invites"
def invites_list(conn, _params) do
def invites(conn, _params) do
invites = UserInviteToken.list_invites()
conn
@ -263,7 +262,7 @@ def invites_list(conn, _params) do
end
@doc "Revokes invite by token"
def invite_revoke(conn, %{"token" => token}) do
def revoke_invite(conn, %{"token" => token}) do
invite = UserInviteToken.find_by_token!(token)
{:ok, updated_invite} = UserInviteToken.update_invite(invite, %{used: true})

View file

@ -163,8 +163,8 @@ defmodule Pleroma.Web.Router do
delete("/relay", AdminAPIController, :relay_unfollow)
get("/invite_token", AdminAPIController, :get_invite_token)
get("/invites_list", AdminAPIController, :invites_list)
post("/invite_revoke", AdminAPIController, :invite_revoke)
get("/invites", AdminAPIController, :invites)
post("/revoke_invite", AdminAPIController, :revoke_invite)
post("/email_invite", AdminAPIController, :email_invite)
get("/password_reset", AdminAPIController, :get_password_reset)

View file

@ -715,14 +715,14 @@ test "with max use and expire_at" do
end
end
describe "GET /api/pleroma/admin/invites_list" do
describe "GET /api/pleroma/admin/invites" do
test "no invites" do
admin = insert(:user, info: %{is_admin: true})
conn =
build_conn()
|> assign(:user, admin)
|> get("/api/pleroma/admin/invites_list")
|> get("/api/pleroma/admin/invites")
assert json_response(conn, 200) == %{"invites" => []}
end
@ -734,7 +734,7 @@ test "with invite" do
conn =
build_conn()
|> assign(:user, admin)
|> get("/api/pleroma/admin/invites_list")
|> get("/api/pleroma/admin/invites")
assert json_response(conn, 200) == %{
"invites" => [
@ -752,7 +752,7 @@ test "with invite" do
end
end
describe "POST /api/pleroma/admin/invite_revoke" do
describe "POST /api/pleroma/admin/revoke_invite" do
test "with token" do
admin = insert(:user, info: %{is_admin: true})
{:ok, invite} = UserInviteToken.create_invite()
@ -760,7 +760,7 @@ test "with token" do
conn =
build_conn()
|> assign(:user, admin)
|> post("/api/pleroma/admin/invite_revoke", %{"token" => invite.token})
|> post("/api/pleroma/admin/revoke_invite", %{"token" => invite.token})
assert json_response(conn, 200) == %{
"expire_at" => nil,