From 6bdad7d6f77bfce1cb89cd2a6c8ec800579695b2 Mon Sep 17 00:00:00 2001 From: khushal Date: Thu, 5 Dec 2024 11:56:33 +0530 Subject: [PATCH] (20241205) Some details added to Mail OAuth. --- api/blueprints/mail/oauth_request.py | 3 ++- models/behaviour/mail/oauth_v2.py | 29 ++++++++++++++++------------ models/data/mail/oauth.py | 6 ++++++ 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/api/blueprints/mail/oauth_request.py b/api/blueprints/mail/oauth_request.py index 5eeda08..3162e6d 100644 --- a/api/blueprints/mail/oauth_request.py +++ b/api/blueprints/mail/oauth_request.py @@ -182,7 +182,8 @@ async def request_oauth_authorization_url( user_info = kwargs["session_info"], email_id = inbound_data.mailId, service_client = inbound_data.mailClient, - auth_type = "oauth" + auth_type = "oauth", + sync_freq = inbound_data.syncFreq ) if token_id is None: return ResponseModel( diff --git a/models/behaviour/mail/oauth_v2.py b/models/behaviour/mail/oauth_v2.py index e4a5f2f..ad79140 100644 --- a/models/behaviour/mail/oauth_v2.py +++ b/models/behaviour/mail/oauth_v2.py @@ -103,6 +103,7 @@ class MailOAuthModel(BaseModel): email_id: str, service_client: Literal["gmail"], auth_type: Literal["oauth"], + sync_freq: Literal[60, 300, 900] = 300, session_token: str = None ) -> ObjectId: @@ -116,6 +117,7 @@ class MailOAuthModel(BaseModel): :param service_client: The name of the company or brand that is providing this service that is being integrated. :param auth_type: To identify the type of authentication being done here. This could indicate simple password authentication, more advance OAuth2.0 authentication, etc. + :param sync_freq: The time interval in which mails need to be sync'd. Specify this in seconds. :param session_token: The session token of the user who requested this service. :return: An ObjectId to later store the granted tokens. """ @@ -150,6 +152,8 @@ class MailOAuthModel(BaseModel): "firstRefreshTs": None, "lastRefreshTs": None, "firstRequestTs": request_ts, + "status": "active", + "syncFreq": max(sync_freq, 60) } }, projection = { @@ -224,19 +228,20 @@ class MailOAuthModel(BaseModel): update = { "$set": { "token": token, + "status": "active", "lastRefreshTs": request_ts, - "firstRefreshTs": { - "$cond": { - "if": { - "$or": [ - {"$eq": ["$firstRefreshTs", None]}, - {"$eq": [{"$type": "$firstRefreshTs"}, "missing"]} - ] - }, - "then": request_ts, - "else": "$firstRefreshTs" - } - } + # "firstRefreshTs": { + # "$cond": { + # "if": { + # "$or": [ + # {"$eq": ["$firstRefreshTs", None]}, + # {"$eq": [{"$type": "$firstRefreshTs"}, "missing"]} + # ] + # }, + # "then": request_ts, + # "else": "$firstRefreshTs" + # } + # } } }, projection = {"token": False}, diff --git a/models/data/mail/oauth.py b/models/data/mail/oauth.py index 33efabd..7470416 100644 --- a/models/data/mail/oauth.py +++ b/models/data/mail/oauth.py @@ -109,6 +109,12 @@ class OAuthMailAuthorizationRequestData(BaseModel): frozen = True ) + syncFreq: Literal[60, 300, 900] = Field( + description = "the sync interval in seconds to fetch the mails from the client", + frozen = True, + default = 300 + ) + # ┏┓ ┏• # ┃ ┏┓┏┓╋┓┏┓ # ┗┛┗┛┛┗┛┗┗┫