(20241205) Migrating from the field "accountId" to "tokenId" to identify auth tokens.

This commit is contained in:
2024-12-05 11:19:23 +05:30
parent f835143ef4
commit 5c36f90e98
15 changed files with 478 additions and 47 deletions
+9 -11
View File
@@ -344,7 +344,7 @@ class MailSyncModel(BaseModel):
self,
session_token: str,
mongo_conn: AsyncMongo,
account_identifier: ObjectId,
token_id: ObjectId,
mail_client: AsyncGMailClient,
tokens: GoogleAuthTokens,
llm: ChatOpenAI = None,
@@ -358,7 +358,7 @@ class MailSyncModel(BaseModel):
Sync many mails from GMail in one shot.
:param session_token: The session token of the uer who is trying to upload this file.
:param mongo_conn: The instance of the connection to the database to use.
:param account_identifier: The id of the document in the database that holds the tokens to access the account.
:param token_id: The id of the document in the database that holds the tokens to access the account.
Needed only for refreshing the tokens and saving them.
:param mail_client: The instance of the mail client to use to perform the action.
:param tokens: The tokens to use to fetch the mails.
@@ -383,7 +383,7 @@ class MailSyncModel(BaseModel):
if tokens_refreshed: await current_app.mail_oauth_model.set_token(
db_conn = current_app.sql_writer,
mongo_conn = mongo_conn,
account_identifier = account_identifier,
token_id = token_id,
email_id = tokens.email,
token = tokens,
session_token = session_token
@@ -439,7 +439,7 @@ class MailSyncModel(BaseModel):
},
replacement = {
"version": "1.0.0",
"accountId": ObjectId(account_identifier),
"tokenId": ObjectId(token_id),
"serviceType": "email",
"client": "gmail",
"payload": result.mailMessage
@@ -461,8 +461,6 @@ class MailSyncModel(BaseModel):
message_ids = [v["id"] for v in messages_list.values()],
add_label_ids = [tokens.labels.get("TCAOFF", {}).get("id")]
)
print(client_response)
print([tokens.labels.get("TCAOFF")])
except Exception as exception:
self._printer(exception)
@@ -474,7 +472,7 @@ class MailSyncModel(BaseModel):
self,
session_token: str,
mongo_conn: AsyncMongo,
account_identifier: ObjectId,
token_id: ObjectId,
llm: ChatOpenAI = None,
force_sync: bool = False,
start_date: datetime.datetime = None,
@@ -487,7 +485,7 @@ class MailSyncModel(BaseModel):
route the request to the appropriate clients.
:param session_token: The session token of the uer who is trying to upload this file.
:param mongo_conn: The instance of the connection to the database to use.
:param account_identifier: The id of the document in the database that holds the tokens to access the account.
:param token_id: The id of the document in the database that holds the tokens to access the account.
Needed only for refreshing the tokens and saving them.
:param llm: The instance of the LLM to use to summarize the mail's content.
:param force_sync: Whether you would like to forcefully re-sync the mail even if it is already present in the
@@ -508,12 +506,12 @@ class MailSyncModel(BaseModel):
# We first load the authorization tokens:
auth_json = await current_app.mail_oauth_model.get_token(
mongo_conn = mongo_conn,
account_identifier = account_identifier,
token_id = token_id,
)
# If we failed to load the authorization tokens:
if not auth_json:
sync_results.message = f"no such account identifier '{account_identifier}'"
sync_results.message = f"no such token id '{token_id}'"
return sync_results
# ┏┓ ┏┓┳┳┓ •┓
@@ -524,7 +522,7 @@ class MailSyncModel(BaseModel):
return await self.__sync_many_gmail(
session_token = session_token,
mongo_conn = mongo_conn,
account_identifier = account_identifier,
token_id = token_id,
mail_client = current_app.gmail_client,
tokens = GoogleAuthTokens(**auth_json["token"]),
llm = llm,