|> html_body(html_body)
end
- def user_invitation_email(user, to_email, to_name \\ nil) do
+ def user_invitation_email(user, user_invite_token, to_email, to_name \\ nil) do
registration_url =
Router.Helpers.redirect_url(
Endpoint,
:registration_page,
- ""
+ user_invite_token.token
)
html_body = """
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]),
- email <- Pleroma.UserEmail.user_invitation_email(user, email, params["name"]),
+ 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
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 "it returns 204", %{conn: conn, user: user} do
+ test "sends invitation and returns 204", %{conn: conn, user: user} do
recipient_email = "foo@bar.com"
recipient_name = "J. D."
assert json_response(conn, :no_content)
- Swoosh.TestAssertions.assert_email_sent(
- Pleroma.UserEmail.user_invitation_email(user, recipient_email, recipient_name)
- )
+ Swoosh.TestAssertions.assert_email_sent()
end
end