Commit d9947178 by Oleksandr Barabash

reverted back by diff

parent 78756e32
...@@ -86,10 +86,10 @@ async def v1_get_initiations(request: Request) -> Response: ...@@ -86,10 +86,10 @@ async def v1_get_initiations(request: Request) -> Response:
id=init.id) for init in inits]) id=init.id) for init in inits])
return Response(body=json.dumps(data), status=HTTPStatus.OK) return Response(body=json.dumps(data), status=HTTPStatus.OK)
except ItemNotFound as e: except ItemNotFound as e:
print("ItemNotFound:", e) Log.e(TAG, "v1_get_initiations::item not found", e)
return Response(status=HTTPStatus.NOT_FOUND) return Response(status=HTTPStatus.NOT_FOUND)
except Exception as e: except Exception as e:
print("error:", e) Log.e(TAG, "v1_get_initiations::exception", sys.exc_info())
return Response(status=HTTPStatus.BAD_REQUEST) return Response(status=HTTPStatus.BAD_REQUEST)
...@@ -111,8 +111,8 @@ async def v1_get_notification(request: Request) -> Response: ...@@ -111,8 +111,8 @@ async def v1_get_notification(request: Request) -> Response:
except ItemNotFound as e: except ItemNotFound as e:
Log.e(TAG, "v1_get_notification::item not found", e) Log.e(TAG, "v1_get_notification::item not found", e)
return Response(status=HTTPStatus.NOT_FOUND) return Response(status=HTTPStatus.NOT_FOUND)
except Exception as e: except Exception:
Log.e(TAG, exc_info=e) Log.e(TAG, exc_info=sys.exc_info())
return Response(status=HTTPStatus.BAD_REQUEST) return Response(status=HTTPStatus.BAD_REQUEST)
......
...@@ -83,13 +83,13 @@ class TeamsMessagingExtensionsActionPreviewBot(TeamsActivityHandler): ...@@ -83,13 +83,13 @@ class TeamsMessagingExtensionsActionPreviewBot(TeamsActivityHandler):
# reset parameters # reset parameters
notification.id = uuid.uuid4().__str__() notification.id = uuid.uuid4().__str__()
notification.tenant_id = notification.tenant_id or AppConfig.TENANT_ID notification.tenant_id = AppConfig.TENANT_ID
async def routine(): async def routine():
""" async routine """ """ async routine """
try: try:
reference = await self.cosmos_client.get_conversation( reference = await self.cosmos_client.get_conversation(
notification notification.destination
) )
except ItemNotFound: except ItemNotFound:
future.set_exception(ConversationNotFound("not found")) future.set_exception(ConversationNotFound("not found"))
...@@ -142,13 +142,12 @@ class TeamsMessagingExtensionsActionPreviewBot(TeamsActivityHandler): ...@@ -142,13 +142,12 @@ class TeamsMessagingExtensionsActionPreviewBot(TeamsActivityHandler):
try: try:
account = turn_context.activity.from_property account = turn_context.activity.from_property
acks = await self.cosmos_client.get_acknowledge_items( acks = await self.cosmos_client.get_acknowledge_items(
mx.notification_id, mx.tenant_id mx.notification_id
) )
if len(acks) > 0: if len(acks) > 0:
return return
await self.cosmos_client.create_acknowledge(mx.notification_id, await self.cosmos_client.create_acknowledge(mx.notification_id,
mx.tenant_id,
account) account)
notification = await self.cosmos_client.get_notification( notification = await self.cosmos_client.get_notification(
mx.notification_id mx.notification_id
...@@ -187,12 +186,12 @@ class TeamsMessagingExtensionsActionPreviewBot(TeamsActivityHandler): ...@@ -187,12 +186,12 @@ class TeamsMessagingExtensionsActionPreviewBot(TeamsActivityHandler):
return await self.on_mx_task_default(turn_context) return await self.on_mx_task_default(turn_context)
async def on_mx_task_notification_url(self, turn_context: TurnContext, async def on_mx_task_notification_url(self, turn_context: TurnContext,
mx: MedX) -> TaskModuleResponse: notification_id: str) \
-> TaskModuleResponse:
""" On MX Task fetch Notification URL """ """ On MX Task fetch Notification URL """
try: try:
notification = await self.cosmos_client.get_notification( notification = await self.cosmos_client.get_notification(
notification_id=mx.notification_id, notification_id=notification_id
tenant_id=mx.tenant_id or AppConfig.TENANT_ID
) )
link = notification.url.link link = notification.url.link
if link is not None: if link is not None:
...@@ -239,6 +238,8 @@ class TeamsMessagingExtensionsActionPreviewBot(TeamsActivityHandler): ...@@ -239,6 +238,8 @@ class TeamsMessagingExtensionsActionPreviewBot(TeamsActivityHandler):
# 1. save action to DB # 1. save action to DB
# 2. return URL # 2. return URL
initiator = turn_context.activity.from_property.name initiator = turn_context.activity.from_property.name
await self.cosmos_client.create_initiation(initiator, mx) await self.cosmos_client.create_initiation(initiator,
return await self.on_mx_task_notification_url(turn_context, mx) mx.notification_id)
return await self.on_mx_task_notification_url(turn_context,
mx.notification_id)
return await self.on_mx_task_default(turn_context) return await self.on_mx_task_default(turn_context)
...@@ -8,7 +8,6 @@ class AcknowledgeSchema(CamelCaseSchema): ...@@ -8,7 +8,6 @@ class AcknowledgeSchema(CamelCaseSchema):
""" Notification Schema """ """ Notification Schema """
id = fields.String(required=True, allow_none=True) # database message id id = fields.String(required=True, allow_none=True) # database message id
notification_id = fields.String(required=True) notification_id = fields.String(required=True)
tenant_id = fields.String(required=True)
username = fields.String(required=True) username = fields.String(required=True)
user_aad_id = fields.String(required=True) user_aad_id = fields.String(required=True)
timestamp = fields.Integer(required=True) timestamp = fields.Integer(required=True)
...@@ -11,6 +11,5 @@ class Initiation(CamelCaseMixin): ...@@ -11,6 +11,5 @@ class Initiation(CamelCaseMixin):
""" Notification Dataclass """ """ Notification Dataclass """
initiator: str # User name initiator: str # User name
notification_id: str # Notification ID notification_id: str # Notification ID
tenant_id: str # Tenant ID
timestamp: Optional[int] = field(default=None) timestamp: Optional[int] = field(default=None)
id: Optional[str] = field(default=None) # Unique Initiation ID id: Optional[str] = field(default=None) # Unique Initiation ID
...@@ -21,4 +21,3 @@ class MedX(CamelCaseMixin): ...@@ -21,4 +21,3 @@ class MedX(CamelCaseMixin):
""" MedX data """ """ MedX data """
type: str type: str
notification_id: Optional[str] notification_id: Optional[str]
tenant_id: Optional[str]
...@@ -24,7 +24,6 @@ class Notification(CamelCaseMixin): ...@@ -24,7 +24,6 @@ class Notification(CamelCaseMixin):
title: Optional[str] = field(default=None) title: Optional[str] = field(default=None)
url: Optional[NotificationUrl] = field(default_factory=NotificationUrl) url: Optional[NotificationUrl] = field(default_factory=NotificationUrl)
acknowledge: Optional[bool] = field(default=False) acknowledge: Optional[bool] = field(default=False)
tenant_id: Optional[str] = field(default=None)
def to_db(self) -> "NotificationCosmos": def to_db(self) -> "NotificationCosmos":
""" Create NotificationCosmos """ """ Create NotificationCosmos """
...@@ -34,8 +33,7 @@ class Notification(CamelCaseMixin): ...@@ -34,8 +33,7 @@ class Notification(CamelCaseMixin):
message=self.message, message=self.message,
title=self.title, title=self.title,
url=self.url, url=self.url,
acknowledge=self.acknowledge, acknowledge=self.acknowledge)
tenant_id=self.tenant_id)
# noinspection PyDataclass # noinspection PyDataclass
...@@ -44,4 +42,5 @@ class NotificationCosmos(Notification): ...@@ -44,4 +42,5 @@ class NotificationCosmos(Notification):
""" Notification Dataclass """ """ Notification Dataclass """
# We have to add these fields # We have to add these fields
id: Optional[str] = field(default=None) id: Optional[str] = field(default=None)
tenant_id: Optional[str] = field(default=None)
timestamp: Optional[int] = field(default_factory=timestamp_factory) timestamp: Optional[int] = field(default_factory=timestamp_factory)
...@@ -17,7 +17,6 @@ from entities.json.acknowledge_schema import AcknowledgeSchema ...@@ -17,7 +17,6 @@ from entities.json.acknowledge_schema import AcknowledgeSchema
from entities.json.camel_case_mixin import timestamp_factory from entities.json.camel_case_mixin import timestamp_factory
from entities.json.conversation_reference import ConversationReference from entities.json.conversation_reference import ConversationReference
from entities.json.initiation import Initiation from entities.json.initiation import Initiation
from entities.json.medx import MedX
from entities.json.notification import NotificationCosmos from entities.json.notification import NotificationCosmos
...@@ -115,8 +114,8 @@ class CosmosClient: ...@@ -115,8 +114,8 @@ class CosmosClient:
return await self.execute_blocking(bl) return await self.execute_blocking(bl)
async def get_acknowledge_items(self, notification_id: str, async def get_acknowledge_items(self, notification_id)\
_tenant_id: str) -> List[Acknowledge]: -> List[Acknowledge]:
""" Get Acknowledge Items """ """ Get Acknowledge Items """
container = await self.get_acknowledges_container() container = await self.get_acknowledges_container()
...@@ -264,15 +263,12 @@ class CosmosClient: ...@@ -264,15 +263,12 @@ class CosmosClient:
CosmosDBConfig.Initiations.PARTITION_KEY CosmosDBConfig.Initiations.PARTITION_KEY
) )
async def create_acknowledge(self, notification_id: str, tenant_id: str, async def create_acknowledge(self, notification_id: str,
account: ChannelAccount) -> Dict[str, Any]: account: ChannelAccount) -> Dict[str, Any]:
""" Add acknowledge to the DB """ """ Add acknowledge to the DB """
from config import AppConfig
container = await self.get_acknowledges_container() container = await self.get_acknowledges_container()
notification = AcknowledgeSchema().dump(dict( notification = AcknowledgeSchema().dump(dict(
notification_id=notification_id, notification_id=notification_id,
tenant_id=tenant_id or AppConfig.TENANT_ID,
username=account.name, username=account.name,
user_aad_id=account.aad_object_id, user_aad_id=account.aad_object_id,
timestamp=timestamp_factory() timestamp=timestamp_factory()
...@@ -284,32 +280,30 @@ class CosmosClient: ...@@ -284,32 +280,30 @@ class CosmosClient:
""" Get Acknowledge object """ """ Get Acknowledge object """
try: try:
container = await self.get_acknowledges_container() container = await self.get_acknowledges_container()
# items = await self.query_items(container, notification_id) items = await self.query_items(container, notification_id)
# return Acknowledge.get_schema(unknown=EXCLUDE).load(items) return Acknowledge.get_schema(unknown=EXCLUDE).load(items)
except ItemNotFound: except ItemNotFound:
return None return None
async def get_conversation(self, notification: NotificationCosmos)\ async def get_conversation(self, conversation_id: str)\
-> ConversationReference: -> ConversationReference:
""" Get Conversation Reference """ """ Get Conversation Reference """
from config import AppConfig from config import AppConfig
container = await self.get_conversations_container() container = await self.get_conversations_container()
item = await self.get_item( item = await self.get_item(container, conversation_id,
container, notification.destination, AppConfig.TENANT_ID)
notification.tenant_id or AppConfig.TENANT_ID
)
return ConversationReference.get_schema(unknown=EXCLUDE)\ return ConversationReference.get_schema(unknown=EXCLUDE)\
.load(item).to_ms_reference() .load(item).to_ms_reference()
async def get_notification(self, notification_id: str, tenant_id: str)\ async def get_notification(self, notification_id: str)\
-> NotificationCosmos: -> NotificationCosmos:
""" Get Notification """ """ Get Notification """
from config import AppConfig from config import AppConfig
container = await self.get_notifications_container() container = await self.get_notifications_container()
item = await self.get_item(container, notification_id, item = await self.get_item(container, notification_id,
tenant_id or AppConfig.TENANT_ID) AppConfig.TENANT_ID)
return NotificationCosmos.get_schema(unknown=EXCLUDE).load(item) return NotificationCosmos.get_schema(unknown=EXCLUDE).load(item)
async def create_conversation_reference(self, turn_context: TurnContext)\ async def create_conversation_reference(self, turn_context: TurnContext)\
...@@ -337,13 +331,12 @@ class CosmosClient: ...@@ -337,13 +331,12 @@ class CosmosClient:
return return
raise SaveItemError(e.http_error_message) raise SaveItemError(e.http_error_message)
async def create_initiation(self, initiator: str, mx: MedX) -> None: async def create_initiation(self, initiator: str,
notification_id: str) -> None:
""" Save initiation """ """ Save initiation """
from config import AppConfig
container = await self.get_initiation_container() container = await self.get_initiation_container()
initiation = Initiation(initiator=initiator, initiation = Initiation(initiator=initiator,
timestamp=timestamp_factory(), timestamp=timestamp_factory(),
notification_id=mx.notification_id, notification_id=notification_id)
tenant_id=mx.tenant_id or AppConfig.TENANT_ID)
data = Initiation.get_schema().dump(initiation) data = Initiation.get_schema().dump(initiation)
await self.create_item(container, body=data) await self.create_item(container, body=data)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment