render_error(conn, :forbidden, "You can't revoke your own admin status.")
end
- @doc "Sends registration invite via email"
- def email_invite(%{assigns: %{user: user}} = conn, %{"email" => email} = params) do
- with {_, false} <- {:registrations_open, Config.get([:instance, :registrations_open])},
- {_, true} <- {:invites_enabled, Config.get([:instance, :invites_enabled])},
- {:ok, invite_token} <- UserInviteToken.create_invite(),
- email <-
- Pleroma.Emails.UserEmail.user_invitation_email(
- user,
- invite_token,
- email,
- params["name"]
- ),
- {:ok, _} <- Pleroma.Emails.Mailer.deliver(email) do
- json_response(conn, :no_content, "")
- def relay_list(conn, _params) do
- with {:ok, list} <- Relay.list() do
- json(conn, %{relays: list})
-- else
- {:registrations_open, _} ->
- {:error, "To send invites you need to set the `registrations_open` option to false."}
-
- {:invites_enabled, _} ->
- {:error, "To send invites you need to set the `invites_enabled` option to true."}
- _ ->
- conn
- |> put_status(500)
-- end
-- end
-
- @doc "Create an account registration invite token"
- def create_invite_token(conn, params) do
- opts = %{}
-
- opts =
- if params["max_use"],
- do: Map.put(opts, :max_use, params["max_use"]),
- else: opts
-
- opts =
- if params["expires_at"],
- do: Map.put(opts, :expires_at, params["expires_at"]),
- else: opts
--
- {:ok, invite} = UserInviteToken.create_invite(opts)
- def relay_follow(%{assigns: %{user: admin}} = conn, %{"relay_url" => target}) do
- with {:ok, _message} <- Relay.follow(target) do
- ModerationLog.insert_log(%{
- action: "relay_follow",
- actor: admin,
- target: target
- })
--
- json(conn, AccountView.render("invite.json", %{invite: invite}))
- json(conn, target)
- else
- _ ->
- conn
- |> put_status(500)
- |> json(target)
- end
-- end
-
- @doc "Get list of created invites"
- def invites(conn, _params) do
- invites = UserInviteToken.list_invites()
--
- conn
- |> put_view(AccountView)
- |> render("invites.json", %{invites: invites})
- end
- def relay_unfollow(%{assigns: %{user: admin}} = conn, %{"relay_url" => target}) do
- with {:ok, _message} <- Relay.unfollow(target) do
- ModerationLog.insert_log(%{
- action: "relay_unfollow",
- actor: admin,
- target: target
- })
--
- @doc "Revokes invite by token"
- def revoke_invite(conn, %{"token" => token}) do
- with {:ok, invite} <- UserInviteToken.find_by_token(token),
- {:ok, updated_invite} = UserInviteToken.update_invite(invite, %{used: true}) do
- conn
- |> put_view(AccountView)
- |> render("invite.json", %{invite: updated_invite})
- json(conn, target)
-- else
- nil -> {:error, :not_found}
- _ ->
- conn
- |> put_status(500)
- |> json(target)
-- end
-- end
--
@doc "Get a password reset token (base64 string) for given nickname"
def get_password_reset(conn, %{"nickname" => nickname}) do
(%User{local: true} = user) = User.get_cached_by_nickname(nickname)
:right_delete_multiple
)
- get("/relay", AdminAPIController, :relay_list)
- post("/relay", AdminAPIController, :relay_follow)
- delete("/relay", AdminAPIController, :relay_unfollow)
+ get("/relay", RelayController, :index)
+ post("/relay", RelayController, :follow)
+ delete("/relay", RelayController, :unfollow)
- post("/users/invite_token", AdminAPIController, :create_invite_token)
- get("/users/invites", AdminAPIController, :invites)
- post("/users/revoke_invite", AdminAPIController, :revoke_invite)
- post("/users/email_invite", AdminAPIController, :email_invite)
+ post("/users/invite_token", InviteController, :create)
+ get("/users/invites", InviteController, :index)
+ post("/users/revoke_invite", InviteController, :revoke)
+ post("/users/email_invite", InviteController, :email)
get("/users/:nickname/password_reset", AdminAPIController, :get_password_reset)
patch("/users/force_password_reset", AdminAPIController, :force_password_reset)