From 48924655f762501c6035375e2bedeebedb40b2ae Mon Sep 17 00:00:00 2001 From: GuoQing Zhang Date: Tue, 2 Jul 2024 19:05:14 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20=E5=AE=A1=E8=AE=A1=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E4=BF=AE=E6=94=B9=E4=B8=BAtext=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=EF=BC=8C=E9=98=B2=E6=AD=A2=E5=86=85=E5=AE=B9=E8=B6=85?= =?UTF-8?q?=E9=95=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/bisheng/database/models/audit_log.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/bisheng/database/models/audit_log.py b/src/backend/bisheng/database/models/audit_log.py index 03083a425..7cfbda92c 100644 --- a/src/backend/bisheng/database/models/audit_log.py +++ b/src/backend/bisheng/database/models/audit_log.py @@ -64,7 +64,7 @@ class AuditLogBase(SQLModelSerializable): object_type: Optional[str] = Field(index=True, description="操作对象类型") object_id: Optional[int] = Field(index=True, description="操作对象ID") object_name: Optional[str] = Field(description="操作对象名称") - note: Optional[str] = Field(sa_column=Column(Text(255)), description="操作备注") + note: Optional[str] = Field(sa_column=Column(Text), description="操作备注") ip_address: Optional[str] = Field(index=True, description="操作时客户端的IP地址") create_time: Optional[datetime] = Field(sa_column=Column( DateTime, nullable=False, index=True, server_default=text('CURRENT_TIMESTAMP')), description="操作时间") From e09f4284aad8cac76626fd1a56bdc3d905aee755 Mon Sep 17 00:00:00 2001 From: GuoQing Zhang Date: Tue, 2 Jul 2024 19:44:21 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20v2=E6=8E=A5=E5=8F=A3=E4=B8=8D?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E5=AE=A1=E8=AE=A1=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/bisheng/api/v1/knowledge.py | 25 +++++++++++++++++++++---- src/backend/bisheng/api/v2/filelib.py | 11 +---------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/backend/bisheng/api/v1/knowledge.py b/src/backend/bisheng/api/v1/knowledge.py index f1238368a..6ec5d7077 100644 --- a/src/backend/bisheng/api/v1/knowledge.py +++ b/src/backend/bisheng/api/v1/knowledge.py @@ -173,12 +173,18 @@ async def process_knowledge(*, session.add(knowledge) session.commit() + upload_knowledge_file_hook(request, login_user, knowledge_id, files) + return resp_200(result) + + +def upload_knowledge_file_hook(request: Request, login_user: UserPayload, knowledge_id: int, + file_list: List[KnowledgeFile]): + logger.info(f'act=upload_knowledge_file_hook user={login_user.user_name} knowledge_id={knowledge_id}') # 记录审计日志 file_name = "" - for one in files: + for one in file_list: file_name += "\n\n" + one.file_name AuditLogService.upload_knowledge_file(login_user, get_request_ip(request), knowledge_id, file_name) - return resp_200(result) @router.post('/create', response_model=UnifiedResponseModel[KnowledgeRead], status_code=201) @@ -220,7 +226,7 @@ def create_knowledge_hook(request: Request, knowledge: Knowledge, login_user: Us # 查询下用户所在的用户组 user_group = UserGroupDao.get_user_group(login_user.user_id) if user_group: - # 批量将助手资源插入到关联表里 + # 批量将知识库资源插入到关联表里 batch_resource = [] for one in user_group: batch_resource.append(GroupResource( @@ -438,6 +444,17 @@ def delete_knowledge_file(*, KnowledgeFileDao.delete_batch([file_id]) # 删除知识库文件的审计日志 - AuditLogService.delete_knowledge_file(login_user, get_request_ip(request), knowledge.id, knowledge_file.file_name) + delete_knowledge_file_hook(request, login_user, knowledge.id, [knowledge_file]) return resp_200(message='删除成功') + + +def delete_knowledge_file_hook(request: Request, login_user: UserPayload, knowledge_id: int, + file_list: List[KnowledgeFile]): + logger.info(f'act=delete_knowledge_file_hook user={login_user.user_name} knowledge_id={knowledge_id}') + # 记录审计日志 + # 记录审计日志 + file_name = "" + for one in file_list: + file_name += "\n\n" + one.file_name + AuditLogService.delete_knowledge_file(login_user, get_request_ip(request), knowledge_id, file_name) diff --git a/src/backend/bisheng/api/v2/filelib.py b/src/backend/bisheng/api/v2/filelib.py index f8e42d639..700097266 100644 --- a/src/backend/bisheng/api/v2/filelib.py +++ b/src/backend/bisheng/api/v2/filelib.py @@ -6,8 +6,6 @@ delete_es, delete_knowledge_by, delete_knowledge_file_vectors, delete_vector, text_knowledge) -from bisheng.api.services.user_service import UserPayload -from bisheng.api.v1.knowledge import delete_knowledge_hook, create_knowledge_hook from bisheng.api.v1.schemas import ChunkInput, UnifiedResponseModel, resp_200, resp_500 from bisheng.cache.utils import save_download_file from bisheng.database.base import session_getter @@ -33,16 +31,12 @@ @router.post('/', response_model=KnowledgeRead, status_code=201) -def creat(knowledge: KnowledgeCreate): +def create(knowledge: KnowledgeCreate): """创建知识库.""" user_id = knowledge.user_id or settings.get_from_db('default_operator').get('user') if not user_id: raise HTTPException(status_code=500, detail='未配置default_operator中user配置') - user_payload = UserPayload(**{ - "user_id": user_id - }) db_knowledge = create_knowledge(knowledge, user_id) - create_knowledge_hook(db_knowledge, user_payload) return db_knowledge @@ -129,9 +123,6 @@ def delete_knowledge_api(*, knowledge_id: int): raise HTTPException(status_code=404, detail='knowledge not found') try: delete_knowledge_by(knowledge) - delete_knowledge_hook(knowledge, UserPayload(**{ - "user_id": knowledge.user_id - })) return {'message': 'knowledge deleted successfully'} except Exception as e: logger.exception(e) From 0fe70c851b4d96a2b68b3915284934d4fdc2a1e1 Mon Sep 17 00:00:00 2001 From: GuoQing Zhang Date: Tue, 2 Jul 2024 19:46:30 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E8=BF=87=E5=A4=9A=E5=AF=BC=E8=87=B4=E7=9A=84?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E8=B6=85=E9=95=BF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/bisheng/database/models/audit_log.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/bisheng/database/models/audit_log.py b/src/backend/bisheng/database/models/audit_log.py index 7cfbda92c..822072a07 100644 --- a/src/backend/bisheng/database/models/audit_log.py +++ b/src/backend/bisheng/database/models/audit_log.py @@ -63,7 +63,7 @@ class AuditLogBase(SQLModelSerializable): event_type: Optional[str] = Field(index=True, description="操作行为") object_type: Optional[str] = Field(index=True, description="操作对象类型") object_id: Optional[int] = Field(index=True, description="操作对象ID") - object_name: Optional[str] = Field(description="操作对象名称") + object_name: Optional[str] = Field(sa_column=Column(Text), description="操作对象名称") note: Optional[str] = Field(sa_column=Column(Text), description="操作备注") ip_address: Optional[str] = Field(index=True, description="操作时客户端的IP地址") create_time: Optional[datetime] = Field(sa_column=Column(