diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index fd988bbc..00000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "version": "0.2.0", - "configurations": [ - { - "name": "Run Uvicorn Server", - "type": "debugpy", - "request": "launch", - "program": "${workspaceFolder}/venv/bin/uvicorn", // Adjust path for Windows if needed - "args": [ - "main:app", - "--reload", - "--port", "8000" - ], - "console": "integratedTerminal", - "env": { - "PYTHONPATH": "${workspaceFolder}" - }, - "cwd": "${workspaceFolder}", - "justMyCode": true - } - ] -} \ No newline at end of file diff --git a/services/supabase/users_manager.py b/services/supabase/users_manager.py index 272e5a8e..d05816f2 100644 --- a/services/supabase/users_manager.py +++ b/services/supabase/users_manager.py @@ -246,10 +246,27 @@ def user_exists(self, user_id: int) -> bool: return True return False + + @handle_exceptions(default_return_value=False, raise_on_error=False) + def get_user_info(self, user_id: int) -> dict: + """Get user info from the users table""" + data, _ = ( + self.client.table(table_name="users") + .select("*") + .eq(column="user_id", value=user_id) + .execute() + ) + if len(data[1]) > 0: + return data[1][0] + return {} + + @handle_exceptions(default_return_value=None, raise_on_error=True) def handle_user_email_update(self, user_id: int, email: str) -> None: - """Update user email in the users table if email is valid and not None""" + """Update user email in the users table if email is valid and not None and different from the current email""" if self.check_email_is_valid(email=email): - self.client.table("users").update( - json={"email": email} - ).eq("user_id", user_id).execute() + user_info = self.get_user_info(user_id=user_id) + if user_info.get("email") != email: + self.client.table("users").update( + json={"email": email} + ).eq("user_id", user_id).execute() diff --git a/tests/services/supabase/test_users_manager.py b/tests/services/supabase/test_users_manager.py index 25b00cd5..0cdecb73 100644 --- a/tests/services/supabase/test_users_manager.py +++ b/tests/services/supabase/test_users_manager.py @@ -431,40 +431,25 @@ def test_handle_user_email_update() -> None: no_reply_email = f"no_reply_email@{GITHUB_NOREPLY_EMAIL_DOMAIN}" supabase_manager.handle_user_email_update(user_id=USER_ID, email=no_reply_email) - # Verify the email was updated - users_data, _ = ( - supabase_manager.client.table(table_name="users") - .select("email") - .eq(column="user_id", value=USER_ID) - .execute() - ) - assert users_data[1][0]["email"] == EMAIL + # Verify the email was not updated + user_data = supabase_manager.get_user_info(user_id=USER_ID) + assert user_data["email"] == EMAIL # Update the user's email none_email = None supabase_manager.handle_user_email_update(user_id=USER_ID, email=none_email) - # Verify the email was updated - users_data, _ = ( - supabase_manager.client.table(table_name="users") - .select("email") - .eq(column="user_id", value=USER_ID) - .execute() - ) - assert users_data[1][0]["email"] == EMAIL + # Verify the email was not updated + user_data = supabase_manager.get_user_info(user_id=USER_ID) + assert user_data["email"] == EMAIL # Update the user's email new_email = "new_email@example.com" supabase_manager.handle_user_email_update(user_id=USER_ID, email=new_email) # Verify the email was updated - users_data, _ = ( - supabase_manager.client.table(table_name="users") - .select("email") - .eq(column="user_id", value=USER_ID) - .execute() - ) - assert users_data[1][0]["email"] == new_email + user_data = supabase_manager.get_user_info(user_id=USER_ID) + assert user_data["email"] == new_email # Clean Up wipe_installation_owner_user_data()