Skip to content

Commit 95b058a

Browse files
committed
refactor: add log
1 parent e5fd7d2 commit 95b058a

File tree

10 files changed

+38
-25
lines changed

10 files changed

+38
-25
lines changed

backend/apps/chat/api/chat.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ async def start_chat(session: SessionDep, current_user: CurrentUser, create_chat
167167

168168

169169
@router.post("/assistant/start", response_model=ChatInfo, summary=f"{PLACEHOLDER_PREFIX}assistant_start_chat")
170+
@system_log(LogConfig(
171+
operation_type=OperationType.CREATE,
172+
module=OperationModules.CHAT,
173+
result_id_expr="id"
174+
))
170175
async def start_chat(session: SessionDep, current_user: CurrentUser):
171176
try:
172177
return create_chat(session, current_user, CreateChat(origin=2), False)
@@ -436,8 +441,9 @@ def _err(_e: Exception):
436441
)
437442

438443

439-
@router.get("/record/{chat_record_id}/excel/export", summary=f"{PLACEHOLDER_PREFIX}export_chart_data")
440-
async def export_excel(session: SessionDep, current_user: CurrentUser, chat_record_id: int, trans: Trans):
444+
@router.get("/record/{chat_record_id}/excel/export/{chat_id}", summary=f"{PLACEHOLDER_PREFIX}export_chart_data")
445+
@system_log(LogConfig(operation_type=OperationType.EXPORT,module=OperationModules.CHAT,resource_id_expr="chat_id",))
446+
async def export_excel(session: SessionDep, current_user: CurrentUser, chat_record_id: int,chat_id: int, trans: Trans):
441447
chat_record = session.get(ChatRecord, chat_record_id)
442448
if not chat_record:
443449
raise HTTPException(

backend/apps/datasource/api/table_relation.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
from apps.swagger.i18n import PLACEHOLDER_PREFIX
99
from apps.system.schemas.permission import SqlbotPermission, require_permissions
1010
from common.core.deps import SessionDep
11-
11+
from common.audit.models.log_model import OperationType, OperationModules
12+
from common.audit.schemas.logger_decorator import LogConfig, system_log
1213
router = APIRouter(tags=["Table Relation"], prefix="/table_relation")
1314

1415

1516
@router.post("/save/{ds_id}", response_model=None, summary=f"{PLACEHOLDER_PREFIX}tr_save")
1617
@require_permissions(permission=SqlbotPermission(role=['ws_admin'], keyExpression="ds_id", type='ds'))
18+
@system_log(LogConfig(operation_type=OperationType.UPDATE_TABLE_RELATION,module=OperationModules.DATASOURCE,resource_id_expr="ds_id"))
1719
async def save_relation(session: SessionDep, relation: List[dict],
1820
ds_id: int = Path(..., description=f"{PLACEHOLDER_PREFIX}ds_id")):
1921
ds = session.get(CoreDatasource, ds_id)

backend/apps/system/api/assistant.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ def iterfile():
108108

109109

110110
@router.patch('/ui', summary=f"{PLACEHOLDER_PREFIX}assistant_ui_api", description=f"{PLACEHOLDER_PREFIX}assistant_ui_api")
111+
@system_log(LogConfig(operation_type=OperationType.UPDATE, module=OperationModules.APPLICATION, result_id_expr="id"))
111112
async def ui(session: SessionDep, data: str = Form(), files: List[UploadFile] = []):
112113
json_data = json.loads(data)
113114
uiSchema = AssistantUiSchema(**json_data)
@@ -155,6 +156,7 @@ async def ui(session: SessionDep, data: str = Form(), files: List[UploadFile] =
155156
session.add(db_model)
156157
session.commit()
157158
await clear_ui_cache(db_model.id)
159+
return db_model
158160

159161

160162
@clear_cache(namespace=CacheNamespace.EMBEDDED_INFO, cacheName=CacheName.ASSISTANT_INFO, keyExpression="id")

backend/apps/system/api/user.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,7 @@ async def langChange(session: SessionDep, current_user: CurrentUser, trans: Tran
272272
@router.patch("/pwd/{id}", summary=f"{PLACEHOLDER_PREFIX}reset_pwd", description=f"{PLACEHOLDER_PREFIX}reset_pwd")
273273
@require_permissions(permission=SqlbotPermission(role=['admin']))
274274
@clear_cache(namespace=CacheNamespace.AUTH_INFO, cacheName=CacheName.USER_INFO, keyExpression="id")
275-
@system_log(LogConfig(
276-
operation_type=OperationType.UPDATE,
277-
module=OperationModules.USER,
278-
resource_id_expr="id"
279-
))
275+
@system_log(LogConfig(operation_type=OperationType.RESET_PWD,module=OperationModules.USER,resource_id_expr="id"))
280276
async def pwdReset(session: SessionDep, current_user: CurrentUser, trans: Trans, id: int = Path(description=f"{PLACEHOLDER_PREFIX}uid")):
281277
if not current_user.isAdmin:
282278
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,
286282

287283
@router.put("/pwd", summary=f"{PLACEHOLDER_PREFIX}update_pwd", description=f"{PLACEHOLDER_PREFIX}update_pwd")
288284
@clear_cache(namespace=CacheNamespace.AUTH_INFO, cacheName=CacheName.USER_INFO, keyExpression="current_user.id")
289-
@system_log(LogConfig(
290-
operation_type=OperationType.UPDATE,
291-
module=OperationModules.USER,
292-
result_id_expr="id"
293-
))
285+
@system_log(LogConfig(operation_type=OperationType.UPDATE_PWD,module=OperationModules.USER,result_id_expr="id"))
294286
async def pwdUpdate(session: SessionDep, current_user: CurrentUser, trans: Trans, editor: PwdEditor):
295287
new_pwd = editor.new_pwd
296288
if not check_pwd_format(new_pwd):
@@ -306,11 +298,7 @@ async def pwdUpdate(session: SessionDep, current_user: CurrentUser, trans: Trans
306298
@router.patch("/status", summary=f"{PLACEHOLDER_PREFIX}update_status", description=f"{PLACEHOLDER_PREFIX}update_status")
307299
@require_permissions(permission=SqlbotPermission(role=['admin']))
308300
@clear_cache(namespace=CacheNamespace.AUTH_INFO, cacheName=CacheName.USER_INFO, keyExpression="statusDto.id")
309-
@system_log(LogConfig(
310-
operation_type=OperationType.UPDATE,
311-
module=OperationModules.USER,
312-
resource_id_expr="statusDto.id"
313-
))
301+
@system_log(LogConfig(operation_type=OperationType.UPDATE_STATUS,module=OperationModules.USER, resource_id_expr="statusDto.id"))
314302
async def statusChange(session: SessionDep, current_user: CurrentUser, trans: Trans, statusDto: UserStatus):
315303
if not current_user.isAdmin:
316304
raise Exception(trans('i18n_permission.no_permission', url = ", ", msg = trans('i18n_permission.only_admin')))

backend/common/audit/models/log_model.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ class OperationType(str, Enum):
3434
CREATE = "create"
3535
DELETE = "delete"
3636
UPDATE = "update"
37+
RESET_PWD = "reset_pwd"
38+
UPDATE_PWD = "update_pwd"
39+
UPDATE_STATUS = "update_status"
40+
UPDATE_TABLE_RELATION = "update_table_relation"
3741
EDIT = "edit"
3842
LOGIN = "login"
3943
VIEW = "view"

backend/locales/en.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,11 @@
178178
"system_management": "System Management",
179179
"opt_log": "Operation Log",
180180
"prediction": "Data prediction",
181-
"analysis": "Data analysis"
181+
"analysis": "Data analysis",
182+
"reset_pwd": "Reset Password",
183+
"update_pwd": "Update Password",
184+
"update_status": "Update Status",
185+
"update_table_relation": "Change Table Relation"
182186
},
183187
"i18n_table_not_exist": "Table not exist"
184188
}

backend/locales/ko-KR.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,11 @@
178178
"system_management": "시스템 관리",
179179
"opt_log": "작업 로그",
180180
"prediction": "데이터 예측",
181-
"analysis": "데이터 분석"
181+
"analysis": "데이터 분석",
182+
"reset_pwd": "비밀번호 재설정",
183+
"update_pwd": "비밀번호 업데이트",
184+
"update_status": "상태 업데이트",
185+
"update_table_relation": "테이블 관계 변경"
182186
},
183187
"i18n_table_not_exist": "현재 테이블이 존재하지 않습니다"
184188
}

