refactor: small changes from PR review
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
918b02a714
commit
55fb845855
2 changed files with 7 additions and 22 deletions
|
|
@ -190,8 +190,9 @@ defmodule Mv.Accounts.User do
|
||||||
changeset
|
changeset
|
||||||
|> Ash.Changeset.change_attribute(:oidc_id, oidc_id)
|
|> Ash.Changeset.change_attribute(:oidc_id, oidc_id)
|
||||||
# Update email if it differs from OIDC provider
|
# Update email if it differs from OIDC provider
|
||||||
|
# change_attribute/3 already checks if value matches existing value
|
||||||
|> then(fn cs ->
|
|> then(fn cs ->
|
||||||
if new_email && to_string(cs.data.email) != new_email do
|
if new_email do
|
||||||
Ash.Changeset.change_attribute(cs, :email, new_email)
|
Ash.Changeset.change_attribute(cs, :email, new_email)
|
||||||
else
|
else
|
||||||
cs
|
cs
|
||||||
|
|
|
||||||
|
|
@ -69,13 +69,11 @@ defmodule Mv.Accounts.User.Validations.OidcEmailCollision do
|
||||||
# User exists with this email - check if it's an upsert or registration
|
# User exists with this email - check if it's an upsert or registration
|
||||||
is_upsert = not is_nil(existing_oidc_user)
|
is_upsert = not is_nil(existing_oidc_user)
|
||||||
|
|
||||||
handle_existing_user(
|
if is_upsert do
|
||||||
user_with_email,
|
handle_upsert_scenario(user_with_email, user_info, existing_oidc_user)
|
||||||
new_oidc_id,
|
else
|
||||||
user_info,
|
handle_create_scenario(user_with_email, new_oidc_id, user_info)
|
||||||
is_upsert,
|
end
|
||||||
existing_oidc_user
|
|
||||||
)
|
|
||||||
|
|
||||||
{:error, error} ->
|
{:error, error} ->
|
||||||
# Database error - log for debugging but don't expose internals to user
|
# Database error - log for debugging but don't expose internals to user
|
||||||
|
|
@ -84,20 +82,6 @@ defmodule Mv.Accounts.User.Validations.OidcEmailCollision do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp handle_existing_user(
|
|
||||||
user_with_email,
|
|
||||||
new_oidc_id,
|
|
||||||
user_info,
|
|
||||||
is_upsert,
|
|
||||||
existing_oidc_user
|
|
||||||
) do
|
|
||||||
if is_upsert do
|
|
||||||
handle_upsert_scenario(user_with_email, user_info, existing_oidc_user)
|
|
||||||
else
|
|
||||||
handle_create_scenario(user_with_email, new_oidc_id, user_info)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Handle email update for existing OIDC user
|
# Handle email update for existing OIDC user
|
||||||
defp handle_upsert_scenario(user_with_email, user_info, existing_oidc_user) do
|
defp handle_upsert_scenario(user_with_email, user_info, existing_oidc_user) do
|
||||||
cond do
|
cond do
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue