diff --git a/api/blueprints/mail/retrieve/list.py b/api/blueprints/mail/retrieve/list.py index 6a890dd..f065b97 100644 --- a/api/blueprints/mail/retrieve/list.py +++ b/api/blueprints/mail/retrieve/list.py @@ -134,7 +134,7 @@ def init(blueprint_setup_state): attr_name = "logs_mongo", project = constants.PROJECT_NAME, log_type = constants.MODULE_NAME, - operation = "mailListByTokIdApi", + operation = "mailListApi", log_input = True, log_output = 1, sensitive_keys = ["sessionToken", "X-Session-Token"] diff --git a/api/blueprints/sms/send.py b/api/blueprints/sms/send.py index 9355828..d830a64 100644 --- a/api/blueprints/sms/send.py +++ b/api/blueprints/sms/send.py @@ -177,7 +177,8 @@ async def send_sms( mongo_conn = current_app.data_mongo, http_client = current_app.http_client, auth_token = auth_token, - messages = inbound_data.message + messages = inbound_data.message, + tags = inbound_data.tags ) # ┳┓ diff --git a/controllers/api/mail.py b/controllers/api/mail.py index 39aee51..44b7867 100644 --- a/controllers/api/mail.py +++ b/controllers/api/mail.py @@ -594,7 +594,7 @@ class MailController: additional_filter: dict = None ) -> List[CoreMessageModel] | None: - # regardless of what additional filter is provided from outside, + # Regardless of what additional filter is provided from outside, # we add a mail-selecting filter here: if additional_filter is None: additional_filter = {} additional_filter["serviceType"] = "email" diff --git a/controllers/api/sms.py b/controllers/api/sms.py index fc463f8..1b4fae9 100644 --- a/controllers/api/sms.py +++ b/controllers/api/sms.py @@ -187,6 +187,7 @@ class SMSController: http_client: httpx.AsyncClient, auth_token: CoreAuthTokenModel, messages: List[NimbusSMSIndiaMessage], + tags: List[Any] ) -> SMSSendManyResults: # Start with a blank variable: @@ -232,7 +233,7 @@ class SMSController: message = client_response.model_dump(), snippet = message.text, aiSnippet = None, - tags = ["sms", "nimbusSmsIndia"] + tags = list(set(tags + ["SMS", "Nimbus SMS", "India"])) )) # Done here: @@ -243,6 +244,7 @@ class SMSController: http_client: httpx.AsyncClient, auth_token: CoreAuthTokenModel, messages: List[SavvyBulkSMSKenyaMessage], + tags: List[Any] ) -> SMSSendManyResults: # Start with a blank variable: @@ -286,7 +288,7 @@ class SMSController: message = client_response.model_dump(), snippet = message.text, aiSnippet = None, - tags = ["sms", "savvyBulkSmsKenya"] + tags = list(set(tags + ["SMS", "Savvy Bulk SMS", "Kenya"])) )) # Done here: @@ -297,7 +299,8 @@ class SMSController: mongo_conn: AsyncMongo, http_client: httpx.AsyncClient, auth_token: CoreAuthTokenModel, - messages: List[NimbusSMSIndiaMessage | SavvyBulkSMSKenyaMessage] + messages: List[NimbusSMSIndiaMessage | SavvyBulkSMSKenyaMessage], + tags: List[Any] ) -> SMSSendManyResults: # Start by assuming failure: @@ -309,13 +312,15 @@ class SMSController: send_results = await self.__send_from_nimbus_sms_india( http_client = http_client, auth_token = auth_token, - messages = messages + messages = messages, + tags = tags ) case "savvyBulkSmsKenya": send_results = await self.__send_from_savvy_bulk_sms_kenya( http_client = http_client, auth_token = auth_token, - messages = messages + messages = messages, + tags = tags ) case _: send_results.message = f"invalid client {auth_token.client}" diff --git a/controllers/core/auth_token.py b/controllers/core/auth_token.py index 638c8f2..0bf52cd 100644 --- a/controllers/core/auth_token.py +++ b/controllers/core/auth_token.py @@ -320,12 +320,14 @@ class CoreAuthTokenController(BaseModel): self, mongo_conn: AsyncMongo, token_ids: List[ObjectId | str] = None, + limit: int = 100 ) -> List[CoreAuthTokenModel]: """ To retrieve stored tokens from the database. Multiple tokens at a time. :param mongo_conn: The database connection (MongoDB) to use to perform the action. :param token_ids: The identifier of the document that holds the token's details. + :param limit: The max. no. of records to pick. :return: The retrieved record that has the token, and information about the service and client if found, else None when there is no matching record. """ @@ -333,7 +335,8 @@ class CoreAuthTokenController(BaseModel): # If there is some filtering possible, we fetch the token: tokens = await mongo_conn.find_many( collection = self.AUTH_COLLECTION, - filter = {"_id": {"$in": [ObjectId(k) for k in token_ids]}} + filter = {"_id": {"$in": [ObjectId(k) for k in token_ids]}}, + limit = limit ) # Done here: @@ -343,12 +346,14 @@ class CoreAuthTokenController(BaseModel): self, mongo_conn: AsyncMongo, token_keys: List[ObjectId | str] = None, + limit: int = 100 ) -> List[CoreAuthTokenModel]: """ To retrieve stored tokens from the database. Multiple tokens at a time. :param mongo_conn: The database connection (MongoDB) to use to perform the action. :param token_keys: the identifiers granted by the 'get_token_key' method. + :param limit: The max. no. of records to pick. :return: The retrieved record that has the token, and information about the service and client if found, else None when there is no matching record. """ @@ -356,7 +361,8 @@ class CoreAuthTokenController(BaseModel): # If there is some filtering possible, we fetch the token: tokens = await mongo_conn.find_many( collection = self.AUTH_COLLECTION, - filter = {"key": {"$in": [ObjectId(k) for k in token_keys]}} + filter = {"key": {"$in": [ObjectId(k) for k in token_keys]}}, + limit = limit ) # Done here: diff --git a/models/api/finstitutions/payments/list.py b/models/api/finstitutions/payments/list.py index 695bdac..aa73328 100644 --- a/models/api/finstitutions/payments/list.py +++ b/models/api/finstitutions/payments/list.py @@ -164,8 +164,9 @@ class PGPaymentListData(BaseModel): # ┗┛┗┻┗┗┗┻┗┻┗┗┗┛┛┗ @field_validator("tokenKeys", "tags", "paymentStatus", mode = "before") - def ensure_list(cls, value): + def ensure_unique_list(cls, value): if not isinstance(value, list): value = [value] + value = list(set(value)) return value diff --git a/models/api/mail/list.py b/models/api/mail/list.py index 6e9255b..1191c21 100644 --- a/models/api/mail/list.py +++ b/models/api/mail/list.py @@ -139,8 +139,9 @@ class MailListRequestData(BaseModel): # ┗┛┗┻┗┗┗┻┗┻┗┗┗┛┛┗ @field_validator("tokenKeys", "tags", mode = "before") - def ensure_list(cls, value): + def ensure_unique_list(cls, value): if not isinstance(value, list): value = [value] + value = list(set(value)) return value diff --git a/models/api/sms/send.py b/models/api/sms/send.py index eb58efd..bac373f 100644 --- a/models/api/sms/send.py +++ b/models/api/sms/send.py @@ -37,7 +37,7 @@ sys.path.append("..") # For making data behaviour_models: from pydantic import BaseModel, Field, field_validator, PastDatetime -from typing import Optional, Literal, Union, List +from typing import Optional, Literal, Union, List, Any # My utils: from utils_v2.string import regex @@ -179,6 +179,7 @@ class SMSSendRequestData(BaseModel): tokenKey: ObjectId = Field(description = "the auth token to use to send this message") message: List[NimbusSMSIndiaMessage] | List[SavvyBulkSMSKenyaMessage] + tags: List[Any] # ┏┓ ┏• # ┃ ┏┓┏┓╋┓┏┓ @@ -204,6 +205,10 @@ class SMSSendRequestData(BaseModel): if not isinstance(value, list): value = [value] return value + @field_validator("tags", mode = "before") + def null_to_list(cls, value): + return [] if value is None else value + # ---------------------------------------------------------------------------------------------------------------------