mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-10 18:17:55 +00:00
Fix connection returns make generic right endpoint [AdminAPI]
This commit is contained in:
parent
c5a2bd6a65
commit
59ce7fedce
|
@ -17,7 +17,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
|
||||||
end
|
end
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> send(200)
|
|> json(nickname)
|
||||||
end
|
end
|
||||||
|
|
||||||
def user_create(
|
def user_create(
|
||||||
|
@ -35,29 +35,71 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
|
||||||
|
|
||||||
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)
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in a new issue