(20241214) testing token keys instead of direct ids.

This commit is contained in:
2024-12-14 11:55:05 +05:30
parent 3a03dd4a61
commit c673c3511f
14 changed files with 164 additions and 60 deletions
+26 -18
View File
@@ -238,7 +238,7 @@ class MailController:
# ┗┛┛┗┗┻┗┛┗┗━•┗┛
@staticmethod
async def get_token_id(
async def get_token_key(
db_conn: AsyncMySQL,
mongo_conn: AsyncMongo,
auth_token: CoreAuthTokenModel,
@@ -246,7 +246,7 @@ class MailController:
) -> ObjectId:
# Simply call the core model:
return await current_app.core_auth_token_controller.get_token_id(
return await current_app.core_auth_token_controller.get_token_key(
db_conn = db_conn,
mongo_conn = mongo_conn,
auth_token = auth_token,
@@ -260,7 +260,7 @@ class MailController:
async def set_token(
db_conn: AsyncMySQL,
mongo_conn: AsyncMongo,
token_id: ObjectId | str,
token_key: ObjectId | str,
auth_token: CoreAuthTokenModel,
session_token: str = None
) -> bool:
@@ -269,7 +269,7 @@ class MailController:
return await current_app.core_auth_token_controller.set_token(
db_conn = db_conn,
mongo_conn = mongo_conn,
token_id = token_id,
token_key = token_key,
auth_token = auth_token,
token_notes = {
"email": auth_token.token["email"],
@@ -282,13 +282,25 @@ class MailController:
@staticmethod
async def get_token(
mongo_conn: AsyncMongo,
token_id: ObjectId | str = None,
token_key: ObjectId | str = None,
) -> CoreAuthTokenModel | None:
# Simply call the core model:
return await current_app.core_auth_token_controller.get_token(
mongo_conn = mongo_conn,
token_id = token_id
token_key = token_key
)
@staticmethod
async def get_tokens(
mongo_conn: AsyncMongo,
token_keys: ObjectId | str = None,
) -> List[CoreAuthTokenModel] | None:
# Simply call the core model:
return await current_app.core_auth_token_controller.get_tokens(
mongo_conn = mongo_conn,
token_keys = token_keys
)
# ┏┓ ┳┳┓
@@ -303,7 +315,6 @@ class MailController:
self,
mongo_conn: AsyncMongo,
user_info: CoreUserInfoModel,
token_id: ObjectId,
auth_token: CoreAuthTokenModel,
mail_client: AsyncGMailClient,
google_tokens: GoogleAuthTokens,
@@ -320,11 +331,11 @@ class MailController:
if not force_sync:
mail_records = await current_app.core_message_controller.get_previews(
mongo_conn = mongo_conn,
token_ids = [ObjectId(token_id)],
token_ids = [ObjectId(auth_token.authTokenId)],
limit = 1,
skip = 0,
additional_filter = {
"tokenId": ObjectId(token_id),
"tokenId": ObjectId(auth_token.authTokenId),
"serviceType": auth_token.serviceType,
"client": auth_token.client,
"clientMessageId": message_id
@@ -357,7 +368,7 @@ class MailController:
mail_message = CoreMessageModel(
ts = client_response.data["ts"],
syncTs = date_time.get_current_utc_date_time(as_string = False),
tokenId = token_id,
tokenId = auth_token.authTokenId,
serviceType = auth_token.serviceType,
client = auth_token.client,
clientMessageId = message_id,
@@ -398,7 +409,6 @@ class MailController:
db_conn: AsyncMySQL,
mongo_conn: AsyncMongo,
user_info: CoreUserInfoModel,
token_id: ObjectId,
auth_token: CoreAuthTokenModel,
mail_client: AsyncGMailClient,
llm: LLMController = None,
@@ -427,7 +437,7 @@ class MailController:
await self.set_token(
db_conn = db_conn,
mongo_conn = mongo_conn,
token_id = token_id,
token_key = auth_token.key,
auth_token = auth_token,
session_token = session_token
)
@@ -454,7 +464,6 @@ class MailController:
self.__sync_one_gmail(
mongo_conn = mongo_conn,
user_info = user_info,
token_id = token_id,
auth_token = auth_token,
mail_client = mail_client,
google_tokens = google_tokens,
@@ -478,7 +487,7 @@ class MailController:
mongo_operations.append(
ReplaceOne(
filter = {
"tokenId": ObjectId(token_id),
"tokenId": ObjectId(auth_token.authTokenId),
"serviceType": auth_token.serviceType,
"client": auth_token.client,
"clientMessageId": result.mailMessage.clientMessageId
@@ -514,7 +523,7 @@ class MailController:
db_conn: AsyncMySQL,
mongo_conn: AsyncMongo,
user_info: CoreUserInfoModel,
token_id: ObjectId | str,
token_key: ObjectId | str,
llm: LLMController = None,
force_sync: bool = False,
start_date: datetime.datetime = None,
@@ -533,12 +542,12 @@ class MailController:
# We first load the authorization tokens:
auth_token = await self.get_token(
mongo_conn = mongo_conn,
token_id = token_id,
token_key = token_key,
)
# If we failed to load the authorization tokens:
if not auth_token:
sync_results.message = f"no such token id '{token_id}'"
sync_results.message = f"no such token key '{token_key}'"
return sync_results
# ┏┓ ┏┓┳┳┓ •┓
@@ -550,7 +559,6 @@ class MailController:
db_conn = db_conn,
mongo_conn = mongo_conn,
user_info = user_info,
token_id = token_id,
auth_token = auth_token,
mail_client = current_app.gmail_client,
llm = llm,