feat(scouts): add gmail label-list + disconnect routes
This commit is contained in:
@@ -41,6 +41,7 @@ from app.core.note_summarizer import generate_note_summary
|
||||
from app.db import get_session
|
||||
from app.integrations import encrypt_token
|
||||
from app.models import CloudScoutConfig, ScoutRunLog, LocalScoutConfig
|
||||
from app.scouts.connectors.registry import get_connector
|
||||
from app.schemas import (
|
||||
CloudScoutCreateRequest,
|
||||
CloudScoutResponse,
|
||||
@@ -375,6 +376,46 @@ async def delete_cloud_scout(
|
||||
return {"ok": True}
|
||||
|
||||
|
||||
@router.get("/cloud/{scout_id}/gmail-labels")
|
||||
async def list_gmail_labels(
|
||||
scout_id: str,
|
||||
db: AsyncSession = Depends(get_session),
|
||||
current_user: UserProfile = Depends(get_current_user),
|
||||
):
|
||||
scout = await db.get(CloudScoutConfig, scout_id)
|
||||
if scout is None or scout.user_id != current_user.id:
|
||||
raise HTTPException(status.HTTP_404_NOT_FOUND, "Scout not found")
|
||||
try:
|
||||
connector = get_connector("gmail")
|
||||
except KeyError:
|
||||
return []
|
||||
return await connector.list_labels(scout)
|
||||
|
||||
|
||||
@router.post("/cloud/{scout_id}/gmail-disconnect", response_model=CloudScoutResponse)
|
||||
async def disconnect_gmail(
|
||||
scout_id: str,
|
||||
db: AsyncSession = Depends(get_session),
|
||||
current_user: UserProfile = Depends(get_current_user),
|
||||
):
|
||||
scout = await db.get(CloudScoutConfig, scout_id)
|
||||
if scout is None or scout.user_id != current_user.id:
|
||||
raise HTTPException(status.HTTP_404_NOT_FOUND, "Scout not found")
|
||||
try:
|
||||
connector = get_connector("gmail")
|
||||
await connector.stop_watch(scout)
|
||||
except KeyError:
|
||||
pass
|
||||
scout.oauth_token_encrypted = None
|
||||
scout.gmail_history_id = None
|
||||
scout.gmail_watch_expires_at = None
|
||||
scout.gmail_address = None
|
||||
scout.enabled = False
|
||||
await db.commit()
|
||||
await db.refresh(scout)
|
||||
return _to_cloud_response(scout)
|
||||
|
||||
|
||||
# ── Gmail OAuth setup (scout-specific) ───────────────────────────────────────
|
||||
|
||||
# Scopes required for Gmail scout connectivity.
|
||||
@@ -556,7 +597,6 @@ async def scout_gmail_oauth_callback(
|
||||
await db.commit()
|
||||
|
||||
# Attempt to set up Gmail push watch so we start receiving Pub/Sub notifications.
|
||||
from app.scouts.connectors.registry import get_connector
|
||||
try:
|
||||
connector = get_connector("gmail")
|
||||
await connector.setup_watch(scout)
|
||||
|
||||
Reference in New Issue
Block a user