(20250123) Made a common API to disable all integrations.

This commit is contained in:
2025-01-23 12:29:03 +05:30
parent 816789fce5
commit fe48b79c09
20 changed files with 663 additions and 36 deletions
View File
+205
View File
@@ -0,0 +1,205 @@
"""
AUTHOR:
Khushal P Soonderji
DATE:
Thursday, 23rd Jan., 2025.
OBJECTIVE:
To disable chat accounts.
REFERENCES:
N/A
DOWNLOADS:
N/A
NOTES:
N/A
"""
# *****************************************************************************************************************
# ***** ****
# *** IMPORT ***
# ***** ****
# *****************************************************************************************************************
# To make sibling directories accessible for imports:
import sys
sys.path.append(".")
sys.path.append("..")
# For using Quart:
from quart import Blueprint, current_app, request
# My utils:
from utils_v2.string import json
from utils_v2.api.codes import StatusCodes, HttpCodes
from utils_v2.api.response import ResponseModel
from utils_v2.api.async_quart import (
set_api_version,
read_input,
get_session_info,
log_request_to_mongo,
log_chain_to_mongo,
should_not_be_under_maintenance,
only_whitelisted_ips,
limit_rate,
validate_input,
handle_cancelled_request
)
# Common:
from shared import constants
# Data Models:
from models.core.user import CoreUserInfoModel
from models.api.common.auth_disable import AuthTokenDisableRequestHeaders, AuthTokenDisableRequestData
# Helpers:
from api.helpers.user import token_check
# To work with MongoDB:
from bson import ObjectId
# For asynchronous activities:
import asyncio
# *****************************************************************************************************************
# ***** ****
# *** MACROS / ONE-TIME INIT ***
# ***** ****
# *****************************************************************************************************************
# Related to Quart:
auth_token_disable_bp = Blueprint("auth_token_dsbl", __name__)
# *****************************************************************************************************************
# ***** ****
# *** VARIABLES ***
# ***** ****
# *****************************************************************************************************************
# --- Nothing Yet
# *****************************************************************************************************************
# ***** ****
# *** FUNCTIONS ***
# ***** ****
# *****************************************************************************************************************
@auth_token_disable_bp.record_once
def init(blueprint_setup_state):
# This gets called when the blueprint is registered.
# Consider this to be a one-time setup for the whole blueprint:
pass
# ---------------------------------------------------------------------------------------------------------------------
@auth_token_disable_bp.route("/auth", methods = ["DELETE"])
@auth_token_disable_bp.route("/integration/auth", methods = ["DELETE"])
@set_api_version(api_version = "1.0.0")
@read_input(sanitize_headers = False, sanitize_data = False)
@get_session_info(key = "X-Session-Token", session_coro = "get_session")
@log_request_to_mongo(
attr_name = "logs_mongo",
project = constants.PROJECT_NAME,
log_type = constants.MODULE_NAME,
operation = "authTokDsblApi",
log_input = True,
log_output = True,
sensitive_keys = ["sessionToken", "X-Session-Token", "tokenKey"]
)
@log_chain_to_mongo(attr_name = "logs_mongo")
@should_not_be_under_maintenance(attr_name = "is_under_maintenance")
@validate_input(
header_validator = lambda x: AuthTokenDisableRequestHeaders(**x).model_dump(),
data_validator = lambda x: AuthTokenDisableRequestData(**x)
)
@handle_cancelled_request()
async def disable_auth_token(
inbound_headers: dict | AuthTokenDisableRequestHeaders = None,
inbound_data: dict | AuthTokenDisableRequestData = None,
inbound_files: dict = None,
**kwargs
):
"""
Use this when a user wants to remove/disable his account.
:param inbound_headers: auto-extracted by the decorators.
:param inbound_data: auto-extracted by the decorators.
:param inbound_files: auto-extracted by the decorators.
:param kwargs: Any number of extra inputs supplied by the decorators.
:return: A standard response structure.
"""
# ┏┓ ┓ ┏┓┓ ┓
# ┣┫┓┏╋┣┓ ┃ ┣┓┏┓┏┃┏
# ┛┗┗┻┗┛┗ ┗┛┛┗┗ ┗┛┗
# If the session token is invalid/expired:
if kwargs.get("session_info") is None:
return ResponseModel(
status_code = StatusCodes.FAILED,
http_code = HttpCodes.UNAUTHORIZED
)
# Get the user's info:
user_info = CoreUserInfoModel(**kwargs.get("session_info"))
# ┳┳┓ ┓•┏ ┏┓
# ┃┃┃┏┓┏┫┓╋┓┏ ┗┓╋┏┓╋┓┏┏
# ┛ ┗┗┛┗┻┗┛┗┫ ┗┛┗┗┻┗┗┻┛
# ┛
# Update the message:
success = await current_app.core_auth_token_controller.modify_status_by_token_key(
sql_conn = current_app.sql_writer,
mongo_data_conn = current_app.data_mongo,
token_key = inbound_data.tokenKey,
new_status = "disabled",
additional_filter = token_check.get_authorization_filter(user_info = user_info),
session_token = inbound_headers["X-Session-Token"]
)
# ┳┓
# ┣┫┏┓┏┏┓┏┓┏┓┏┏┓
# ┛┗┗ ┛┣┛┗┛┛┗┛┗
# ┛
# Done here:
return ResponseModel(
status_code = StatusCodes.OK if success else StatusCodes.FAILED,
http_code = HttpCodes.SUCCESS if success else HttpCodes.INTERNAL_SERVER_ERROR
)
# *****************************************************************************************************************
# ***** ****
# *** MAIN PROGRAM ***
# ***** ****
# *****************************************************************************************************************
if __name__ == "__main__":
pass
+19
View File
@@ -153,6 +153,25 @@ async def is_not_authorized(
return not authorized return not authorized
# ---------------------------------------------------------------------------------------------------------------------
def get_authorization_filter(user_info: CoreUserInfoModel) -> dict:
"""
Just returns a MongoDB query filter that can be sent as an 'additional_filter' to various methods to ensure that the
user requesting the service and the user that has rights over the resource are matching.
:param user_info: The information of the user obtained from the session.
:return: A filter condition.
"""
return AsyncMongo.dict_to_dot_notation({
"user": {
"billingAccountId": user_info.billingAccountId
}
})
# ***************************************************************************************************************** # *****************************************************************************************************************
# ***** **** # ***** ****
# *** MAIN PROGRAM *** # *** MAIN PROGRAM ***
+6
View File
@@ -144,6 +144,9 @@ from api.blueprints.finstitutions.trading.symbols.list import trading_symbols_li
# AI Blueprints: # AI Blueprints:
from api.blueprints.ai.llm.invoke import llm_invoke_bp from api.blueprints.ai.llm.invoke import llm_invoke_bp
# Common Blueprints:
from api.blueprints.common.disable import auth_token_disable_bp
# Tech and Testing Blueprints: # Tech and Testing Blueprints:
from api.blueprints.tech.chat_alerts import tech_chat_alert_bp from api.blueprints.tech.chat_alerts import tech_chat_alert_bp
from api.blueprints.test.callback import test_callback_bp from api.blueprints.test.callback import test_callback_bp
@@ -213,6 +216,9 @@ app.register_blueprint(trading_oauth_request_bp, url_prefix = f"/{MODULE_BASE}/f
app.register_blueprint(trading_oauth_callback_bp, url_prefix = f"/{MODULE_BASE}/finstitutions/trading/oauth") app.register_blueprint(trading_oauth_callback_bp, url_prefix = f"/{MODULE_BASE}/finstitutions/trading/oauth")
app.register_blueprint(trading_symbols_list_bp, url_prefix = f"/{MODULE_BASE}/finstitutions/trading/symbols") app.register_blueprint(trading_symbols_list_bp, url_prefix = f"/{MODULE_BASE}/finstitutions/trading/symbols")
# Common Blueprints:
app.register_blueprint(auth_token_disable_bp, url_prefix = f"/{MODULE_BASE}")
# AI Blueprints: # AI Blueprints:
app.register_blueprint(llm_invoke_bp, url_prefix = f"/{MODULE_BASE}/ai") app.register_blueprint(llm_invoke_bp, url_prefix = f"/{MODULE_BASE}/ai")
+56 -6
View File
@@ -48,7 +48,7 @@ from controllers_v2.core.base import CoreBaseModel
from models.core.auth_token import CoreAuthTokenModel from models.core.auth_token import CoreAuthTokenModel
# To work with datatypes: # To work with datatypes:
from typing import List from typing import List, Literal
# To make API calls: # To make API calls:
import httpx import httpx
@@ -210,6 +210,8 @@ class CoreAuthTokenController(CoreBaseModel):
"authType": auth_token.authType, "authType": auth_token.authType,
"user": auth_token.user.model_dump(), "user": auth_token.user.model_dump(),
"clientUserId": auth_token.clientUserId, "clientUserId": auth_token.clientUserId,
"clientDisplayName": auth_token.clientDisplayName,
"clientDisplayPicture": auth_token.clientDisplayPicture,
"auth": auth_token.auth, "auth": auth_token.auth,
"token": auth_token.token, "token": auth_token.token,
"firstRefreshTs": auth_token.firstRefreshTs, "firstRefreshTs": auth_token.firstRefreshTs,
@@ -258,6 +260,7 @@ class CoreAuthTokenController(CoreBaseModel):
token_notes: dict, token_notes: dict,
display_name: str = None, display_name: str = None,
display_picture: str = None, display_picture: str = None,
last_action: Literal["Auth Requested", "Auth Granted", "Auth Revoked"] = "Auth Granted",
session_token: str = None session_token: str = None
) -> bool: ) -> bool:
@@ -272,6 +275,7 @@ class CoreAuthTokenController(CoreBaseModel):
:param token_notes: Any notes to feed into MariaDB with the token identifier. :param token_notes: Any notes to feed into MariaDB with the token identifier.
:param display_name: The name of the user to user as their display name. :param display_name: The name of the user to user as their display name.
:param display_picture: The URL at which you will find a display picture of the user. :param display_picture: The URL at which you will find a display picture of the user.
:param last_action: A string to show what action was taken last.
:param session_token: The session token of the user who requested this service. :param session_token: The session token of the user who requested this service.
:return: True if saved, False if failed. :return: True if saved, False if failed.
""" """
@@ -301,6 +305,8 @@ class CoreAuthTokenController(CoreBaseModel):
"auth": auth_token.auth, "auth": auth_token.auth,
"token": auth_token.token, "token": auth_token.token,
"status": auth_token.status, "status": auth_token.status,
"clientDisplayName": auth_token.clientDisplayName,
"clientDisplayPicture": auth_token.clientDisplayPicture,
"lastRefreshTs": request_ts, "lastRefreshTs": request_ts,
"firstRefreshTs": { "firstRefreshTs": {
"$cond": { "$cond": {
@@ -331,7 +337,7 @@ class CoreAuthTokenController(CoreBaseModel):
mongo_json["user"]["billingAccountId"], # ............................... 'p_billing_account_id' mongo_json["user"]["billingAccountId"], # ............................... 'p_billing_account_id'
mongo_json["client"], # ................................................. 'p_provider' mongo_json["client"], # ................................................. 'p_provider'
auth_token.status, # .................................................... 'p_current_status' auth_token.status, # .................................................... 'p_current_status'
"Auth Granted", # ....................................................... 'p_last_action' last_action or "Auth Granted", # ........................................ 'p_last_action'
display_name, # ......................................................... 'p_display_name' display_name, # ......................................................... 'p_display_name'
display_picture, # ...................................................... 'p_display_picture' display_picture, # ...................................................... 'p_display_picture'
token_key, # ............................................................ 'p_token_id' token_key, # ............................................................ 'p_token_id'
@@ -398,14 +404,55 @@ class CoreAuthTokenController(CoreBaseModel):
# Done here: # Done here:
return success return success
async def modify_status( async def modify_status_by_token_key(
self, self,
sql_conn: AsyncMySQL, sql_conn: AsyncMySQL,
mongo_data_conn: AsyncMongo, mongo_data_conn: AsyncMongo,
auth_token: CoreAuthTokenModel, token_key: str | ObjectId,
): new_status: Literal["pending", "active", "disabled"],
additional_filter: dict = None,
session_token: str = None
) -> bool:
pass """
This is to simply modify the status of an account to efficiently activate/deactivate it.
NOTE: The operation succeeds ONLY IF the new status of the account is different from the existing status.
:param sql_conn: The database connection (MariaDB) to use to perform the action.
:param mongo_data_conn: The database connection (MongoDB) to use to perform the action.
:param token_key: The identifier granted by the 'generate_token_key' method.
:param new_status: Whatever you want the new status to be.
:param additional_filter: Any addition filters to use.
:param session_token: The session token of the user who requested this service.
:return: True if successful, else False.
"""
# Fetch the token from the key:
additional_filter = additional_filter or {}
# additional_filter["status"] = {"$ne": new_status}
if self._service_type is not None: additional_filter["serviceType"] = self._service_type
if self._client is not None: additional_filter["client"] = self._client
auth_token = await self.get_token_from_key(
mongo_data_conn = mongo_data_conn,
token_key = token_key,
additional_filter = additional_filter
)
# If there is not matching auth-token:
if not auth_token: return False
# Now we modify the status and return the result:
auth_token.status = new_status
return await self.set_token(
sql_conn = sql_conn,
mongo_data_conn = mongo_data_conn,
token_key = token_key,
auth_token = auth_token,
token_notes = {},
display_name = auth_token.clientDisplayName,
display_picture = auth_token.clientDisplayPicture,
last_action = "Auth Revoked",
session_token = session_token
)
# ┏┓┳┓┳┳┳┓ ┳┓ • # ┏┓┳┓┳┳┳┓ ┳┓ •
# ┃ ┣┫┃┃┃┃ ━━ ┣┫┏┓╋┏┓┓┏┓┓┏┏┓ # ┃ ┣┫┃┃┃┃ ━━ ┣┫┏┓╋┏┓┓┏┓┓┏┏┓
@@ -597,6 +644,9 @@ class CoreAuthTokenController(CoreBaseModel):
batch_timeout_ts = now - datetime.timedelta(seconds = int(batch_timeout_seconds)) batch_timeout_ts = now - datetime.timedelta(seconds = int(batch_timeout_seconds))
filter_json = { filter_json = {
"$and": [ "$and": [
{
"status": "active", # ... The account must be active.
},
{ {
"$or": [ "$or": [
{"syncAfterTs": None}, # ............ The time after which sync'ing is allowed is null. {"syncAfterTs": None}, # ............ The time after which sync'ing is allowed is null.
+8 -5
View File
@@ -98,6 +98,12 @@ from abc import ABC, abstractmethod
class TradingController(CoreAuthTokenController, ABC): class TradingController(CoreAuthTokenController, ABC):
# ┏┓┓ ┓┏
# ┃ ┃┏┓┏┏ ┃┃┏┓┏┓┏
# ┗┛┗┗┻┛┛ ┗┛┗┻┛ ┛
SERVICE_TYPE = "stockTrading"
# ┏┓ # ┏┓
# ┃ ┏┓┏┓┏╋┏┓┓┏┏╋┏┓┏┓ # ┃ ┏┓┏┓┏╋┏┓┓┏┏╋┏┓┏┓
# ┗┛┗┛┛┗┛┗┛ ┗┻┗┗┗┛┛ # ┗┛┗┛┛┗┛┗┛ ┗┻┗┗┗┛┛
@@ -126,13 +132,10 @@ class TradingController(CoreAuthTokenController, ABC):
:return: None. :return: None.
""" """
# Declare the service type:
this_service_type = "stockTrading"
# Prepare base filter: # Prepare base filter:
this_filter = {} this_filter = {}
for k, v in (base_filter or {}).items(): this_filter[k] = v for k, v in (base_filter or {}).items(): this_filter[k] = v
this_filter["serviceType"] = this_service_type this_filter["serviceType"] = self.SERVICE_TYPE
# Invoke the parent's constructor: # Invoke the parent's constructor:
CoreAuthTokenController.__init__( CoreAuthTokenController.__init__(
@@ -147,7 +150,7 @@ class TradingController(CoreAuthTokenController, ABC):
) )
# Init a variable in a parent: # Init a variable in a parent:
self._service_type = this_service_type self._service_type = self.SERVICE_TYPE
# ┏┓ ┓ # ┏┓ ┓
# ┣┫┓┏╋┣┓ # ┣┫┓┏╋┣┓
@@ -137,11 +137,8 @@ class ICICIBreezeTradingController(TradingController):
:return: None. :return: None.
""" """
# Declare the client:
this_client = self.CLIENT_NAME
# Prepare base filter: # Prepare base filter:
this_filter = {"client": this_client} this_filter = {"client": self.CLIENT_NAME}
# Invoke the parent's constructor: # Invoke the parent's constructor:
super().__init__( super().__init__(
@@ -155,7 +152,7 @@ class ICICIBreezeTradingController(TradingController):
) )
# Init a variable in a parent: # Init a variable in a parent:
self._client = this_client self._client = self.CLIENT_NAME
# ┏┓ ┓ # ┏┓ ┓
# ┣┫┓┏╋┣┓ # ┣┫┓┏╋┣┓
@@ -136,11 +136,8 @@ class PaperTradingController(TradingController):
:return: None. :return: None.
""" """
# Declare the client:
this_client = self.CLIENT_NAME
# Prepare base filter: # Prepare base filter:
this_filter = {"client": this_client} this_filter = {"client": self.CLIENT_NAME}
# Invoke the parent's constructor: # Invoke the parent's constructor:
super().__init__( super().__init__(
@@ -154,7 +151,7 @@ class PaperTradingController(TradingController):
) )
# Init a variable in a parent: # Init a variable in a parent:
self._client = this_client self._client = self.CLIENT_NAME
# ┏┓ ┓ # ┏┓ ┓
# ┣┫┓┏╋┣┓ # ┣┫┓┏╋┣┓
@@ -136,11 +136,8 @@ class ZerodhaKiteTradingController(TradingController):
:return: None. :return: None.
""" """
# Declare the client:
this_client = self.CLIENT_NAME
# Prepare base filter: # Prepare base filter:
this_filter = {"client": this_client} this_filter = {"client": self.CLIENT_NAME}
# Invoke the parent's constructor: # Invoke the parent's constructor:
super().__init__( super().__init__(
@@ -154,7 +151,7 @@ class ZerodhaKiteTradingController(TradingController):
) )
# Init a variable in a parent: # Init a variable in a parent:
self._client = this_client self._client = self.CLIENT_NAME
# ┏┓ ┓ # ┏┓ ┓
# ┣┫┓┏╋┣┓ # ┣┫┓┏╋┣┓
+10 -1
View File
@@ -106,6 +106,12 @@ from abc import ABC, abstractmethod
class ChatController(CoreMessageController, ABC): class ChatController(CoreMessageController, ABC):
# ┏┓┓ ┓┏
# ┃ ┃┏┓┏┏ ┃┃┏┓┏┓┏
# ┗┛┗┗┻┛┛ ┗┛┗┻┛ ┛
SERVICE_TYPE = "chat"
# ┏┓ # ┏┓
# ┃ ┏┓┏┓┏╋┏┓┓┏┏╋┏┓┏┓ # ┃ ┏┓┏┓┏╋┏┓┓┏┏╋┏┓┏┓
# ┗┛┗┛┛┗┛┗┛ ┗┻┗┗┗┛┛ # ┗┛┗┛┛┗┛┗┛ ┗┻┗┗┗┛┛
@@ -137,7 +143,7 @@ class ChatController(CoreMessageController, ABC):
# Prepare the combined base filter: # Prepare the combined base filter:
sms_filter = {} sms_filter = {}
for k, v in (base_filter or {}).items(): sms_filter[k] = v for k, v in (base_filter or {}).items(): sms_filter[k] = v
sms_filter["serviceType"] = "chat" sms_filter["serviceType"] = self.SERVICE_TYPE
# Invoke the parent's constructor: # Invoke the parent's constructor:
CoreMessageController.__init__( CoreMessageController.__init__(
@@ -151,6 +157,9 @@ class ChatController(CoreMessageController, ABC):
debug_only_errors = debug_only_errors debug_only_errors = debug_only_errors
) )
# Init a variable in a parent:
self._service_type = self.SERVICE_TYPE
# ┏┓ ┓ ┳┳┓ # ┏┓ ┓ ┳┳┓
# ┗┓┏┓┏┓┏┫ ┃┃┃┏┓┏┏┏┓┏┓┏┓┏ # ┗┓┏┓┏┓┏┫ ┃┃┃┏┓┏┏┏┓┏┓┏┓┏
# ┗┛┗ ┛┗┗┻ ┛ ┗┗ ┛┛┗┻┗┫┗ ┛ # ┗┛┗ ┛┗┗┻ ┛ ┗┗ ┛┛┗┻┗┫┗ ┛
+10 -1
View File
@@ -105,6 +105,12 @@ import asyncio
class WhatsAppNimbusController(ChatController): class WhatsAppNimbusController(ChatController):
# ┏┓┓ ┓┏
# ┃ ┃┏┓┏┏ ┃┃┏┓┏┓┏
# ┗┛┗┗┻┛┛ ┗┛┗┻┛ ┛
CLIENT_NAME = "gmail"
# ┏┓ # ┏┓
# ┃ ┏┓┏┓┏╋┏┓┓┏┏╋┏┓┏┓ # ┃ ┏┓┏┓┏╋┏┓┓┏┏╋┏┓┏┓
# ┗┛┗┛┛┗┛┗┛ ┗┻┗┗┗┛┛ # ┗┛┗┛┛┗┛┗┛ ┗┻┗┗┗┛┛
@@ -134,12 +140,15 @@ class WhatsAppNimbusController(ChatController):
cache = cache, cache = cache,
alert_url = alert_url, alert_url = alert_url,
http_client = http_client, http_client = http_client,
base_filter = {"client": "whatsappNimbus"}, base_filter = {"client": self.CLIENT_NAME},
debug = debug, debug = debug,
debug_prefix = debug_prefix, debug_prefix = debug_prefix,
debug_only_errors = debug_only_errors debug_only_errors = debug_only_errors
) )
# Init a variable in a parent:
self._client = self.CLIENT_NAME
# ┏┓ ┓ ┳┳┓ # ┏┓ ┓ ┳┳┓
# ┗┓┏┓┏┓┏┫ ┃┃┃┏┓┏┏┏┓┏┓┏┓┏ # ┗┓┏┓┏┓┏┫ ┃┃┃┏┓┏┏┏┓┏┓┏┓┏
# ┗┛┗ ┛┗┗┻ ┛ ┗┗ ┛┛┗┻┗┫┗ ┛ # ┗┛┗ ┛┗┗┻ ┛ ┗┗ ┛┛┗┻┗┫┗ ┛
+9 -4
View File
@@ -119,9 +119,11 @@ from abc import ABC, abstractmethod
class MailController(CoreMessageController, ABC): class MailController(CoreMessageController, ABC):
# ┏┓┓ ┓┏ • ┓ ┓ # ┏┓┓ ┓┏
# ┃ ┃┏┓┏┏ ┃┃┏┓┏┓┓┏┓┣┓┃┏┓ # ┃ ┃┏┓┏┏ ┃┃┏┓┏┓┏
# ┗┛┗┗┻┛┛ ┗┛┗┻┛ ┗┗┻┗┛┗┗ # ┗┛┗┗┻┛┛ ┗┛┗┻┛ ┛
SERVICE_TYPE = "email"
# For AI Magic through LLMs: # For AI Magic through LLMs:
RECEIVED_MAIL_SUMMARIZATION_PROMPT_TEMPLATE = [ RECEIVED_MAIL_SUMMARIZATION_PROMPT_TEMPLATE = [
@@ -189,7 +191,7 @@ class MailController(CoreMessageController, ABC):
# Prepare the combined base filter: # Prepare the combined base filter:
sms_filter = {} sms_filter = {}
for k, v in (base_filter or {}).items(): sms_filter[k] = v for k, v in (base_filter or {}).items(): sms_filter[k] = v
sms_filter["serviceType"] = "email" sms_filter["serviceType"] = self.SERVICE_TYPE
# Invoke the parents' constructor: # Invoke the parents' constructor:
CoreMessageController.__init__( CoreMessageController.__init__(
@@ -203,6 +205,9 @@ class MailController(CoreMessageController, ABC):
debug_only_errors = debug_only_errors debug_only_errors = debug_only_errors
) )
# Init a variable in a parent:
self._service_type = self.SERVICE_TYPE
# ┓┏ ┓ # ┓┏ ┓
# ┣┫┏┓┃┏┓┏┓┏┓┏ # ┣┫┏┓┃┏┓┏┓┏┓┏
# ┛┗┗ ┗┣┛┗ ┛ ┛ # ┛┗┗ ┗┣┛┗ ┛ ┛
+10 -1
View File
@@ -127,6 +127,12 @@ import asyncio
class GmailController(MailController): class GmailController(MailController):
# ┏┓┓ ┓┏
# ┃ ┃┏┓┏┏ ┃┃┏┓┏┓┏
# ┗┛┗┗┻┛┛ ┗┛┗┻┛ ┛
CLIENT_NAME = "gmail"
# ┏┓ # ┏┓
# ┃ ┏┓┏┓┏╋┏┓┓┏┏╋┏┓┏┓ # ┃ ┏┓┏┓┏╋┏┓┓┏┏╋┏┓┏┓
# ┗┛┗┛┛┗┛┗┛ ┗┻┗┗┗┛┛ # ┗┛┗┛┛┗┛┗┛ ┗┻┗┗┗┛┛
@@ -156,12 +162,15 @@ class GmailController(MailController):
cache = cache, cache = cache,
alert_url = alert_url, alert_url = alert_url,
http_client = http_client, http_client = http_client,
base_filter = {"client": "gmail"}, base_filter = {"client": self.CLIENT_NAME},
debug = debug, debug = debug,
debug_prefix = debug_prefix, debug_prefix = debug_prefix,
debug_only_errors = debug_only_errors debug_only_errors = debug_only_errors
) )
# Init a variable in a parent:
self._client = self.CLIENT_NAME
# ┏┓┏┓ ┓ ┏┓ ┏┓ # ┏┓┏┓ ┓ ┏┓ ┏┓
# ┃┃┣┫┓┏╋┣┓┏┛ ┃┫ # ┃┃┣┫┓┏╋┣┓┏┛ ┃┫
# ┗┛┛┗┗┻┗┛┗┗━•┗┛ # ┗┛┛┗┗┻┗┛┗┗━•┗┛
+10 -1
View File
@@ -107,6 +107,12 @@ from abc import ABC, abstractmethod
class SMSController(CoreMessageController, ABC): class SMSController(CoreMessageController, ABC):
# ┏┓┓ ┓┏
# ┃ ┃┏┓┏┏ ┃┃┏┓┏┓┏
# ┗┛┗┗┻┛┛ ┗┛┗┻┛ ┛
SERVICE_TYPE = "sms"
# ┏┓ # ┏┓
# ┃ ┏┓┏┓┏╋┏┓┓┏┏╋┏┓┏┓ # ┃ ┏┓┏┓┏╋┏┓┓┏┏╋┏┓┏┓
# ┗┛┗┛┛┗┛┗┛ ┗┻┗┗┗┛┛ # ┗┛┗┛┛┗┛┗┛ ┗┻┗┗┗┛┛
@@ -138,7 +144,7 @@ class SMSController(CoreMessageController, ABC):
# Prepare the combined base filter: # Prepare the combined base filter:
sms_filter = {} sms_filter = {}
for k, v in (base_filter or {}).items(): sms_filter[k] = v for k, v in (base_filter or {}).items(): sms_filter[k] = v
sms_filter["serviceType"] = "sms" sms_filter["serviceType"] = self.SERVICE_TYPE
# Invoke the parent's constructor: # Invoke the parent's constructor:
CoreMessageController.__init__( CoreMessageController.__init__(
@@ -152,6 +158,9 @@ class SMSController(CoreMessageController, ABC):
debug_only_errors = debug_only_errors debug_only_errors = debug_only_errors
) )
# Init a variable in a parent:
self._service_type = self.SERVICE_TYPE
# ┏┓┳┳┓┏┓ ┏┓ ┓• # ┏┓┳┳┓┏┓ ┏┓ ┓•
# ┗┓┃┃┃┗┓ ┗┓┏┓┏┓┏┫┓┏┓┏┓ # ┗┓┃┃┃┗┓ ┗┓┏┓┏┓┏┫┓┏┓┏┓
# ┗┛┛ ┗┗┛ ┗┛┗ ┛┗┗┻┗┛┗┗┫ # ┗┛┛ ┗┗┛ ┗┛┗ ┛┗┗┻┗┛┗┗┫
+10 -1
View File
@@ -105,6 +105,12 @@ import asyncio
class NimbusSMSIndiaController(SMSController): class NimbusSMSIndiaController(SMSController):
# ┏┓┓ ┓┏
# ┃ ┃┏┓┏┏ ┃┃┏┓┏┓┏
# ┗┛┗┗┻┛┛ ┗┛┗┻┛ ┛
CLIENT_NAME = "nimbusSmsIndia"
# ┏┓ # ┏┓
# ┃ ┏┓┏┓┏╋┏┓┓┏┏╋┏┓┏┓ # ┃ ┏┓┏┓┏╋┏┓┓┏┏╋┏┓┏┓
# ┗┛┗┛┛┗┛┗┛ ┗┻┗┗┗┛┛ # ┗┛┗┛┛┗┛┗┛ ┗┻┗┗┗┛┛
@@ -135,12 +141,15 @@ class NimbusSMSIndiaController(SMSController):
cache = cache, cache = cache,
alert_url = alert_url, alert_url = alert_url,
http_client = http_client, http_client = http_client,
base_filter = {"client": "nimbusSmsIndia"}, base_filter = {"client": self.CLIENT_NAME},
debug = debug, debug = debug,
debug_prefix = debug_prefix, debug_prefix = debug_prefix,
debug_only_errors = debug_only_errors debug_only_errors = debug_only_errors
) )
# Init a variable in a parent:
self._client = self.CLIENT_NAME
# ┏┓┳┳┓┏┓ ┏┓ ┓• # ┏┓┳┳┓┏┓ ┏┓ ┓•
# ┗┓┃┃┃┗┓ ┗┓┏┓┏┓┏┫┓┏┓┏┓ # ┗┓┃┃┃┗┓ ┗┓┏┓┏┓┏┫┓┏┓┏┓
# ┗┛┛ ┗┗┛ ┗┛┗ ┛┗┗┻┗┛┗┗┫ # ┗┛┛ ┗┗┛ ┗┛┗ ┛┗┗┻┗┛┗┗┫
@@ -105,6 +105,12 @@ import asyncio
class SavvyBulkSMSKenyaController(SMSController): class SavvyBulkSMSKenyaController(SMSController):
# ┏┓┓ ┓┏
# ┃ ┃┏┓┏┏ ┃┃┏┓┏┓┏
# ┗┛┗┗┻┛┛ ┗┛┗┻┛ ┛
CLIENT_NAME = "savvyBulkSmsKenya"
# ┏┓ # ┏┓
# ┃ ┏┓┏┓┏╋┏┓┓┏┏╋┏┓┏┓ # ┃ ┏┓┏┓┏╋┏┓┓┏┏╋┏┓┏┓
# ┗┛┗┛┛┗┛┗┛ ┗┻┗┗┗┛┛ # ┗┛┗┛┛┗┛┗┛ ┗┻┗┗┗┛┛
@@ -135,12 +141,15 @@ class SavvyBulkSMSKenyaController(SMSController):
cache = cache, cache = cache,
alert_url = alert_url, alert_url = alert_url,
http_client = http_client, http_client = http_client,
base_filter = {"client": "savvyBulkSmsKenya"}, base_filter = {"client": self.CLIENT_NAME},
debug = debug, debug = debug,
debug_prefix = debug_prefix, debug_prefix = debug_prefix,
debug_only_errors = debug_only_errors debug_only_errors = debug_only_errors
) )
# Init a variable in a parent:
self._client = self.CLIENT_NAME
# ┏┓┳┳┓┏┓ ┏┓ ┓• # ┏┓┳┳┓┏┓ ┏┓ ┓•
# ┗┓┃┃┃┗┓ ┗┓┏┓┏┓┏┫┓┏┓┏┓ # ┗┓┃┃┃┗┓ ┗┓┏┓┏┓┏┫┓┏┓┏┓
# ┗┛┛ ┗┗┛ ┗┛┗ ┛┗┗┻┗┛┗┗┫ # ┗┛┛ ┗┗┛ ┗┛┗ ┛┗┗┻┗┛┗┗┫
View File
+141
View File
@@ -0,0 +1,141 @@
"""
AUTHOR:
Khushal P Soonderji
DATE:
Thursday, 23rd Jan., 2025.
OBJECTIVE:
To provide a structure to allow users to disable their third-party integration accounts.
REFERENCES:
N/A
DOWNLOADS:
N/A
"""
# *****************************************************************************************************************
# ***** ****
# *** IMPORT ***
# ***** ****
# *****************************************************************************************************************
# To make sibling directories accessible for imports:
import sys
sys.path.append(".")
sys.path.append("..")
# For making data behaviour_models:
from pydantic import BaseModel, Field, field_validator, PastDatetime
from typing import Optional, Literal, List, Any
# My utils:
from utils_v2.string import regex
from utils_v2.date_time import date_time
# To work with MongoDB:
from bson.objectid import ObjectId
# To work with date and time:
import datetime
# *****************************************************************************************************************
# ***** ****
# *** MACROS / ONE-TIME INIT ***
# ***** ****
# *****************************************************************************************************************
# RegEx Patterns:
REGEX_SESSION_TOKEN = r"^[a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$"
# *****************************************************************************************************************
# ***** ****
# *** VARIABLES ***
# ***** ****
# *****************************************************************************************************************
# --- Nothing Yet
# *****************************************************************************************************************
# ***** ****
# *** FUNCTIONS ***
# ***** ****
# *****************************************************************************************************************
class AuthTokenDisableRequestHeaders(BaseModel):
sessionToken: str = Field(
description = "The session token of the user who is requesting the service.",
pattern = REGEX_SESSION_TOKEN,
frozen = True,
alias = "X-Session-Token"
)
# ┏┓ ┏•
# ┃ ┏┓┏┓╋┓┏┓
# ┗┛┗┛┛┗┛┗┗┫
# ┛
class Config:
extra = "allow"
def model_dump(self, *args, **kwargs):
return super().model_dump(*args, by_alias = True, **kwargs)
# ---------------------------------------------------------------------------------------------------------------------
class AuthTokenDisableRequestData(BaseModel):
tokenKey: ObjectId = Field(
description = "The token identifier that tell you which account needs to be disabled.",
frozen = True,
)
# ┏┓ ┏•
# ┃ ┏┓┏┓╋┓┏┓
# ┗┛┗┛┛┗┛┗┗┫
# ┛
class Config:
extra = "forbid"
arbitrary_types_allowed = True
# ┓┏ ┓• ┓ •
# ┃┃┏┓┃┓┏┫┏┓╋┓┏┓┏┓
# ┗┛┗┻┗┗┗┻┗┻┗┗┗┛┛┗
@field_validator("tokenKey", mode = "before")
def parse_oid(cls, value):
try: value = ObjectId(value)
except: value = None
return value
# *****************************************************************************************************************
# ***** ****
# *** MAIN PROGRAM ***
# ***** ****
# *****************************************************************************************************************
if __name__ == "__main__":
pass
+141
View File
@@ -0,0 +1,141 @@
"""
AUTHOR:
Khushal P Soonderji
DATE:
Thursday, 23rd Jan., 2025.
OBJECTIVE:
To provide a structure to allow users to disable their third-party integration accounts.
REFERENCES:
N/A
DOWNLOADS:
N/A
"""
# *****************************************************************************************************************
# ***** ****
# *** IMPORT ***
# ***** ****
# *****************************************************************************************************************
# To make sibling directories accessible for imports:
import sys
sys.path.append(".")
sys.path.append("..")
# For making data behaviour_models:
from pydantic import BaseModel, Field, field_validator, PastDatetime
from typing import Optional, Literal, List, Any
# My utils:
from utils_v2.string import regex
from utils_v2.date_time import date_time
# To work with MongoDB:
from bson.objectid import ObjectId
# To work with date and time:
import datetime
# *****************************************************************************************************************
# ***** ****
# *** MACROS / ONE-TIME INIT ***
# ***** ****
# *****************************************************************************************************************
# RegEx Patterns:
REGEX_SESSION_TOKEN = r"^[a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$"
# *****************************************************************************************************************
# ***** ****
# *** VARIABLES ***
# ***** ****
# *****************************************************************************************************************
# --- Nothing Yet
# *****************************************************************************************************************
# ***** ****
# *** FUNCTIONS ***
# ***** ****
# *****************************************************************************************************************
class ChatAuthDisableRequestHeaders(BaseModel):
sessionToken: str = Field(
description = "The session token of the user who is requesting the service.",
pattern = REGEX_SESSION_TOKEN,
frozen = True,
alias = "X-Session-Token"
)
# ┏┓ ┏•
# ┃ ┏┓┏┓╋┓┏┓
# ┗┛┗┛┛┗┛┗┗┫
# ┛
class Config:
extra = "allow"
def model_dump(self, *args, **kwargs):
return super().model_dump(*args, by_alias = True, **kwargs)
# ---------------------------------------------------------------------------------------------------------------------
class ChatAuthDisableRequestData(BaseModel):
tokenKey: ObjectId = Field(
description = "The token identifier that tell you which account needs to be disabled.",
frozen = True,
)
# ┏┓ ┏•
# ┃ ┏┓┏┓╋┓┏┓
# ┗┛┗┛┛┗┛┗┗┫
# ┛
class Config:
extra = "forbid"
arbitrary_types_allowed = True
# ┓┏ ┓• ┓ •
# ┃┃┏┓┃┓┏┫┏┓╋┓┏┓┏┓
# ┗┛┗┻┗┗┗┻┗┻┗┗┗┛┛┗
@field_validator("tokenKey", mode = "before")
def parse_oid(cls, value):
try: value = ObjectId(value)
except: value = None
return value
# *****************************************************************************************************************
# ***** ****
# *** MAIN PROGRAM ***
# ***** ****
# *****************************************************************************************************************
if __name__ == "__main__":
pass
+12
View File
@@ -167,6 +167,18 @@ class CoreAuthTokenModel(BaseModel):
frozen = False frozen = False
) )
clientDisplayName: str | None = Field(
description = "How the user has registered himself with the third-party client.",
frozen = False,
default = None
)
clientDisplayPicture: str | None = Field(
description = "The URL of the display picture that the user has set up with the third-party client.",
frozen = False,
default = None
)
status: Literal["pending", "active", "disabled"] = Field( status: Literal["pending", "active", "disabled"] = Field(
description = "to indicate the status of this account", description = "to indicate the status of this account",
frozen = False, frozen = False,