feat(api): update internal id for existing account

This commit is contained in:
Alexander 2024-06-14 15:35:32 +02:00
parent 09daaa2666
commit e081fdc446
2 changed files with 14 additions and 0 deletions

View file

@ -134,6 +134,7 @@ async def create_oauth_tenant(fullname: str, email: str):
errors.append("Invalid email address.")
else:
if users.email_exists(email):
users.update_user_internal_id(email, email)
return users.authenticate_sso(email, email)
if users.get_deleted_user_by_email(email) is not None:
errors.append("Email address previously deleted.")

View file

@ -1020,3 +1020,16 @@ def update_user_settings(user_id, settings):
{"user_id": user_id, "settings": json.dumps(settings)})
)
return helper.dict_to_camel_case(cur.fetchone())
def update_user_internal_id(email, internal_id):
with pg_client.PostgresClient() as cur:
cur.execute(
cur.mogrify(
f"""UPDATE public.users
SET internal_id = %(internal_id)s
WHERE email = %(email)s
AND deleted_at IS NULL;""",
{"email": email, "internal_id": internal_id})
)
return helper.dict_to_camel_case(cur.fetchone())