(20241219) SMS module fully re-organized.

This commit is contained in:
2024-12-19 17:26:18 +05:30
parent d89a88ab8e
commit 79b771b48c
28 changed files with 1086 additions and 827 deletions
+1 -1
View File
@@ -61,7 +61,7 @@ from utils_v2.api.async_quart import (
)
# GMail-related utils:
from utils_v2.goog.gmail.gmail_client import SCOPES_GMAIL_MAIL_MANAGEMENT
from utils_v2.goog.controllers.gmail.gmail_client import SCOPES_GMAIL_MAIL_MANAGEMENT
# Data Models:
from models.core.auth_token import CoreAuthTokenModel
+1 -1
View File
@@ -61,7 +61,7 @@ from utils_v2.api.async_quart import (
)
# GMail-related utils:
from utils_v2.goog.gmail.gmail_client import SCOPES_GMAIL_MAIL_MANAGEMENT
from utils_v2.goog.controllers.gmail.gmail_client import SCOPES_GMAIL_MAIL_MANAGEMENT
# Common:
from shared import constants
+1 -1
View File
@@ -62,7 +62,7 @@ from utils_v2.api.async_quart import (
)
# GMail-related utils:
from utils_v2.goog.gmail.gmail_client import SCOPES_GMAIL_MAIL_MANAGEMENT
from utils_v2.goog.controllers.gmail.gmail_client import SCOPES_GMAIL_MAIL_MANAGEMENT
from utils_v2.goog.models.auth_tokens import GoogleAuthTokens
# Common:
+1 -1
View File
@@ -63,7 +63,7 @@ from utils_v2.api.async_quart import (
)
# GMail-related utils:
from utils_v2.goog.gmail.gmail_client import SCOPES_GMAIL_MAIL_MANAGEMENT
from utils_v2.goog.controllers.gmail.gmail_client import SCOPES_GMAIL_MAIL_MANAGEMENT
from utils_v2.goog.models.auth_tokens import GoogleAuthTokens
# Common:
+26 -30
View File
@@ -62,7 +62,7 @@ from utils_v2.api.async_quart import (
)
# GMail-related utils:
from utils_v2.goog.gmail.gmail_client import SCOPES_GMAIL_MAIL_MANAGEMENT
from utils_v2.goog.controllers.gmail.gmail_client import SCOPES_GMAIL_MAIL_MANAGEMENT
from utils_v2.goog.models.auth_tokens import GoogleAuthTokens
# Common:
@@ -140,19 +140,19 @@ def init(blueprint_setup_state):
@log_chain_to_mongo(attr_name = "logs_mongo")
@should_not_be_under_maintenance(attr_name = "is_under_maintenance")
@validate_input(
header_validator = lambda x: MailUpdateTagsRequestHeaders(**x).model_dump(),
data_validator = lambda x: MailUpdateTagsRequestData(**x)
header_validator = lambda x: MailSendRequestHeaders(**x).model_dump(),
data_validator = lambda x: MailSendRequestData(**x)
)
@handle_cancelled_request()
async def send_one_mail(
inbound_headers: dict | MailUpdateTagsRequestHeaders = None,
inbound_data: dict | MailUpdateTagsRequestData = None,
inbound_headers: dict | MailSendRequestHeaders = None,
inbound_data: dict | MailSendRequestData = None,
inbound_files: dict = None,
**kwargs
):
"""
Use this endpoint to update the tags on an e-mail message.
Use this endpoint to send one mail message.
:param inbound_headers: auto-extracted by the decorators.
:param inbound_data: auto-extracted by the decorators.
:param inbound_files: auto-extracted by the decorators.
@@ -160,6 +160,9 @@ async def send_one_mail(
:return: A standard response structure.
"""
# Start by assuming failure:
success = False
# ┏┓ ┓ ┏┓┓ ┓
# ┣┫┓┏╋┣┓ ┃ ┣┓┏┓┏┃┏
# ┛┗┗┻┗┛┗ ┗┛┛┗┗ ┗┛┗
@@ -171,44 +174,37 @@ async def send_one_mail(
http_code = HttpCodes.UNAUTHORIZED
)
# ┏┓ ┓ ┳┳┓ •┓
# ┣ ┏┓╋┏┣┓ ┃┃┃┏┓┓┃
# ┻ ┗ ┗┗┛┗ ┛ ┗┗┻┗┗
# Get the mail:
message = await current_app.mail_controller.get_one_mail(
mongo_conn = current_app.data_mongo,
message_id = inbound_data.messageId
)
# ┏┓ ┓ • ┏┓┓ ┓
# ┃┃┓┏┏┏┓┏┓┏┓┏┣┓┓┏┓ ┃ ┣┓┏┓┏┃┏
# ┗┛┗┻┛┛┗┗ ┛ ┛┛┗┗┣┛ ┗┛┛┗┗ ┗┛┗
# ┛
# Get the token based on the key:
auth_token = await current_app.mail_controller.get_token_from_key(
mongo_conn = current_app.data_mongo,
token_key = inbound_data.tokenKey
)
print("INBOUND DATA:", json.to_string(inbound_data.model_dump(), default=str))
print("INBOUND FILES:", json.to_string(inbound_files, default=str))
print("AUTH TOKEN:", json.to_string(auth_token, default=str))
# We check if the token that was used to fetch the mail is owned by this user:
if not await token_check.is_authorized(
mongo_conn=current_app.data_mongo,
mongo_conn = current_app.data_mongo,
user_info = CoreUserInfoModel(**kwargs["session_info"]),
token_ids = [message.tokenId]
token_ids = [auth_token.authTokenId]
): return ResponseModel(
status_code = StatusCodes.FAILED,
http_code = HttpCodes.UNAUTHORIZED,
message = "The message does not belong to this user."
message = "The account does not belong to this user."
)
# ┳┳ ┓ ┳┳┓ •┓
# ┃┃┏┓┏┫┏┓╋┏┓ ┃┃┃┏┓┓┃
# ┗┛┛┗┗┻┗┗ ┛ ┗┗┻┗┗
# ┛
# ┳┳┓ •┓
# ┗┓┏┓┏┓┏┫ ┃┃┃┏┓┓┃
# ┗┛┛┗┗┻ ┛ ┗┗┻┗┗
# Update the mail:
success = await current_app.mail_controller.update_tags(
mongo_conn = current_app.data_mongo,
message_id = inbound_data.messageId,
unset_tags = inbound_data.unsetTags,
set_tags = inbound_data.setTags
)
pass
# ┳┓
# ┣┫┏┓┏┏┓┏┓┏┓┏┏┓
+1 -1
View File
@@ -63,7 +63,7 @@ from utils_v2.api.async_quart import (
)
# GMail-related utils:
from utils_v2.goog.gmail.gmail_client import SCOPES_GMAIL_MAIL_MANAGEMENT
from utils_v2.goog.controllers.gmail.gmail_client import SCOPES_GMAIL_MAIL_MANAGEMENT
from utils_v2.goog.models.auth_tokens import GoogleAuthTokens
# Common:
+1 -1
View File
@@ -62,7 +62,7 @@ from utils_v2.api.async_quart import (
)
# GMail-related utils:
from utils_v2.goog.gmail.gmail_client import SCOPES_GMAIL_MAIL_MANAGEMENT
from utils_v2.goog.controllers.gmail.gmail_client import SCOPES_GMAIL_MAIL_MANAGEMENT
from utils_v2.goog.models.auth_tokens import GoogleAuthTokens
# Common: