diff --git a/backend/apps/chat/api/chat.py b/backend/apps/chat/api/chat.py index 7ca3d571..56c5fe66 100644 --- a/backend/apps/chat/api/chat.py +++ b/backend/apps/chat/api/chat.py @@ -167,6 +167,11 @@ async def start_chat(session: SessionDep, current_user: CurrentUser, create_chat @router.post("/assistant/start", response_model=ChatInfo, summary=f"{PLACEHOLDER_PREFIX}assistant_start_chat") +@system_log(LogConfig( + operation_type=OperationType.CREATE, + module=OperationModules.CHAT, + result_id_expr="id" +)) async def start_chat(session: SessionDep, current_user: CurrentUser): try: return create_chat(session, current_user, CreateChat(origin=2), False) @@ -436,8 +441,9 @@ async def analysis_or_predict(session: SessionDep, current_user: CurrentUser, ch ) -@router.get("/record/{chat_record_id}/excel/export", summary=f"{PLACEHOLDER_PREFIX}export_chart_data") -async def export_excel(session: SessionDep, current_user: CurrentUser, chat_record_id: int, trans: Trans): +@router.get("/record/{chat_record_id}/excel/export/{chat_id}", summary=f"{PLACEHOLDER_PREFIX}export_chart_data") +@system_log(LogConfig(operation_type=OperationType.EXPORT,module=OperationModules.CHAT,resource_id_expr="chat_id",)) +async def export_excel(session: SessionDep, current_user: CurrentUser, chat_record_id: int,chat_id: int, trans: Trans): chat_record = session.get(ChatRecord, chat_record_id) if not chat_record: raise HTTPException( diff --git a/backend/apps/datasource/api/table_relation.py b/backend/apps/datasource/api/table_relation.py index 21d433a5..6454dc8b 100644 --- a/backend/apps/datasource/api/table_relation.py +++ b/backend/apps/datasource/api/table_relation.py @@ -8,12 +8,14 @@ from apps.datasource.models.datasource import CoreDatasource from apps.swagger.i18n import PLACEHOLDER_PREFIX from apps.system.schemas.permission import SqlbotPermission, require_permissions from common.core.deps import SessionDep - +from common.audit.models.log_model import OperationType, OperationModules +from common.audit.schemas.logger_decorator import LogConfig, system_log router = APIRouter(tags=["Table Relation"], prefix="/table_relation") @router.post("/save/{ds_id}", response_model=None, summary=f"{PLACEHOLDER_PREFIX}tr_save") @require_permissions(permission=SqlbotPermission(role=['ws_admin'], keyExpression="ds_id", type='ds')) +@system_log(LogConfig(operation_type=OperationType.UPDATE_TABLE_RELATION,module=OperationModules.DATASOURCE,resource_id_expr="ds_id")) async def save_relation(session: SessionDep, relation: List[dict], ds_id: int = Path(..., description=f"{PLACEHOLDER_PREFIX}ds_id")): ds = session.get(CoreDatasource, ds_id) diff --git a/backend/apps/system/api/assistant.py b/backend/apps/system/api/assistant.py index 69c90746..c0e375ad 100644 --- a/backend/apps/system/api/assistant.py +++ b/backend/apps/system/api/assistant.py @@ -108,6 +108,7 @@ async def picture(file_id: str = Path(description="file_id")): @router.patch('/ui', summary=f"{PLACEHOLDER_PREFIX}assistant_ui_api", description=f"{PLACEHOLDER_PREFIX}assistant_ui_api") +@system_log(LogConfig(operation_type=OperationType.UPDATE, module=OperationModules.APPLICATION, result_id_expr="id")) async def ui(session: SessionDep, data: str = Form(), files: List[UploadFile] = []): json_data = json.loads(data) uiSchema = AssistantUiSchema(**json_data) @@ -155,6 +156,7 @@ async def ui(session: SessionDep, data: str = Form(), files: List[UploadFile] = session.add(db_model) session.commit() await clear_ui_cache(db_model.id) + return db_model @clear_cache(namespace=CacheNamespace.EMBEDDED_INFO, cacheName=CacheName.ASSISTANT_INFO, keyExpression="id") diff --git a/backend/apps/system/api/user.py b/backend/apps/system/api/user.py index f9a9b1a5..a8c152d2 100644 --- a/backend/apps/system/api/user.py +++ b/backend/apps/system/api/user.py @@ -272,11 +272,7 @@ async def langChange(session: SessionDep, current_user: CurrentUser, trans: Tran @router.patch("/pwd/{id}", summary=f"{PLACEHOLDER_PREFIX}reset_pwd", description=f"{PLACEHOLDER_PREFIX}reset_pwd") @require_permissions(permission=SqlbotPermission(role=['admin'])) @clear_cache(namespace=CacheNamespace.AUTH_INFO, cacheName=CacheName.USER_INFO, keyExpression="id") -@system_log(LogConfig( - operation_type=OperationType.UPDATE, - module=OperationModules.USER, - resource_id_expr="id" -)) +@system_log(LogConfig(operation_type=OperationType.RESET_PWD,module=OperationModules.USER,resource_id_expr="id")) async def pwdReset(session: SessionDep, current_user: CurrentUser, trans: Trans, id: int = Path(description=f"{PLACEHOLDER_PREFIX}uid")): if not current_user.isAdmin: raise Exception(trans('i18n_permission.no_permission', url = " patch[/user/pwd/id],", msg = trans('i18n_permission.only_admin'))) @@ -286,11 +282,7 @@ async def pwdReset(session: SessionDep, current_user: CurrentUser, trans: Trans, @router.put("/pwd", summary=f"{PLACEHOLDER_PREFIX}update_pwd", description=f"{PLACEHOLDER_PREFIX}update_pwd") @clear_cache(namespace=CacheNamespace.AUTH_INFO, cacheName=CacheName.USER_INFO, keyExpression="current_user.id") -@system_log(LogConfig( - operation_type=OperationType.UPDATE, - module=OperationModules.USER, - result_id_expr="id" -)) +@system_log(LogConfig(operation_type=OperationType.UPDATE_PWD,module=OperationModules.USER,result_id_expr="id")) async def pwdUpdate(session: SessionDep, current_user: CurrentUser, trans: Trans, editor: PwdEditor): new_pwd = editor.new_pwd if not check_pwd_format(new_pwd): @@ -306,11 +298,7 @@ async def pwdUpdate(session: SessionDep, current_user: CurrentUser, trans: Trans @router.patch("/status", summary=f"{PLACEHOLDER_PREFIX}update_status", description=f"{PLACEHOLDER_PREFIX}update_status") @require_permissions(permission=SqlbotPermission(role=['admin'])) @clear_cache(namespace=CacheNamespace.AUTH_INFO, cacheName=CacheName.USER_INFO, keyExpression="statusDto.id") -@system_log(LogConfig( - operation_type=OperationType.UPDATE, - module=OperationModules.USER, - resource_id_expr="statusDto.id" -)) +@system_log(LogConfig(operation_type=OperationType.UPDATE_STATUS,module=OperationModules.USER, resource_id_expr="statusDto.id")) async def statusChange(session: SessionDep, current_user: CurrentUser, trans: Trans, statusDto: UserStatus): if not current_user.isAdmin: raise Exception(trans('i18n_permission.no_permission', url = ", ", msg = trans('i18n_permission.only_admin'))) diff --git a/backend/common/audit/models/log_model.py b/backend/common/audit/models/log_model.py index 975191be..bdafe6a6 100644 --- a/backend/common/audit/models/log_model.py +++ b/backend/common/audit/models/log_model.py @@ -34,6 +34,10 @@ class OperationType(str, Enum): CREATE = "create" DELETE = "delete" UPDATE = "update" + RESET_PWD = "reset_pwd" + UPDATE_PWD = "update_pwd" + UPDATE_STATUS = "update_status" + UPDATE_TABLE_RELATION = "update_table_relation" EDIT = "edit" LOGIN = "login" VIEW = "view" diff --git a/backend/locales/en.json b/backend/locales/en.json index c784baea..fb9e1ad8 100644 --- a/backend/locales/en.json +++ b/backend/locales/en.json @@ -178,7 +178,11 @@ "system_management": "System Management", "opt_log": "Operation Log", "prediction": "Data prediction", - "analysis": "Data analysis" + "analysis": "Data analysis", + "reset_pwd": "Reset Password", + "update_pwd": "Update Password", + "update_status": "Update Status", + "update_table_relation": "Change Table Relation" }, "i18n_table_not_exist": "Table not exist" } \ No newline at end of file diff --git a/backend/locales/ko-KR.json b/backend/locales/ko-KR.json index d46cc2ee..4d5cdd76 100644 --- a/backend/locales/ko-KR.json +++ b/backend/locales/ko-KR.json @@ -178,7 +178,11 @@ "system_management": "시스템 관리", "opt_log": "작업 로그", "prediction": "데이터 예측", - "analysis": "데이터 분석" + "analysis": "데이터 분석", + "reset_pwd": "비밀번호 재설정", + "update_pwd": "비밀번호 업데이트", + "update_status": "상태 업데이트", + "update_table_relation": "테이블 관계 변경" }, "i18n_table_not_exist": "현재 테이블이 존재하지 않습니다" } \ No newline at end of file diff --git a/backend/locales/zh-CN.json b/backend/locales/zh-CN.json index 2dc2a1a5..8fe37bcf 100644 --- a/backend/locales/zh-CN.json +++ b/backend/locales/zh-CN.json @@ -178,8 +178,11 @@ "system_management": "系统管理", "opt_log": "操作日志", "prediction": "数据预测", - "analysis": "数据分析" - + "analysis": "数据分析", + "reset_pwd": "重置密码", + "update_pwd": "更新密码", + "update_status": "更新状态", + "update_table_relation": "变更表关系" }, "i18n_table_not_exist": "当前表不存在" } \ No newline at end of file diff --git a/frontend/src/api/chat.ts b/frontend/src/api/chat.ts index 2899abd1..6c471f8c 100644 --- a/frontend/src/api/chat.ts +++ b/frontend/src/api/chat.ts @@ -356,8 +356,8 @@ export const chatApi = { return request.get(`/chat/recent_questions/${datasource_id}`) }, checkLLMModel: () => request.get('/system/aimodel/default', { requestOptions: { silent: true } }), - export2Excel: (record_id: number | undefined) => - request.get(`/chat/record/${record_id}/excel/export`, { + export2Excel: (record_id: number | undefined, chat_id: any) => + request.get(`/chat/record/${record_id}/excel/export/${chat_id}`, { responseType: 'blob', requestOptions: { customError: true }, }), diff --git a/frontend/src/views/chat/chat-block/ChartBlock.vue b/frontend/src/views/chat/chat-block/ChartBlock.vue index 2a62a14b..2fa1cc7e 100644 --- a/frontend/src/views/chat/chat-block/ChartBlock.vue +++ b/frontend/src/views/chat/chat-block/ChartBlock.vue @@ -247,7 +247,7 @@ function exportToExcel() { if (chartRef.value && props.recordId) { loading.value = true chatApi - .export2Excel(props.recordId) + .export2Excel(props.recordId, props.message?.record?.chat_id || 0) .then((res) => { const blob = new Blob([res], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',