From 479e2c90366e4ad7067a9766e10857b7cffd26f5 Mon Sep 17 00:00:00 2001
From: Brian Manifold
Date: Thu, 21 Dec 2023 13:36:08 -0500
Subject: [PATCH] Add ability to email new user after creation (#2957)
Why:
* When a new user and/or identity is created using the Email provider,
there is currently no way to notify the new user/identity automatically.
With this commit an email will now be sent to the newly added
user/identity upon successful creation. This will only be done for
identities created with the 'Email' provider.
---------
Signed-off-by: Brian Manifold
Co-authored-by: Andrew Dryga
---
.../web/lib/web/components/core_components.ex | 13 +-
.../web/lib/web/components/page_components.ex | 2 +-
elixir/apps/web/lib/web/live/actors/show.ex | 30 +++
.../lib/web/live/actors/users/new_identity.ex | 11 +-
elixir/apps/web/lib/web/mailer/auth_email.ex | 15 ++
.../web/mailer/auth_email/new_user.html.heex | 172 ++++++++++++++++++
.../web/mailer/auth_email/new_user.text.heex | 22 +++
.../web/test/web/live/actors/show_test.exs | 84 +++++++++
.../live/actors/users/new_identity_test.exs | 4 +
elixir/apps/web/test/web/mailer/auth_mail.exs | 54 ++++++
10 files changed, 403 insertions(+), 4 deletions(-)
create mode 100644 elixir/apps/web/lib/web/mailer/auth_email/new_user.html.heex
create mode 100644 elixir/apps/web/lib/web/mailer/auth_email/new_user.text.heex
create mode 100644 elixir/apps/web/test/web/mailer/auth_mail.exs
diff --git a/elixir/apps/web/lib/web/components/core_components.ex b/elixir/apps/web/lib/web/components/core_components.ex
index b0eab33d1..007a37582 100644
--- a/elixir/apps/web/lib/web/components/core_components.ex
+++ b/elixir/apps/web/lib/web/components/core_components.ex
@@ -345,7 +345,8 @@ defmodule Web.CoreComponents do
class={[
"p-4 text-sm flash-#{@kind}",
@kind == :success && "text-green-800 bg-green-50",
- @kind == :info && "text-yellow-800 bg-yellow-50",
+ @kind == :info && "text-blue-800 bg-blue-50",
+ @kind == :warning && "text-yellow-800 bg-yellow-50",
@kind == :error && "text-red-800 bg-red-50",
@style != "wide" && "mb-4 rounded"
]}
@@ -937,7 +938,15 @@ defmodule Web.CoreComponents do
end
def get_identity_email(identity) do
- get_in(identity.provider_state, ["userinfo", "email"]) || identity.provider_identifier
+ provider_email(identity) || identity.provider_identifier
+ end
+
+ def identity_has_email?(identity) do
+ not is_nil(provider_email(identity)) || identity.provider.adapter == :email
+ end
+
+ defp provider_email(identity) do
+ get_in(identity.provider_state, ["userinfo", "email"])
end
attr :account, :any, required: true
diff --git a/elixir/apps/web/lib/web/components/page_components.ex b/elixir/apps/web/lib/web/components/page_components.ex
index baf762c5e..4a64356e4 100644
--- a/elixir/apps/web/lib/web/components/page_components.ex
+++ b/elixir/apps/web/lib/web/components/page_components.ex
@@ -32,7 +32,7 @@ defmodule Web.PageComponents do
-
+
<.flash kind={:info} flash={Map.get(content, :flash)} style="wide" />
<.flash kind={:error} flash={Map.get(content, :flash)} style="wide" />
diff --git a/elixir/apps/web/lib/web/live/actors/show.ex b/elixir/apps/web/lib/web/live/actors/show.ex
index e191fe236..1de2544ab 100644
--- a/elixir/apps/web/lib/web/live/actors/show.ex
+++ b/elixir/apps/web/lib/web/live/actors/show.ex
@@ -123,6 +123,18 @@ defmodule Web.Actors.Show do
<:col :let={identity} label="LAST SIGNED IN" sortable="false">
<.relative_datetime datetime={identity.last_seen_at} />
+ <:action :let={identity}>
+
+
<:action :let={identity}>