backend/locales/zh-CN.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,11 @@
178178
"system_management": "系统管理",
179179
"opt_log": "操作日志",
180180
"prediction": "数据预测",
181-
"analysis": "数据分析"
182-
181+
"analysis": "数据分析",
182+
"reset_pwd": "重置密码",
183+
"update_pwd": "更新密码",
184+
"update_status": "更新状态",
185+
"update_table_relation": "变更表关系"
183186
},
184187
"i18n_table_not_exist": "当前表不存在"
185188
}

frontend/src/api/chat.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,8 @@ export const chatApi = {
356356
return request.get(`/chat/recent_questions/${datasource_id}`)
357357
},
358358
checkLLMModel: () => request.get('/system/aimodel/default', { requestOptions: { silent: true } }),
359-
export2Excel: (record_id: number | undefined) =>
360-
request.get(`/chat/record/${record_id}/excel/export`, {
359+
export2Excel: (record_id: number | undefined, chat_id: any) =>
360+
request.get(`/chat/record/${record_id}/excel/export/${chat_id}`, {
361361
responseType: 'blob',
362362
requestOptions: { customError: true },
363363
}),

frontend/src/views/chat/chat-block/ChartBlock.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ function exportToExcel() {
247247
if (chartRef.value && props.recordId) {
248248
loading.value = true
249249
chatApi
250-
.export2Excel(props.recordId)
250+
.export2Excel(props.recordId, props.message?.record?.chat_id || 0)
251251
.then((res) => {
252252
const blob = new Blob([res], {
253253
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',

0 commit comments

Comments
 (0)