end
end
+ @doc "Sends registration invite via email"
+ def email_invite(%{assigns: %{user: user}} = conn, %{"email" => email} = params) do
+ with true <-
+ Pleroma.Config.get([:instance, :invites_enabled]) &&
+ !Pleroma.Config.get([:instance, :registrations_open]),
+ {:ok, invite_token} <- Pleroma.UserInviteToken.create_token(),
+ email <-
+ Pleroma.UserEmail.user_invitation_email(user, invite_token, email, params["name"]),
+ {:ok, _} <- Pleroma.Mailer.deliver(email) do
+ json_response(conn, :no_content, "")
+ end
+ end
+
@doc "Get a account registeration invite token (base64 string)"
def get_invite_token(conn, _params) do
{:ok, token} = Pleroma.UserInviteToken.create_token()
delete("/relay", AdminAPIController, :relay_unfollow)
get("/invite_token", AdminAPIController, :get_invite_token)
+ post("/email_invite", AdminAPIController, :email_invite)
+
get("/password_reset", AdminAPIController, :get_password_reset)
end
def confirm_email(_conn, _params), do: :noop
- def email_invite(%{assigns: %{user: user}} = conn, %{"email" => email} = params) do
- with true <-
- Pleroma.Config.get([:instance, :invites_enabled]) &&
- !Pleroma.Config.get([:instance, :registrations_open]),
- {:ok, invite_token} <- Pleroma.UserInviteToken.create_token(),
- email <-
- Pleroma.UserEmail.user_invitation_email(user, invite_token, email, params["name"]),
- {:ok, _} <- Pleroma.Mailer.deliver(email) do
- json_response(conn, :no_content, "")
- end
- end
-
def update_avatar(%{assigns: %{user: user}} = conn, params) do
{:ok, object} = ActivityPub.upload(params, type: :avatar)
change = Changeset.change(user, %{avatar: object.data})
end
end
+ describe "POST /api/pleroma/admin/email_invite, with valid parameters" do
+ setup do
+ registrations_open = Pleroma.Config.get([:instance, :registrations_open])
+ invites_enabled = Pleroma.Config.get([:instance, :invites_enabled])
+ Pleroma.Config.put([:instance, :registrations_open], false)
+ Pleroma.Config.put([:instance, :invites_enabled], true)
+
+ on_exit(fn ->
+ Pleroma.Config.put([:instance, :registrations_open], registrations_open)
+ Pleroma.Config.put([:instance, :invites_enabled], invites_enabled)
+ :ok
+ end)
+
+ [user: insert(:user, info: %{is_admin: true})]
+ end
+
+ test "sends invitation and returns 204", %{conn: conn, user: user} do
+ recipient_email = "foo@bar.com"
+ recipient_name = "J. D."
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/pleroma/admin/email_invite?email=#{recipient_email}&name=#{recipient_name}")
+
+ assert json_response(conn, :no_content)
+
+ Swoosh.TestAssertions.assert_email_sent()
+ end
+ end
+
test "/api/pleroma/admin/invite_token" do
admin = insert(:user, info: %{is_admin: true})
end
end
- describe "POST /api/email_invite, with valid parameters" do
- setup [:valid_user]
-
- setup do
- registrations_open = Pleroma.Config.get([:instance, :registrations_open])
- invites_enabled = Pleroma.Config.get([:instance, :invites_enabled])
- Pleroma.Config.put([:instance, :registrations_open], false)
- Pleroma.Config.put([:instance, :invites_enabled], true)
-
- on_exit(fn ->
- Pleroma.Config.put([:instance, :registrations_open], registrations_open)
- Pleroma.Config.put([:instance, :invites_enabled], invites_enabled)
- :ok
- end)
-
- :ok
- end
-
- test "sends invitation and returns 204", %{conn: conn, user: user} do
- recipient_email = "foo@bar.com"
- recipient_name = "J. D."
-
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/email_invite?email=#{recipient_email}&name=#{recipient_name}")
-
- assert json_response(conn, :no_content)
-
- Swoosh.TestAssertions.assert_email_sent()
- end
- end
-
describe "GET /api/externalprofile/show" do
test "it returns the user", %{conn: conn} do
user = insert(:user)