|
29 | 29 | ChatUserType, ApplicationChatUserStats, ApplicationAccessToken, ChatRecord, Chat, ApplicationVersion |
30 | 30 | from application.serializers.application import ApplicationOperateSerializer |
31 | 31 | from application.serializers.common import ChatInfo |
| 32 | +from common.database_model_manage.database_model_manage import DatabaseModelManage |
32 | 33 | from common.exception.app_exception import AppApiException, AppChatNumOutOfBoundsFailed, ChatException |
33 | 34 | from common.handle.base_to_response import BaseToResponse |
34 | 35 | from common.handle.impl.response.openai_to_response import OpenaiToResponse |
@@ -308,13 +309,23 @@ def chat_work_flow(self, chat_info: ChatInfo, instance: dict, base_to_response): |
308 | 309 | r = work_flow_manage.run() |
309 | 310 | return r |
310 | 311 |
|
| 312 | + def is_valid_chat_user(self): |
| 313 | + chat_user_id = self.data.get('chat_user_id') |
| 314 | + application_id = self.data.get('application_id') |
| 315 | + is_auth_chat_user = DatabaseModelManage.get_model("is_auth_chat_user") |
| 316 | + if self.chat_user_type == ChatUserType.CHAT_USER.value and is_auth_chat_user: |
| 317 | + is_auth = is_auth_chat_user(chat_user_id, application_id) |
| 318 | + if not is_auth: |
| 319 | + raise ChatException(500, _("The chat user is not authorized.")) |
| 320 | + |
311 | 321 | def chat(self, instance: dict, base_to_response: BaseToResponse = SystemToResponse()): |
312 | 322 | super().is_valid(raise_exception=True) |
313 | 323 | ChatMessageSerializers(data=instance).is_valid(raise_exception=True) |
314 | 324 | chat_info = self.get_chat_info() |
315 | 325 | chat_info.get_application() |
316 | 326 | chat_info.get_chat_user() |
317 | 327 | self.is_valid_chat_id(chat_info) |
| 328 | + self.is_valid_chat_user() |
318 | 329 | if chat_info.application.type == ApplicationTypeChoices.SIMPLE: |
319 | 330 | self.is_valid_application_simple(raise_exception=True, chat_info=chat_info) |
320 | 331 | return self.chat_simple(chat_info, instance, base_to_response) |
|
0 commit comments