From b810aac117563a941b50180f19bca2d96a329a0a Mon Sep 17 00:00:00 2001 From: Alex S Date: Sun, 7 Apr 2019 19:48:52 +0700 Subject: [PATCH] added docs to docs/api/admin_api.md code style and little renamings --- docs/api/admin_api.md | 59 +++++++++++++++++++++-- lib/pleroma/web/admin_api/admin_api_controller.ex | 5 +- lib/pleroma/web/router.ex | 4 +- test/web/admin_api/admin_api_controller_test.exs | 10 ++-- 4 files changed, 65 insertions(+), 13 deletions(-) diff --git a/docs/api/admin_api.md b/docs/api/admin_api.md index 86cacebb1..638b235b8 100644 --- a/docs/api/admin_api.md +++ b/docs/api/admin_api.md @@ -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` diff --git a/lib/pleroma/web/admin_api/admin_api_controller.ex b/lib/pleroma/web/admin_api/admin_api_controller.ex index 8b74efdd3..df729ee02 100644 --- a/lib/pleroma/web/admin_api/admin_api_controller.ex +++ b/lib/pleroma/web/admin_api/admin_api_controller.ex @@ -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 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController 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 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController 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}) diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index f628baa44..b65eaf357 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -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) diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs index ae287a953..67ee0f3fa 100644 --- a/test/web/admin_api/admin_api_controller_test.exs +++ b/test/web/admin_api/admin_api_controller_test.exs @@ -715,14 +715,14 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest 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 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest 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 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest 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 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest 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,