Skip to content

Commit

Permalink
Feat/0.3.2.1 (#723)
Browse files Browse the repository at this point in the history
  • Loading branch information
zgqgit authored Jul 2, 2024
2 parents c07e208 + 0fe70c8 commit 5db1217
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
25 changes: 21 additions & 4 deletions src/backend/bisheng/api/v1/knowledge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
11 changes: 1 addition & 10 deletions src/backend/bisheng/api/v2/filelib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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


Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/backend/bisheng/database/models/audit_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ 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="操作对象名称")
note: Optional[str] = Field(sa_column=Column(Text(255)), 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(
DateTime, nullable=False, index=True, server_default=text('CURRENT_TIMESTAMP')), description="操作时间")
Expand Down

0 comments on commit 5db1217

Please sign in to comment.