(20241205) Accepting many token ids to list mails.
This commit is contained in:
@@ -121,7 +121,7 @@ def init(blueprint_setup_state):
|
|||||||
# ---------------------------------------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
@mail_list_bp.route("/list/id/token", methods = ["GET"])
|
@mail_list_bp.route("/list/id/token", methods = ["GET", "POST"])
|
||||||
@set_api_version(api_version = "1.0.0")
|
@set_api_version(api_version = "1.0.0")
|
||||||
@read_input(sanitize_headers = False, sanitize_data = False)
|
@read_input(sanitize_headers = False, sanitize_data = False)
|
||||||
@get_session_info(key = "X-Session-Token", session_coro = "get_session")
|
@get_session_info(key = "X-Session-Token", session_coro = "get_session")
|
||||||
|
|||||||
@@ -211,7 +211,7 @@ async def handle_gmail_callback() -> render_template:
|
|||||||
mongo_conn = current_app.data_mongo,
|
mongo_conn = current_app.data_mongo,
|
||||||
session_token = g.inbound_headers.get("X-Session-Token"),
|
session_token = g.inbound_headers.get("X-Session-Token"),
|
||||||
token_id = g.inbound_data["state"],
|
token_id = g.inbound_data["state"],
|
||||||
client_user_id = {"email": tokens.email},
|
client_user_id = tokens.client_user_id,
|
||||||
token = tokens.model_dump()
|
token = tokens.model_dump()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ async def request_oauth_authorization_url(
|
|||||||
client_user_id = {
|
client_user_id = {
|
||||||
"userId": inbound_data.auth.userId,
|
"userId": inbound_data.auth.userId,
|
||||||
"senderId": inbound_data.auth.senderId,
|
"senderId": inbound_data.auth.senderId,
|
||||||
"entityId": inbound_data.auth.enttiyId
|
"entityId": inbound_data.auth.entityId
|
||||||
},
|
},
|
||||||
auth = inbound_data.auth.model_dump(),
|
auth = inbound_data.auth.model_dump(),
|
||||||
token = None,
|
token = None,
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ from models.behaviour.base import BaseModel
|
|||||||
from bson import ObjectId
|
from bson import ObjectId
|
||||||
|
|
||||||
# To work with datatypes:
|
# To work with datatypes:
|
||||||
from typing import Literal
|
from typing import Literal, List
|
||||||
|
|
||||||
# For asynchronous activities:
|
# For asynchronous activities:
|
||||||
import asyncio
|
import asyncio
|
||||||
@@ -142,7 +142,7 @@ class MailRetrieveModel(BaseModel):
|
|||||||
async def list_for_token_id(
|
async def list_for_token_id(
|
||||||
self,
|
self,
|
||||||
mongo_conn: AsyncMongo,
|
mongo_conn: AsyncMongo,
|
||||||
token_id: str | ObjectId,
|
token_id: str | ObjectId | List[str | ObjectId],
|
||||||
limit: int = 25,
|
limit: int = 25,
|
||||||
skip: int = 0
|
skip: int = 0
|
||||||
):
|
):
|
||||||
@@ -150,16 +150,20 @@ class MailRetrieveModel(BaseModel):
|
|||||||
"""
|
"""
|
||||||
To enlist mails for one account.
|
To enlist mails for one account.
|
||||||
:param mongo_conn: The instance of the database connector to use to get the mail's data.
|
:param mongo_conn: The instance of the database connector to use to get the mail's data.
|
||||||
:param token_id: The id of the document in the database that holds the tokens to access the account.
|
:param token_id: The id(s) of the document in the database that holds the tokens to access the account.
|
||||||
:param limit: How many records to fetch.
|
:param limit: How many records to fetch.
|
||||||
:param skip: How many initial records to skip. useful for pagination.
|
:param skip: How many initial records to skip. useful for pagination.
|
||||||
:return: Either the JSON that describes the mails or None if something failed.
|
:return: Either the JSON that describes the mails or None if something failed.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# Ensure that the token ids are in expected format:
|
||||||
|
if not isinstance(token_id, list): token_id = [token_id]
|
||||||
|
token_id = [ObjectId(t) for t in token_id]
|
||||||
|
|
||||||
# Get the data from the database:
|
# Get the data from the database:
|
||||||
mails_list = await mongo_conn.find_many(
|
mails_list = await mongo_conn.find_many(
|
||||||
collection = self.MAIL_COLLECTION,
|
collection = self.MAIL_COLLECTION,
|
||||||
filter = {"tokenId": ObjectId(token_id)},
|
filter = {"tokenId": {"$in": token_id}},
|
||||||
projection = {
|
projection = {
|
||||||
"_id": True,
|
"_id": True,
|
||||||
"serviceType": True,
|
"serviceType": True,
|
||||||
|
|||||||
@@ -389,7 +389,7 @@ class MailSyncModel(BaseModel):
|
|||||||
db_conn = current_app.sql_writer,
|
db_conn = current_app.sql_writer,
|
||||||
mongo_conn = mongo_conn,
|
mongo_conn = mongo_conn,
|
||||||
token_id = token_id,
|
token_id = token_id,
|
||||||
email_id = tokens.email,
|
client_user_id = tokens.client_user_id,
|
||||||
token = tokens,
|
token = tokens,
|
||||||
session_token = session_token
|
session_token = session_token
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ sys.path.append("..")
|
|||||||
|
|
||||||
# For making data behaviour_models:
|
# For making data behaviour_models:
|
||||||
from pydantic import BaseModel, Field, field_validator, PastDatetime
|
from pydantic import BaseModel, Field, field_validator, PastDatetime
|
||||||
from typing import Optional, Literal
|
from typing import Optional, Literal, List
|
||||||
|
|
||||||
# My utils:
|
# My utils:
|
||||||
from utils_v2.string import regex
|
from utils_v2.string import regex
|
||||||
@@ -101,8 +101,8 @@ class MailListRequestHeaders(BaseModel):
|
|||||||
|
|
||||||
class MailListByAccountIdRequestData(BaseModel):
|
class MailListByAccountIdRequestData(BaseModel):
|
||||||
|
|
||||||
tokenId: str = Field(
|
tokenId: str | List[str] = Field(
|
||||||
description = "the account identifier (Mongo ObjectId) granted by 'MailOAuthModel.get_account_identifier'",
|
description = "the account identifier(s) (Mongo ObjectId) granted by 'MailOAuthModel.get_account_identifier'",
|
||||||
frozen = True
|
frozen = True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -118,6 +118,10 @@ class GoogleAuthTokens(BaseModel):
|
|||||||
# ┣┛┛ ┗┛┣┛┗ ┛ ┗┗┗ ┛
|
# ┣┛┛ ┗┛┣┛┗ ┛ ┗┗┗ ┛
|
||||||
# ┛
|
# ┛
|
||||||
|
|
||||||
|
@property
|
||||||
|
def client_user_id(self):
|
||||||
|
return {"email": self.email}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def expired(self):
|
def expired(self):
|
||||||
return True if date_time.get_current_utc_date_time() >= self.expiresAt else False
|
return True if date_time.get_current_utc_date_time() >= self.expiresAt else False
|
||||||
|
|||||||
Reference in New Issue
Block a user