forked from AkkomaGang/akkoma
Merge branch 'uniform-admin-api-url' into 'develop'
make user related url uniform in admin api See merge request pleroma/pleroma!1135
This commit is contained in:
commit
1cb7a15727
3 changed files with 74 additions and 54 deletions
|
@ -45,7 +45,7 @@ Authentication is required and the user must be an admin.
|
|||
}
|
||||
```
|
||||
|
||||
## `/api/pleroma/admin/user`
|
||||
## `/api/pleroma/admin/users`
|
||||
|
||||
### Remove a user
|
||||
|
||||
|
@ -63,7 +63,7 @@ Authentication is required and the user must be an admin.
|
|||
- `password`
|
||||
- Response: User’s nickname
|
||||
|
||||
## `/api/pleroma/admin/user/follow`
|
||||
## `/api/pleroma/admin/users/follow`
|
||||
### Make a user follow another user
|
||||
|
||||
- Methods: `POST`
|
||||
|
@ -73,7 +73,7 @@ Authentication is required and the user must be an admin.
|
|||
- Response:
|
||||
- "ok"
|
||||
|
||||
## `/api/pleroma/admin/user/unfollow`
|
||||
## `/api/pleroma/admin/users/unfollow`
|
||||
### Make a user unfollow another user
|
||||
|
||||
- Methods: `POST`
|
||||
|
@ -116,7 +116,7 @@ Authentication is required and the user must be an admin.
|
|||
- `nickname`
|
||||
- `tags`
|
||||
|
||||
## `/api/pleroma/admin/permission_group/:nickname`
|
||||
## `/api/pleroma/admin/users/:nickname/permission_group`
|
||||
|
||||
### Get user user permission groups membership
|
||||
|
||||
|
@ -131,7 +131,7 @@ Authentication is required and the user must be an admin.
|
|||
}
|
||||
```
|
||||
|
||||
## `/api/pleroma/admin/permission_group/:nickname/:permission_group`
|
||||
## `/api/pleroma/admin/users/:nickname/permission_group/:permission_group`
|
||||
|
||||
Note: Available `:permission_group` is currently moderator and admin. 404 is returned when the permission group doesn’t exist.
|
||||
|
||||
|
@ -165,7 +165,7 @@ Note: Available `:permission_group` is currently moderator and admin. 404 is ret
|
|||
- On success: JSON of the `user.info`
|
||||
- Note: An admin cannot revoke their own admin status.
|
||||
|
||||
## `/api/pleroma/admin/activation_status/:nickname`
|
||||
## `/api/pleroma/admin/users/:nickname/activation_status`
|
||||
|
||||
### Active or deactivate a user
|
||||
|
||||
|
@ -203,7 +203,7 @@ Note: Available `:permission_group` is currently moderator and admin. 404 is ret
|
|||
- Response:
|
||||
- On success: URL of the unfollowed relay
|
||||
|
||||
## `/api/pleroma/admin/invite_token`
|
||||
## `/api/pleroma/admin/users/invite_token`
|
||||
|
||||
### Get an account registration invite token
|
||||
|
||||
|
@ -215,7 +215,7 @@ Note: Available `:permission_group` is currently moderator and admin. 404 is ret
|
|||
]
|
||||
- Response: invite token (base64 string)
|
||||
|
||||
## `/api/pleroma/admin/invites`
|
||||
## `/api/pleroma/admin/users/invites`
|
||||
|
||||
### Get a list of generated invites
|
||||
|
||||
|
@ -241,7 +241,7 @@ Note: Available `:permission_group` is currently moderator and admin. 404 is ret
|
|||
}
|
||||
```
|
||||
|
||||
## `/api/pleroma/admin/revoke_invite`
|
||||
## `/api/pleroma/admin/users/revoke_invite`
|
||||
|
||||
### Revoke invite by token
|
||||
|
||||
|
@ -264,7 +264,7 @@ Note: Available `:permission_group` is currently moderator and admin. 404 is ret
|
|||
```
|
||||
|
||||
|
||||
## `/api/pleroma/admin/email_invite`
|
||||
## `/api/pleroma/admin/users/email_invite`
|
||||
|
||||
### Sends registration invite via email
|
||||
|
||||
|
@ -273,7 +273,7 @@ Note: Available `:permission_group` is currently moderator and admin. 404 is ret
|
|||
- `email`
|
||||
- `name`, optional
|
||||
|
||||
## `/api/pleroma/admin/password_reset`
|
||||
## `/api/pleroma/admin/users/:nickname/password_reset`
|
||||
|
||||
### Get a password reset token for a given nickname
|
||||
|
||||
|
|
|
@ -146,34 +146,52 @@ defmodule Pleroma.Web.Router do
|
|||
scope "/api/pleroma/admin", Pleroma.Web.AdminAPI do
|
||||
pipe_through([:admin_api, :oauth_write])
|
||||
|
||||
post("/user/follow", AdminAPIController, :user_follow)
|
||||
post("/user/unfollow", AdminAPIController, :user_unfollow)
|
||||
|
||||
get("/users", AdminAPIController, :list_users)
|
||||
get("/users/:nickname", AdminAPIController, :user_show)
|
||||
post("/users/follow", AdminAPIController, :user_follow)
|
||||
post("/users/unfollow", AdminAPIController, :user_unfollow)
|
||||
|
||||
# TODO: to be removed at version 1.0
|
||||
delete("/user", AdminAPIController, :user_delete)
|
||||
patch("/users/:nickname/toggle_activation", AdminAPIController, :user_toggle_activation)
|
||||
post("/user", AdminAPIController, :user_create)
|
||||
|
||||
delete("/users", AdminAPIController, :user_delete)
|
||||
post("/users", AdminAPIController, :user_create)
|
||||
patch("/users/:nickname/toggle_activation", AdminAPIController, :user_toggle_activation)
|
||||
put("/users/tag", AdminAPIController, :tag_users)
|
||||
delete("/users/tag", AdminAPIController, :untag_users)
|
||||
|
||||
# TODO: to be removed at version 1.0
|
||||
get("/permission_group/:nickname", AdminAPIController, :right_get)
|
||||
get("/permission_group/:nickname/:permission_group", AdminAPIController, :right_get)
|
||||
post("/permission_group/:nickname/:permission_group", AdminAPIController, :right_add)
|
||||
delete("/permission_group/:nickname/:permission_group", AdminAPIController, :right_delete)
|
||||
|
||||
put("/activation_status/:nickname", AdminAPIController, :set_activation_status)
|
||||
get("/users/:nickname/permission_group", AdminAPIController, :right_get)
|
||||
get("/users/:nickname/permission_group/:permission_group", AdminAPIController, :right_get)
|
||||
post("/users/:nickname/permission_group/:permission_group", AdminAPIController, :right_add)
|
||||
|
||||
delete(
|
||||
"/users/:nickname/permission_group/:permission_group",
|
||||
AdminAPIController,
|
||||
:right_delete
|
||||
)
|
||||
|
||||
put("/users/:nickname/activation_status", AdminAPIController, :set_activation_status)
|
||||
|
||||
post("/relay", AdminAPIController, :relay_follow)
|
||||
delete("/relay", AdminAPIController, :relay_unfollow)
|
||||
|
||||
get("/invite_token", AdminAPIController, :get_invite_token)
|
||||
get("/invites", AdminAPIController, :invites)
|
||||
post("/revoke_invite", AdminAPIController, :revoke_invite)
|
||||
post("/email_invite", AdminAPIController, :email_invite)
|
||||
get("/users/invite_token", AdminAPIController, :get_invite_token)
|
||||
get("/users/invites", AdminAPIController, :invites)
|
||||
post("/users/revoke_invite", AdminAPIController, :revoke_invite)
|
||||
post("/users/email_invite", AdminAPIController, :email_invite)
|
||||
|
||||
# TODO: to be removed at version 1.0
|
||||
get("/password_reset", AdminAPIController, :get_password_reset)
|
||||
|
||||
get("/users/:nickname/password_reset", AdminAPIController, :get_password_reset)
|
||||
|
||||
get("/users", AdminAPIController, :list_users)
|
||||
get("/users/:nickname", AdminAPIController, :user_show)
|
||||
end
|
||||
|
||||
scope "/", Pleroma.Web.TwitterAPI do
|
||||
|
|
|
@ -9,7 +9,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
alias Pleroma.UserInviteToken
|
||||
import Pleroma.Factory
|
||||
|
||||
describe "/api/pleroma/admin/user" do
|
||||
describe "/api/pleroma/admin/users" do
|
||||
test "Delete" do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
user = insert(:user)
|
||||
|
@ -18,7 +18,7 @@ test "Delete" do
|
|||
build_conn()
|
||||
|> assign(:user, admin)
|
||||
|> put_req_header("accept", "application/json")
|
||||
|> delete("/api/pleroma/admin/user?nickname=#{user.nickname}")
|
||||
|> delete("/api/pleroma/admin/users?nickname=#{user.nickname}")
|
||||
|
||||
assert json_response(conn, 200) == user.nickname
|
||||
end
|
||||
|
@ -30,7 +30,7 @@ test "Create" do
|
|||
build_conn()
|
||||
|> assign(:user, admin)
|
||||
|> put_req_header("accept", "application/json")
|
||||
|> post("/api/pleroma/admin/user", %{
|
||||
|> post("/api/pleroma/admin/users", %{
|
||||
"nickname" => "lain",
|
||||
"email" => "lain@example.org",
|
||||
"password" => "test"
|
||||
|
@ -75,7 +75,7 @@ test "when the user doesn't exist", %{conn: conn} do
|
|||
end
|
||||
end
|
||||
|
||||
describe "/api/pleroma/admin/user/follow" do
|
||||
describe "/api/pleroma/admin/users/follow" do
|
||||
test "allows to force-follow another user" do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
user = insert(:user)
|
||||
|
@ -84,7 +84,7 @@ test "allows to force-follow another user" do
|
|||
build_conn()
|
||||
|> assign(:user, admin)
|
||||
|> put_req_header("accept", "application/json")
|
||||
|> post("/api/pleroma/admin/user/follow", %{
|
||||
|> post("/api/pleroma/admin/users/follow", %{
|
||||
"follower" => follower.nickname,
|
||||
"followed" => user.nickname
|
||||
})
|
||||
|
@ -96,7 +96,7 @@ test "allows to force-follow another user" do
|
|||
end
|
||||
end
|
||||
|
||||
describe "/api/pleroma/admin/user/unfollow" do
|
||||
describe "/api/pleroma/admin/users/unfollow" do
|
||||
test "allows to force-unfollow another user" do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
user = insert(:user)
|
||||
|
@ -107,7 +107,7 @@ test "allows to force-unfollow another user" do
|
|||
build_conn()
|
||||
|> assign(:user, admin)
|
||||
|> put_req_header("accept", "application/json")
|
||||
|> post("/api/pleroma/admin/user/unfollow", %{
|
||||
|> post("/api/pleroma/admin/users/unfollow", %{
|
||||
"follower" => follower.nickname,
|
||||
"followed" => user.nickname
|
||||
})
|
||||
|
@ -191,7 +191,7 @@ test "it does not modify tags of not specified users", %{conn: conn, user3: user
|
|||
end
|
||||
end
|
||||
|
||||
describe "/api/pleroma/admin/permission_group" do
|
||||
describe "/api/pleroma/admin/users/:nickname/permission_group" do
|
||||
test "GET is giving user_info" do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
|
||||
|
@ -199,7 +199,7 @@ test "GET is giving user_info" do
|
|||
build_conn()
|
||||
|> assign(:user, admin)
|
||||
|> put_req_header("accept", "application/json")
|
||||
|> get("/api/pleroma/admin/permission_group/#{admin.nickname}")
|
||||
|> get("/api/pleroma/admin/users/#{admin.nickname}/permission_group/")
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
"is_admin" => true,
|
||||
|
@ -215,7 +215,7 @@ test "/:right POST, can add to a permission group" do
|
|||
build_conn()
|
||||
|> assign(:user, admin)
|
||||
|> put_req_header("accept", "application/json")
|
||||
|> post("/api/pleroma/admin/permission_group/#{user.nickname}/admin")
|
||||
|> post("/api/pleroma/admin/users/#{user.nickname}/permission_group/admin")
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
"is_admin" => true
|
||||
|
@ -230,7 +230,7 @@ test "/:right DELETE, can remove from a permission group" do
|
|||
build_conn()
|
||||
|> assign(:user, admin)
|
||||
|> put_req_header("accept", "application/json")
|
||||
|> delete("/api/pleroma/admin/permission_group/#{user.nickname}/admin")
|
||||
|> delete("/api/pleroma/admin/users/#{user.nickname}/permission_group/admin")
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
"is_admin" => false
|
||||
|
@ -238,7 +238,7 @@ test "/:right DELETE, can remove from a permission group" do
|
|||
end
|
||||
end
|
||||
|
||||
describe "PUT /api/pleroma/admin/activation_status" do
|
||||
describe "PUT /api/pleroma/admin/users/:nickname/activation_status" do
|
||||
setup %{conn: conn} do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
|
||||
|
@ -255,7 +255,7 @@ test "deactivates the user", %{conn: conn} do
|
|||
|
||||
conn =
|
||||
conn
|
||||
|> put("/api/pleroma/admin/activation_status/#{user.nickname}", %{status: false})
|
||||
|> put("/api/pleroma/admin/users/#{user.nickname}/activation_status", %{status: false})
|
||||
|
||||
user = User.get_cached_by_id(user.id)
|
||||
assert user.info.deactivated == true
|
||||
|
@ -267,7 +267,7 @@ test "activates the user", %{conn: conn} do
|
|||
|
||||
conn =
|
||||
conn
|
||||
|> put("/api/pleroma/admin/activation_status/#{user.nickname}", %{status: true})
|
||||
|> put("/api/pleroma/admin/users/#{user.nickname}/activation_status", %{status: true})
|
||||
|
||||
user = User.get_cached_by_id(user.id)
|
||||
assert user.info.deactivated == false
|
||||
|
@ -280,7 +280,7 @@ test "returns 403 when requested by a non-admin", %{conn: conn} do
|
|||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> put("/api/pleroma/admin/activation_status/#{user.nickname}", %{status: false})
|
||||
|> put("/api/pleroma/admin/users/#{user.nickname}/activation_status", %{status: false})
|
||||
|
||||
assert json_response(conn, :forbidden)
|
||||
end
|
||||
|
@ -309,7 +309,9 @@ test "sends invitation and returns 204", %{conn: conn, user: user} do
|
|||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> post("/api/pleroma/admin/email_invite?email=#{recipient_email}&name=#{recipient_name}")
|
||||
|> post(
|
||||
"/api/pleroma/admin/users/email_invite?email=#{recipient_email}&name=#{recipient_name}"
|
||||
)
|
||||
|
||||
assert json_response(conn, :no_content)
|
||||
|
||||
|
@ -341,13 +343,13 @@ test "it returns 403 if requested by a non-admin", %{conn: conn} do
|
|||
conn =
|
||||
conn
|
||||
|> assign(:user, non_admin_user)
|
||||
|> post("/api/pleroma/admin/email_invite?email=foo@bar.com&name=JD")
|
||||
|> post("/api/pleroma/admin/users/email_invite?email=foo@bar.com&name=JD")
|
||||
|
||||
assert json_response(conn, :forbidden)
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /api/pleroma/admin/email_invite, with invalid config" do
|
||||
describe "POST /api/pleroma/admin/users/email_invite, with invalid config" do
|
||||
setup do
|
||||
[user: insert(:user, info: %{is_admin: true})]
|
||||
end
|
||||
|
@ -367,7 +369,7 @@ test "it returns 500 if `invites_enabled` is not enabled", %{conn: conn, user: u
|
|||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> post("/api/pleroma/admin/email_invite?email=foo@bar.com&name=JD")
|
||||
|> post("/api/pleroma/admin/users/email_invite?email=foo@bar.com&name=JD")
|
||||
|
||||
assert json_response(conn, :internal_server_error)
|
||||
end
|
||||
|
@ -387,7 +389,7 @@ test "it returns 500 if `registrations_open` is enabled", %{conn: conn, user: us
|
|||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> post("/api/pleroma/admin/email_invite?email=foo@bar.com&name=JD")
|
||||
|> post("/api/pleroma/admin/users/email_invite?email=foo@bar.com&name=JD")
|
||||
|
||||
assert json_response(conn, :internal_server_error)
|
||||
end
|
||||
|
@ -405,7 +407,7 @@ test "/api/pleroma/admin/invite_token" do
|
|||
assert conn.status == 200
|
||||
end
|
||||
|
||||
test "/api/pleroma/admin/password_reset" do
|
||||
test "/api/pleroma/admin/users/:nickname/password_reset" do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
user = insert(:user)
|
||||
|
||||
|
@ -413,7 +415,7 @@ test "/api/pleroma/admin/password_reset" do
|
|||
build_conn()
|
||||
|> assign(:user, admin)
|
||||
|> put_req_header("accept", "application/json")
|
||||
|> get("/api/pleroma/admin/password_reset?nickname=#{user.nickname}")
|
||||
|> get("/api/pleroma/admin/users/#{user.nickname}/password_reset")
|
||||
|
||||
assert conn.status == 200
|
||||
end
|
||||
|
@ -822,7 +824,7 @@ test "PATCH /api/pleroma/admin/users/:nickname/toggle_activation" do
|
|||
}
|
||||
end
|
||||
|
||||
describe "GET /api/pleroma/admin/invite_token" do
|
||||
describe "GET /api/pleroma/admin/users/invite_token" do
|
||||
setup do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
|
||||
|
@ -834,7 +836,7 @@ test "PATCH /api/pleroma/admin/users/:nickname/toggle_activation" do
|
|||
end
|
||||
|
||||
test "without options", %{conn: conn} do
|
||||
conn = get(conn, "/api/pleroma/admin/invite_token")
|
||||
conn = get(conn, "/api/pleroma/admin/users/invite_token")
|
||||
|
||||
token = json_response(conn, 200)
|
||||
invite = UserInviteToken.find_by_token!(token)
|
||||
|
@ -846,7 +848,7 @@ test "without options", %{conn: conn} do
|
|||
|
||||
test "with expires_at", %{conn: conn} do
|
||||
conn =
|
||||
get(conn, "/api/pleroma/admin/invite_token", %{
|
||||
get(conn, "/api/pleroma/admin/users/invite_token", %{
|
||||
"invite" => %{"expires_at" => Date.to_string(Date.utc_today())}
|
||||
})
|
||||
|
||||
|
@ -861,7 +863,7 @@ test "with expires_at", %{conn: conn} do
|
|||
|
||||
test "with max_use", %{conn: conn} do
|
||||
conn =
|
||||
get(conn, "/api/pleroma/admin/invite_token", %{
|
||||
get(conn, "/api/pleroma/admin/users/invite_token", %{
|
||||
"invite" => %{"max_use" => 150}
|
||||
})
|
||||
|
||||
|
@ -875,7 +877,7 @@ test "with max_use", %{conn: conn} do
|
|||
|
||||
test "with max use and expires_at", %{conn: conn} do
|
||||
conn =
|
||||
get(conn, "/api/pleroma/admin/invite_token", %{
|
||||
get(conn, "/api/pleroma/admin/users/invite_token", %{
|
||||
"invite" => %{"max_use" => 150, "expires_at" => Date.to_string(Date.utc_today())}
|
||||
})
|
||||
|
||||
|
@ -888,7 +890,7 @@ test "with max use and expires_at", %{conn: conn} do
|
|||
end
|
||||
end
|
||||
|
||||
describe "GET /api/pleroma/admin/invites" do
|
||||
describe "GET /api/pleroma/admin/users/invites" do
|
||||
setup do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
|
||||
|
@ -900,7 +902,7 @@ test "with max use and expires_at", %{conn: conn} do
|
|||
end
|
||||
|
||||
test "no invites", %{conn: conn} do
|
||||
conn = get(conn, "/api/pleroma/admin/invites")
|
||||
conn = get(conn, "/api/pleroma/admin/users/invites")
|
||||
|
||||
assert json_response(conn, 200) == %{"invites" => []}
|
||||
end
|
||||
|
@ -908,7 +910,7 @@ test "no invites", %{conn: conn} do
|
|||
test "with invite", %{conn: conn} do
|
||||
{:ok, invite} = UserInviteToken.create_invite()
|
||||
|
||||
conn = get(conn, "/api/pleroma/admin/invites")
|
||||
conn = get(conn, "/api/pleroma/admin/users/invites")
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
"invites" => [
|
||||
|
@ -926,7 +928,7 @@ test "with invite", %{conn: conn} do
|
|||
end
|
||||
end
|
||||
|
||||
describe "POST /api/pleroma/admin/revoke_invite" do
|
||||
describe "POST /api/pleroma/admin/users/revoke_invite" do
|
||||
test "with token" do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
{:ok, invite} = UserInviteToken.create_invite()
|
||||
|
@ -934,7 +936,7 @@ test "with token" do
|
|||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, admin)
|
||||
|> post("/api/pleroma/admin/revoke_invite", %{"token" => invite.token})
|
||||
|> post("/api/pleroma/admin/users/revoke_invite", %{"token" => invite.token})
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
"expires_at" => nil,
|
||||
|
|
Loading…
Reference in a new issue