Fix import contact from google
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
bc6ddf84ea
commit
b66c11a71e
@ -59,6 +59,10 @@ async def import_contacts_from_google(
|
|||||||
Number of contacts imported
|
Number of contacts imported
|
||||||
"""
|
"""
|
||||||
from uuid import UUID
|
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
|
# event_id and added_by_user_id are required
|
||||||
if not event_id:
|
if not event_id:
|
||||||
@ -85,6 +89,8 @@ async def import_contacts_from_google(
|
|||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
response = await client.get(url, headers=headers, params=params)
|
response = await client.get(url, headers=headers, params=params)
|
||||||
|
|
||||||
|
logger.info(f"Google API response status: {response.status_code}")
|
||||||
|
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
# Try to parse error details
|
# Try to parse error details
|
||||||
try:
|
try:
|
||||||
@ -108,6 +114,8 @@ async def import_contacts_from_google(
|
|||||||
data = response.json()
|
data = response.json()
|
||||||
connections = data.get("connections", [])
|
connections = data.get("connections", [])
|
||||||
|
|
||||||
|
logger.info(f"Received {len(connections)} connections from Google")
|
||||||
|
|
||||||
for connection in connections:
|
for connection in connections:
|
||||||
# Extract name
|
# Extract name
|
||||||
names = connection.get("names", [])
|
names = connection.get("names", [])
|
||||||
@ -172,4 +180,6 @@ async def import_contacts_from_google(
|
|||||||
|
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
|
logger.info(f"Completed Google contacts import - imported {imported_count} new contacts")
|
||||||
|
|
||||||
return imported_count
|
return imported_count
|
||||||
|
|||||||
@ -976,6 +976,8 @@ async def google_callback(
|
|||||||
Handle Google OAuth callback.
|
Handle Google OAuth callback.
|
||||||
Exchanges authorization code for access token and imports contacts.
|
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:
|
if error:
|
||||||
frontend_url = os.getenv("FRONTEND_URL", "http://localhost:5173")
|
frontend_url = os.getenv("FRONTEND_URL", "http://localhost:5173")
|
||||||
error_url = f"{frontend_url}?error={quote(error)}"
|
error_url = f"{frontend_url}?error={quote(error)}"
|
||||||
@ -1053,6 +1055,8 @@ async def google_callback(
|
|||||||
event_id=event_id
|
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
|
# Success - return HTML that sets sessionStorage with import details and redirects
|
||||||
frontend_url = os.getenv("FRONTEND_URL", "http://localhost:5173")
|
frontend_url = os.getenv("FRONTEND_URL", "http://localhost:5173")
|
||||||
|
|
||||||
@ -1086,10 +1090,12 @@ async def google_callback(
|
|||||||
return HTMLResponse(content=html_content)
|
return HTMLResponse(content=html_content)
|
||||||
|
|
||||||
except Exception as import_error:
|
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")
|
frontend_url = os.getenv("FRONTEND_URL", "http://localhost:5173")
|
||||||
return RedirectResponse(url=f"{frontend_url}?error={quote(f'Import failed: {str(import_error)}')}")
|
return RedirectResponse(url=f"{frontend_url}?error={quote(f'Import failed: {str(import_error)}')}")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
logger.error(f"OAuth callback error: {str(e)}", exc_info=True)
|
||||||
frontend_url = os.getenv("FRONTEND_URL", "http://localhost:5173")
|
frontend_url = os.getenv("FRONTEND_URL", "http://localhost:5173")
|
||||||
return RedirectResponse(url=f"{frontend_url}?error={quote('OAuth error')}")
|
return RedirectResponse(url=f"{frontend_url}?error={quote('OAuth error')}")
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user