Commit f01f9958 authored by Sachin Joshi's avatar Sachin Joshi

make url uniform in admin api

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