mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-09-29 05:15:12 +02:00
Ensure gmail works for personal accounts (#3541)
* Ensure gmail works for personal accounts * nit * minor update
This commit is contained in:
@@ -4,6 +4,7 @@ from typing import Dict
|
|||||||
|
|
||||||
from google.oauth2.credentials import Credentials as OAuthCredentials # type: ignore
|
from google.oauth2.credentials import Credentials as OAuthCredentials # type: ignore
|
||||||
from google.oauth2.service_account import Credentials as ServiceAccountCredentials # type: ignore
|
from google.oauth2.service_account import Credentials as ServiceAccountCredentials # type: ignore
|
||||||
|
from googleapiclient.errors import HttpError # type: ignore
|
||||||
|
|
||||||
from onyx.configs.app_configs import INDEX_BATCH_SIZE
|
from onyx.configs.app_configs import INDEX_BATCH_SIZE
|
||||||
from onyx.configs.constants import DocumentSource
|
from onyx.configs.constants import DocumentSource
|
||||||
@@ -249,6 +250,13 @@ class GmailConnector(LoadConnector, PollConnector, SlimConnector):
|
|||||||
return new_creds_dict
|
return new_creds_dict
|
||||||
|
|
||||||
def _get_all_user_emails(self) -> list[str]:
|
def _get_all_user_emails(self) -> list[str]:
|
||||||
|
"""
|
||||||
|
List all user emails if we are on a Google Workspace domain.
|
||||||
|
If the domain is gmail.com, or if we attempt to call the Admin SDK and
|
||||||
|
get a 404, fall back to using the single user.
|
||||||
|
"""
|
||||||
|
|
||||||
|
try:
|
||||||
admin_service = get_admin_service(self.creds, self.primary_admin_email)
|
admin_service = get_admin_service(self.creds, self.primary_admin_email)
|
||||||
emails = []
|
emails = []
|
||||||
for user in execute_paginated_retrieval(
|
for user in execute_paginated_retrieval(
|
||||||
@@ -261,6 +269,18 @@ class GmailConnector(LoadConnector, PollConnector, SlimConnector):
|
|||||||
emails.append(email)
|
emails.append(email)
|
||||||
return emails
|
return emails
|
||||||
|
|
||||||
|
except HttpError as e:
|
||||||
|
if e.resp.status == 404:
|
||||||
|
logger.warning(
|
||||||
|
"Received 404 from Admin SDK; this may indicate a personal Gmail account "
|
||||||
|
"with no Workspace domain. Falling back to single user."
|
||||||
|
)
|
||||||
|
return [self.primary_admin_email]
|
||||||
|
raise
|
||||||
|
|
||||||
|
except Exception:
|
||||||
|
raise
|
||||||
|
|
||||||
def _fetch_threads(
|
def _fetch_threads(
|
||||||
self,
|
self,
|
||||||
time_range_start: SecondsSinceUnixEpoch | None = None,
|
time_range_start: SecondsSinceUnixEpoch | None = None,
|
||||||
|
Reference in New Issue
Block a user