feat(portal): enable welcome email sending on manually provisionned o… (#5679)

…idc users (#5127)

Currently we can only send a welcome email to oidc users who have
already logged in once. For manually provisionned oidc users, we can't.
This PR aims to solve this issue

---------

Co-authored-by: Antoine <antoinelabarussias@gmail.com>
This commit is contained in:
Jamil
2024-07-02 12:59:23 -07:00
committed by GitHub
parent 33dff8af96
commit 1edc827bca
2 changed files with 45 additions and 3 deletions

View File

@@ -926,7 +926,8 @@ defmodule Web.CoreComponents do
end
def identity_has_email?(identity) do
not is_nil(provider_email(identity)) or identity.provider.adapter == :email
not is_nil(provider_email(identity)) or identity.provider.adapter == :email or
identity.provider_identifier =~ "@"
end
defp provider_email(identity) do

View File

@@ -501,7 +501,34 @@ defmodule Web.Live.Actors.ShowTest do
}
)
oidc_identity = Fixtures.Auth.create_identity(account: account, actor: actor)
{oidc_provider, _bypass} =
Fixtures.Auth.start_and_create_openid_connect_provider(account: account)
oidc_manually_provisioned_identity =
Fixtures.Auth.create_identity(
account: account,
actor: actor,
provider: oidc_provider,
provider_identifier: Fixtures.Auth.email()
)
oidc_identity =
Fixtures.Auth.create_identity(
account: account,
actor: actor,
provider: oidc_provider,
provider_state: %{
"userinfo" => %{"email" => Fixtures.Auth.email()}
}
)
oidc_identity_with_no_email =
Fixtures.Auth.create_identity(
account: account,
actor: actor,
provider: oidc_provider,
provider_identifier: "sub123"
)
email_identity =
Fixtures.Auth.create_identity(account: account, actor: actor, provider: email_provider)
@@ -524,9 +551,23 @@ defmodule Web.Live.Actors.ShowTest do
|> element("#identity-#{google_identity.id} button", "Send Welcome Email")
|> has_element?()
refute lv
assert lv
|> element(
"#identity-#{oidc_manually_provisioned_identity.id} button",
"Send Welcome Email"
)
|> has_element?()
assert lv
|> element("#identity-#{oidc_identity.id} button", "Send Welcome Email")
|> has_element?()
refute lv
|> element(
"#identity-#{oidc_identity_with_no_email.id} button",
"Send Welcome Email"
)
|> has_element?()
end
test "allows deleting identities", %{