diff --git a/apps/chat/api/chat_authentication_api.py b/apps/chat/api/chat_authentication_api.py index 86dcde5e829..1c7aeeee383 100644 --- a/apps/chat/api/chat_authentication_api.py +++ b/apps/chat/api/chat_authentication_api.py @@ -52,4 +52,12 @@ def get_parameters(): class ChatOpenAPI(APIMixin): @staticmethod def get_parameters(): - return [] + return [ + OpenApiParameter( + name="application_id", + description=_("Application ID"), + type=OpenApiTypes.UUID, + location=OpenApiParameter.PATH, + required=True, + ) + ] diff --git a/apps/chat/urls.py b/apps/chat/urls.py index b78d07d760b..041d1467e20 100644 --- a/apps/chat/urls.py +++ b/apps/chat/urls.py @@ -15,7 +15,7 @@ path('application//profile', views.ApplicationProfile.as_view(), name='profile'), path('chat_message/', views.ChatView.as_view(), name='chat'), path('chat_message//cancel', views.CancelWorkflowView.as_view(), name='cancel_workflow'), - path('open', views.OpenView.as_view(), name='open'), + path('application//open', views.OpenView.as_view(), name='open'), path('text_to_speech', views.TextToSpeech.as_view()), path('speech_to_text', views.SpeechToText.as_view()), path('captcha', views.CaptchaView.as_view(), name='captcha'), diff --git a/apps/chat/views/chat.py b/apps/chat/views/chat.py index 96676e832bd..0ae2081d49a 100644 --- a/apps/chat/views/chat.py +++ b/apps/chat/views/chat.py @@ -217,14 +217,15 @@ class OpenView(APIView): responses=None, tags=[_('Chat')] # type: ignore ) - def get(self, request: Request): + @has_permissions(ChatPermissionConstants.get_aggregate_permissions()) + def get(self, request: Request, application_id: str): ip_address = _get_ip_address(request) return result.success(OpenChatSerializers( - data={'application_id': request.auth.application_id, - 'chat_user_id': request.auth.chat_user_id, 'chat_user_type': request.auth.chat_user_type, + data={'application_id': application_id, + 'chat_user_id': request.user.id, 'chat_user_type': request.user.type, 'ip_address': ip_address, 'source': { - 'type': ChatSourceChoices.API_CALL.value if request.auth.chat_user_type == ChatUserType.APPLICATION_API_KEY.value else ChatSourceChoices.ONLINE.value}, + 'type': ChatSourceChoices.API_CALL.value if request.user.type == ChatUserType.APPLICATION_API_KEY.value else ChatSourceChoices.ONLINE.value}, 'debug': False}).open()) diff --git a/apps/common/auth/struct/auth.py b/apps/common/auth/struct/auth.py index b542a33f748..82e659312aa 100644 --- a/apps/common/auth/struct/auth.py +++ b/apps/common/auth/struct/auth.py @@ -36,6 +36,6 @@ def __init__(self, _id, profile=None, **keywords): self.id = _id - self._type = _type + self.type = _type self.profile = profile self.keywords = keywords