end
conn
- |> send(200)
+ |> json(nickname)
end
def user_create(
User.register_changeset(%User{}, new_user)
- Repo.insert!(user)
+ Repo.insert!(new_user)
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
def relay_follow(conn, %{"relay_url" => target}) do
:ok = Relay.follow(target)
conn
- |> send(200)
+ |> json(target)
end
def relay_unfollow(conn, %{"relay_url" => target}) do
:ok = Relay.unfollow(target)
conn
- |> send(200)
+ |> json(target)
end
@shortdoc "Get a account registeration invite token (base64 string)"
def get_invite_token(conn, _params) do
- {:ok, token} <- Pleroma.UserInviteToken.create_token()
+ {:ok, token} = Pleroma.UserInviteToken.create_token()
conn
|> json(token.token)
delete("/user", AdminAPIController, :user_delete)
post("/user", AdminAPIController, :user_create)
- # Maybe put a "rights" endpoint instead?
- post("/moderator", AdminAPIController, :moderator_make)
- delete("/moderator", AdminAPIController, :moderator_unmake)
- post("/admin", AdminAPIController, :admin_make)
- delete("/admin", AdminAPIController, :admin_unmake)
+ post("/rights/:right/:nickname", AdminAPIController, :right_add)
+ delete("/rights/:right/:nickname", AdminAPIController, :right_delete)
post("/relay", AdminAPIController, :relay_follow)
delete("/relay", AdminAPIController, :relay_unfollow)