(20250123) Made a common API to disable all integrations.
This commit is contained in:
@@ -48,7 +48,7 @@ from controllers_v2.core.base import CoreBaseModel
|
||||
from models.core.auth_token import CoreAuthTokenModel
|
||||
|
||||
# To work with datatypes:
|
||||
from typing import List
|
||||
from typing import List, Literal
|
||||
|
||||
# To make API calls:
|
||||
import httpx
|
||||
@@ -210,6 +210,8 @@ class CoreAuthTokenController(CoreBaseModel):
|
||||
"authType": auth_token.authType,
|
||||
"user": auth_token.user.model_dump(),
|
||||
"clientUserId": auth_token.clientUserId,
|
||||
"clientDisplayName": auth_token.clientDisplayName,
|
||||
"clientDisplayPicture": auth_token.clientDisplayPicture,
|
||||
"auth": auth_token.auth,
|
||||
"token": auth_token.token,
|
||||
"firstRefreshTs": auth_token.firstRefreshTs,
|
||||
@@ -258,6 +260,7 @@ class CoreAuthTokenController(CoreBaseModel):
|
||||
token_notes: dict,
|
||||
display_name: str = None,
|
||||
display_picture: str = None,
|
||||
last_action: Literal["Auth Requested", "Auth Granted", "Auth Revoked"] = "Auth Granted",
|
||||
session_token: str = None
|
||||
) -> bool:
|
||||
|
||||
@@ -272,6 +275,7 @@ class CoreAuthTokenController(CoreBaseModel):
|
||||
: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_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.
|
||||
:return: True if saved, False if failed.
|
||||
"""
|
||||
@@ -301,6 +305,8 @@ class CoreAuthTokenController(CoreBaseModel):
|
||||
"auth": auth_token.auth,
|
||||
"token": auth_token.token,
|
||||
"status": auth_token.status,
|
||||
"clientDisplayName": auth_token.clientDisplayName,
|
||||
"clientDisplayPicture": auth_token.clientDisplayPicture,
|
||||
"lastRefreshTs": request_ts,
|
||||
"firstRefreshTs": {
|
||||
"$cond": {
|
||||
@@ -331,7 +337,7 @@ class CoreAuthTokenController(CoreBaseModel):
|
||||
mongo_json["user"]["billingAccountId"], # ............................... 'p_billing_account_id'
|
||||
mongo_json["client"], # ................................................. 'p_provider'
|
||||
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_picture, # ...................................................... 'p_display_picture'
|
||||
token_key, # ............................................................ 'p_token_id'
|
||||
@@ -398,14 +404,55 @@ class CoreAuthTokenController(CoreBaseModel):
|
||||
# Done here:
|
||||
return success
|
||||
|
||||
async def modify_status(
|
||||
async def modify_status_by_token_key(
|
||||
self,
|
||||
sql_conn: AsyncMySQL,
|
||||
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))
|
||||
filter_json = {
|
||||
"$and": [
|
||||
{
|
||||
"status": "active", # ... The account must be active.
|
||||
},
|
||||
{
|
||||
"$or": [
|
||||
{"syncAfterTs": None}, # ............ The time after which sync'ing is allowed is null.
|
||||
|
||||
@@ -98,6 +98,12 @@ from abc import ABC, abstractmethod
|
||||
|
||||
class TradingController(CoreAuthTokenController, ABC):
|
||||
|
||||
# ┏┓┓ ┓┏
|
||||
# ┃ ┃┏┓┏┏ ┃┃┏┓┏┓┏
|
||||
# ┗┛┗┗┻┛┛ ┗┛┗┻┛ ┛
|
||||
|
||||
SERVICE_TYPE = "stockTrading"
|
||||
|
||||
# ┏┓
|
||||
# ┃ ┏┓┏┓┏╋┏┓┓┏┏╋┏┓┏┓
|
||||
# ┗┛┗┛┛┗┛┗┛ ┗┻┗┗┗┛┛
|
||||
@@ -126,13 +132,10 @@ class TradingController(CoreAuthTokenController, ABC):
|
||||
:return: None.
|
||||
"""
|
||||
|
||||
# Declare the service type:
|
||||
this_service_type = "stockTrading"
|
||||
|
||||
# Prepare base filter:
|
||||
this_filter = {}
|
||||
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:
|
||||
CoreAuthTokenController.__init__(
|
||||
@@ -147,7 +150,7 @@ class TradingController(CoreAuthTokenController, ABC):
|
||||
)
|
||||
|
||||
# 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.
|
||||
"""
|
||||
|
||||
# Declare the client:
|
||||
this_client = self.CLIENT_NAME
|
||||
|
||||
# Prepare base filter:
|
||||
this_filter = {"client": this_client}
|
||||
this_filter = {"client": self.CLIENT_NAME}
|
||||
|
||||
# Invoke the parent's constructor:
|
||||
super().__init__(
|
||||
@@ -155,7 +152,7 @@ class ICICIBreezeTradingController(TradingController):
|
||||
)
|
||||
|
||||
# Init a variable in a parent:
|
||||
self._client = this_client
|
||||
self._client = self.CLIENT_NAME
|
||||
|
||||
# ┏┓ ┓
|
||||
# ┣┫┓┏╋┣┓
|
||||
|
||||
@@ -136,11 +136,8 @@ class PaperTradingController(TradingController):
|
||||
:return: None.
|
||||
"""
|
||||
|
||||
# Declare the client:
|
||||
this_client = self.CLIENT_NAME
|
||||
|
||||
# Prepare base filter:
|
||||
this_filter = {"client": this_client}
|
||||
this_filter = {"client": self.CLIENT_NAME}
|
||||
|
||||
# Invoke the parent's constructor:
|
||||
super().__init__(
|
||||
@@ -154,7 +151,7 @@ class PaperTradingController(TradingController):
|
||||
)
|
||||
|
||||
# Init a variable in a parent:
|
||||
self._client = this_client
|
||||
self._client = self.CLIENT_NAME
|
||||
|
||||
# ┏┓ ┓
|
||||
# ┣┫┓┏╋┣┓
|
||||
|
||||
@@ -136,11 +136,8 @@ class ZerodhaKiteTradingController(TradingController):
|
||||
:return: None.
|
||||
"""
|
||||
|
||||
# Declare the client:
|
||||
this_client = self.CLIENT_NAME
|
||||
|
||||
# Prepare base filter:
|
||||
this_filter = {"client": this_client}
|
||||
this_filter = {"client": self.CLIENT_NAME}
|
||||
|
||||
# Invoke the parent's constructor:
|
||||
super().__init__(
|
||||
@@ -154,7 +151,7 @@ class ZerodhaKiteTradingController(TradingController):
|
||||
)
|
||||
|
||||
# Init a variable in a parent:
|
||||
self._client = this_client
|
||||
self._client = self.CLIENT_NAME
|
||||
|
||||
# ┏┓ ┓
|
||||
# ┣┫┓┏╋┣┓
|
||||
|
||||
@@ -106,6 +106,12 @@ from abc import ABC, abstractmethod
|
||||
|
||||
class ChatController(CoreMessageController, ABC):
|
||||
|
||||
# ┏┓┓ ┓┏
|
||||
# ┃ ┃┏┓┏┏ ┃┃┏┓┏┓┏
|
||||
# ┗┛┗┗┻┛┛ ┗┛┗┻┛ ┛
|
||||
|
||||
SERVICE_TYPE = "chat"
|
||||
|
||||
# ┏┓
|
||||
# ┃ ┏┓┏┓┏╋┏┓┓┏┏╋┏┓┏┓
|
||||
# ┗┛┗┛┛┗┛┗┛ ┗┻┗┗┗┛┛
|
||||
@@ -137,7 +143,7 @@ class ChatController(CoreMessageController, ABC):
|
||||
# Prepare the combined base filter:
|
||||
sms_filter = {}
|
||||
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:
|
||||
CoreMessageController.__init__(
|
||||
@@ -151,6 +157,9 @@ class ChatController(CoreMessageController, ABC):
|
||||
debug_only_errors = debug_only_errors
|
||||
)
|
||||
|
||||
# Init a variable in a parent:
|
||||
self._service_type = self.SERVICE_TYPE
|
||||
|
||||
# ┏┓ ┓ ┳┳┓
|
||||
# ┗┓┏┓┏┓┏┫ ┃┃┃┏┓┏┏┏┓┏┓┏┓┏
|
||||
# ┗┛┗ ┛┗┗┻ ┛ ┗┗ ┛┛┗┻┗┫┗ ┛
|
||||
|
||||
@@ -105,6 +105,12 @@ import asyncio
|
||||
|
||||
class WhatsAppNimbusController(ChatController):
|
||||
|
||||
# ┏┓┓ ┓┏
|
||||
# ┃ ┃┏┓┏┏ ┃┃┏┓┏┓┏
|
||||
# ┗┛┗┗┻┛┛ ┗┛┗┻┛ ┛
|
||||
|
||||
CLIENT_NAME = "gmail"
|
||||
|
||||
# ┏┓
|
||||
# ┃ ┏┓┏┓┏╋┏┓┓┏┏╋┏┓┏┓
|
||||
# ┗┛┗┛┛┗┛┗┛ ┗┻┗┗┗┛┛
|
||||
@@ -134,12 +140,15 @@ class WhatsAppNimbusController(ChatController):
|
||||
cache = cache,
|
||||
alert_url = alert_url,
|
||||
http_client = http_client,
|
||||
base_filter = {"client": "whatsappNimbus"},
|
||||
base_filter = {"client": self.CLIENT_NAME},
|
||||
debug = debug,
|
||||
debug_prefix = debug_prefix,
|
||||
debug_only_errors = debug_only_errors
|
||||
)
|
||||
|
||||
# Init a variable in a parent:
|
||||
self._client = self.CLIENT_NAME
|
||||
|
||||
# ┏┓ ┓ ┳┳┓
|
||||
# ┗┓┏┓┏┓┏┫ ┃┃┃┏┓┏┏┏┓┏┓┏┓┏
|
||||
# ┗┛┗ ┛┗┗┻ ┛ ┗┗ ┛┛┗┻┗┫┗ ┛
|
||||
|
||||
@@ -119,9 +119,11 @@ from abc import ABC, abstractmethod
|
||||
|
||||
class MailController(CoreMessageController, ABC):
|
||||
|
||||
# ┏┓┓ ┓┏ • ┓ ┓
|
||||
# ┃ ┃┏┓┏┏ ┃┃┏┓┏┓┓┏┓┣┓┃┏┓┏
|
||||
# ┗┛┗┗┻┛┛ ┗┛┗┻┛ ┗┗┻┗┛┗┗ ┛
|
||||
# ┏┓┓ ┓┏
|
||||
# ┃ ┃┏┓┏┏ ┃┃┏┓┏┓┏
|
||||
# ┗┛┗┗┻┛┛ ┗┛┗┻┛ ┛
|
||||
|
||||
SERVICE_TYPE = "email"
|
||||
|
||||
# For AI Magic through LLMs:
|
||||
RECEIVED_MAIL_SUMMARIZATION_PROMPT_TEMPLATE = [
|
||||
@@ -189,7 +191,7 @@ class MailController(CoreMessageController, ABC):
|
||||
# Prepare the combined base filter:
|
||||
sms_filter = {}
|
||||
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:
|
||||
CoreMessageController.__init__(
|
||||
@@ -203,6 +205,9 @@ class MailController(CoreMessageController, ABC):
|
||||
debug_only_errors = debug_only_errors
|
||||
)
|
||||
|
||||
# Init a variable in a parent:
|
||||
self._service_type = self.SERVICE_TYPE
|
||||
|
||||
# ┓┏ ┓
|
||||
# ┣┫┏┓┃┏┓┏┓┏┓┏
|
||||
# ┛┗┗ ┗┣┛┗ ┛ ┛
|
||||
|
||||
@@ -127,6 +127,12 @@ import asyncio
|
||||
|
||||
class GmailController(MailController):
|
||||
|
||||
# ┏┓┓ ┓┏
|
||||
# ┃ ┃┏┓┏┏ ┃┃┏┓┏┓┏
|
||||
# ┗┛┗┗┻┛┛ ┗┛┗┻┛ ┛
|
||||
|
||||
CLIENT_NAME = "gmail"
|
||||
|
||||
# ┏┓
|
||||
# ┃ ┏┓┏┓┏╋┏┓┓┏┏╋┏┓┏┓
|
||||
# ┗┛┗┛┛┗┛┗┛ ┗┻┗┗┗┛┛
|
||||
@@ -156,12 +162,15 @@ class GmailController(MailController):
|
||||
cache = cache,
|
||||
alert_url = alert_url,
|
||||
http_client = http_client,
|
||||
base_filter = {"client": "gmail"},
|
||||
base_filter = {"client": self.CLIENT_NAME},
|
||||
debug = debug,
|
||||
debug_prefix = debug_prefix,
|
||||
debug_only_errors = debug_only_errors
|
||||
)
|
||||
|
||||
# Init a variable in a parent:
|
||||
self._client = self.CLIENT_NAME
|
||||
|
||||
# ┏┓┏┓ ┓ ┏┓ ┏┓
|
||||
# ┃┃┣┫┓┏╋┣┓┏┛ ┃┫
|
||||
# ┗┛┛┗┗┻┗┛┗┗━•┗┛
|
||||
|
||||
@@ -107,6 +107,12 @@ from abc import ABC, abstractmethod
|
||||
|
||||
class SMSController(CoreMessageController, ABC):
|
||||
|
||||
# ┏┓┓ ┓┏
|
||||
# ┃ ┃┏┓┏┏ ┃┃┏┓┏┓┏
|
||||
# ┗┛┗┗┻┛┛ ┗┛┗┻┛ ┛
|
||||
|
||||
SERVICE_TYPE = "sms"
|
||||
|
||||
# ┏┓
|
||||
# ┃ ┏┓┏┓┏╋┏┓┓┏┏╋┏┓┏┓
|
||||
# ┗┛┗┛┛┗┛┗┛ ┗┻┗┗┗┛┛
|
||||
@@ -138,7 +144,7 @@ class SMSController(CoreMessageController, ABC):
|
||||
# Prepare the combined base filter:
|
||||
sms_filter = {}
|
||||
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:
|
||||
CoreMessageController.__init__(
|
||||
@@ -152,6 +158,9 @@ class SMSController(CoreMessageController, ABC):
|
||||
debug_only_errors = debug_only_errors
|
||||
)
|
||||
|
||||
# Init a variable in a parent:
|
||||
self._service_type = self.SERVICE_TYPE
|
||||
|
||||
# ┏┓┳┳┓┏┓ ┏┓ ┓•
|
||||
# ┗┓┃┃┃┗┓ ┗┓┏┓┏┓┏┫┓┏┓┏┓
|
||||
# ┗┛┛ ┗┗┛ ┗┛┗ ┛┗┗┻┗┛┗┗┫
|
||||
|
||||
@@ -105,6 +105,12 @@ import asyncio
|
||||
|
||||
class NimbusSMSIndiaController(SMSController):
|
||||
|
||||
# ┏┓┓ ┓┏
|
||||
# ┃ ┃┏┓┏┏ ┃┃┏┓┏┓┏
|
||||
# ┗┛┗┗┻┛┛ ┗┛┗┻┛ ┛
|
||||
|
||||
CLIENT_NAME = "nimbusSmsIndia"
|
||||
|
||||
# ┏┓
|
||||
# ┃ ┏┓┏┓┏╋┏┓┓┏┏╋┏┓┏┓
|
||||
# ┗┛┗┛┛┗┛┗┛ ┗┻┗┗┗┛┛
|
||||
@@ -135,12 +141,15 @@ class NimbusSMSIndiaController(SMSController):
|
||||
cache = cache,
|
||||
alert_url = alert_url,
|
||||
http_client = http_client,
|
||||
base_filter = {"client": "nimbusSmsIndia"},
|
||||
base_filter = {"client": self.CLIENT_NAME},
|
||||
debug = debug,
|
||||
debug_prefix = debug_prefix,
|
||||
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):
|
||||
|
||||
# ┏┓┓ ┓┏
|
||||
# ┃ ┃┏┓┏┏ ┃┃┏┓┏┓┏
|
||||
# ┗┛┗┗┻┛┛ ┗┛┗┻┛ ┛
|
||||
|
||||
CLIENT_NAME = "savvyBulkSmsKenya"
|
||||
|
||||
# ┏┓
|
||||
# ┃ ┏┓┏┓┏╋┏┓┓┏┏╋┏┓┏┓
|
||||
# ┗┛┗┛┛┗┛┗┛ ┗┻┗┗┗┛┛
|
||||
@@ -135,12 +141,15 @@ class SavvyBulkSMSKenyaController(SMSController):
|
||||
cache = cache,
|
||||
alert_url = alert_url,
|
||||
http_client = http_client,
|
||||
base_filter = {"client": "savvyBulkSmsKenya"},
|
||||
base_filter = {"client": self.CLIENT_NAME},
|
||||
debug = debug,
|
||||
debug_prefix = debug_prefix,
|
||||
debug_only_errors = debug_only_errors
|
||||
)
|
||||
|
||||
# Init a variable in a parent:
|
||||
self._client = self.CLIENT_NAME
|
||||
|
||||
# ┏┓┳┳┓┏┓ ┏┓ ┓•
|
||||
# ┗┓┃┃┃┗┓ ┗┓┏┓┏┓┏┫┓┏┓┏┓
|
||||
# ┗┛┛ ┗┗┛ ┗┛┗ ┛┗┗┻┗┛┗┗┫
|
||||
|
||||
Reference in New Issue
Block a user