(20241205) Some details added to Mail OAuth.

This commit is contained in:
2024-12-05 11:56:33 +05:30
parent 449d7ed451
commit 6bdad7d6f7
3 changed files with 25 additions and 13 deletions
+17 -12
View File
@@ -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},