Fix connection returns make generic right endpoint [AdminAPI]

This commit is contained in:
Haelwenn (lanodan) Monnier 2018-11-02 08:15:09 +01:00
parent c5a2bd6a65
commit 59ce7fedce
No known key found for this signature in database
GPG key ID: D5B7A8E43C997DEE
2 changed files with 50 additions and 11 deletions

View file

@ -17,7 +17,7 @@ def user_delete(conn, %{"nickname" => nickname}) do
end end
conn conn
|> send(200) |> json(nickname)
end end
def user_create( def user_create(
@ -35,29 +35,71 @@ def user_create(
User.register_changeset(%User{}, new_user) User.register_changeset(%User{}, new_user)
Repo.insert!(user) Repo.insert!(new_user)
conn conn
|> send(200) |> json(new_user.nickname)
end
def right_add(conn, %{"right" => right, "nickname" => nickname})
when right in ["moderator", "admin"] do
user = User.get_by_nickname(nickname)
info =
user.info
|> Map.put("is_" <> right, true)
cng = User.info_changeset(user, %{info: info})
{:ok, user} = User.update_and_set_cache(cng)
conn
|> json(user.info)
end
def right_add(conn, _) do
conn
|> put_status(404)
|> json(%{error: "No such right"})
end
def right_delete(conn, %{"right" => right, "nickname" => nickname})
when right in ["moderator", "admin"] do
user = User.get_by_nickname(nickname)
info =
user.info
|> Map.put("is_" <> right, false)
cng = User.info_changeset(user, %{info: info})
{:ok, user} = User.update_and_set_cache(cng)
conn
|> json(user.info)
end
def right_delete(conn, _) do
conn
|> put_status(404)
|> json(%{error: "No such right"})
end end
def relay_follow(conn, %{"relay_url" => target}) do def relay_follow(conn, %{"relay_url" => target}) do
:ok = Relay.follow(target) :ok = Relay.follow(target)
conn conn
|> send(200) |> json(target)
end end
def relay_unfollow(conn, %{"relay_url" => target}) do def relay_unfollow(conn, %{"relay_url" => target}) do
:ok = Relay.unfollow(target) :ok = Relay.unfollow(target)
conn conn
|> send(200) |> json(target)
end end
@shortdoc "Get a account registeration invite token (base64 string)" @shortdoc "Get a account registeration invite token (base64 string)"
def get_invite_token(conn, _params) do def get_invite_token(conn, _params) do
{:ok, token} <- Pleroma.UserInviteToken.create_token() {:ok, token} = Pleroma.UserInviteToken.create_token()
conn conn
|> json(token.token) |> json(token.token)

View file

@ -99,11 +99,8 @@ defmodule Pleroma.Web.Router do
delete("/user", AdminAPIController, :user_delete) delete("/user", AdminAPIController, :user_delete)
post("/user", AdminAPIController, :user_create) post("/user", AdminAPIController, :user_create)
# Maybe put a "rights" endpoint instead? post("/rights/:right/:nickname", AdminAPIController, :right_add)
post("/moderator", AdminAPIController, :moderator_make) delete("/rights/:right/:nickname", AdminAPIController, :right_delete)
delete("/moderator", AdminAPIController, :moderator_unmake)
post("/admin", AdminAPIController, :admin_make)
delete("/admin", AdminAPIController, :admin_unmake)
post("/relay", AdminAPIController, :relay_follow) post("/relay", AdminAPIController, :relay_follow)
delete("/relay", AdminAPIController, :relay_unfollow) delete("/relay", AdminAPIController, :relay_unfollow)