Fix import contact from google
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
dvirlabs 2026-03-24 05:47:47 +02:00
parent bc6ddf84ea
commit b66c11a71e
2 changed files with 16 additions and 0 deletions

View File

@ -59,6 +59,10 @@ async def import_contacts_from_google(
Number of contacts imported
"""
from uuid import UUID
import logging
logger = logging.getLogger(__name__)
logger.info(f"Starting Google contacts import - event_id: {event_id}, user_id: {added_by_user_id}, owner: {owner_email}")
# event_id and added_by_user_id are required
if not event_id:
@ -85,6 +89,8 @@ async def import_contacts_from_google(
async with httpx.AsyncClient() as client:
response = await client.get(url, headers=headers, params=params)
logger.info(f"Google API response status: {response.status_code}")
if response.status_code != 200:
# Try to parse error details
try:
@ -108,6 +114,8 @@ async def import_contacts_from_google(
data = response.json()
connections = data.get("connections", [])
logger.info(f"Received {len(connections)} connections from Google")
for connection in connections:
# Extract name
names = connection.get("names", [])
@ -171,5 +179,7 @@ async def import_contacts_from_google(
imported_count += 1
db.commit()
logger.info(f"Completed Google contacts import - imported {imported_count} new contacts")
return imported_count

View File

@ -976,6 +976,8 @@ async def google_callback(
Handle Google OAuth callback.
Exchanges authorization code for access token and imports contacts.
"""
logger.info(f"Google OAuth callback received - state: {state}, has_code: {bool(code)}, error: {error}")
if error:
frontend_url = os.getenv("FRONTEND_URL", "http://localhost:5173")
error_url = f"{frontend_url}?error={quote(error)}"
@ -1053,6 +1055,8 @@ async def google_callback(
event_id=event_id
)
logger.info(f"Successfully imported {imported_count} contacts from Google for event {event_id}")
# Success - return HTML that sets sessionStorage with import details and redirects
frontend_url = os.getenv("FRONTEND_URL", "http://localhost:5173")
@ -1086,10 +1090,12 @@ async def google_callback(
return HTMLResponse(content=html_content)
except Exception as import_error:
logger.error(f"Failed to import contacts from Google: {str(import_error)}", exc_info=True)
frontend_url = os.getenv("FRONTEND_URL", "http://localhost:5173")
return RedirectResponse(url=f"{frontend_url}?error={quote(f'Import failed: {str(import_error)}')}")
except Exception as e:
logger.error(f"OAuth callback error: {str(e)}", exc_info=True)
frontend_url = os.getenv("FRONTEND_URL", "http://localhost:5173")
return RedirectResponse(url=f"{frontend_url}?error={quote('OAuth error')}")