mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-28 03:38:11 +08:00
Go: add audit log framework (#17129)
### Summary Prepare for audit log --------- Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
@@ -1968,3 +1968,29 @@ func (h *Handler) GetTokenStatsSummary(c *gin.Context) {
|
||||
|
||||
common.SuccessWithData(c, stats, "success")
|
||||
}
|
||||
|
||||
func (h *Handler) ListLogs(c *gin.Context) {
|
||||
userName := c.Query("user_name")
|
||||
if userName == "" {
|
||||
common.ErrorWithCode(c, common.CodeBadRequest, "User name is required")
|
||||
return
|
||||
}
|
||||
days := c.Query("days")
|
||||
if days == "" {
|
||||
days = "7"
|
||||
}
|
||||
daysInt, err := strconv.Atoi(days)
|
||||
if err != nil {
|
||||
common.ErrorWithCode(c, common.CodeBadRequest, "Invalid days")
|
||||
return
|
||||
}
|
||||
|
||||
stats, err := h.service.ListLogs(userName, daysInt)
|
||||
if err != nil {
|
||||
common.ErrorWithCode(c, common.CodeDataError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
common.SuccessWithData(c, stats, "success")
|
||||
|
||||
}
|
||||
|
||||
@@ -80,6 +80,9 @@ func RegisterEERouter(protected *gin.RouterGroup, r *Router) {
|
||||
protected.GET("/stats/token/users", r.handler.GetTokenUsersStats)
|
||||
protected.GET("/stats/token/summary", r.handler.GetTokenStatsSummary)
|
||||
|
||||
// Logs
|
||||
protected.GET("/logs", r.handler.ListLogs)
|
||||
|
||||
// Stats data info
|
||||
protected.GET("/users/:username/activity", r.handler.ShowUserActivity)
|
||||
protected.GET("/users/:username/dataset", r.handler.ShowUserDatasetSummary)
|
||||
|
||||
@@ -1328,3 +1328,16 @@ func (s *Service) GetTokenStatsSummary(fromDate, toDate string) (map[string]inte
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// ListLogs lists operation logs for the user.
|
||||
func (s *Service) ListLogs(userName string, days int) ([]map[string]interface{}, error) {
|
||||
result := []map[string]interface{}{
|
||||
{
|
||||
"command": "list_logs",
|
||||
"user_name": userName,
|
||||
"days": days,
|
||||
"error": "'List operation logs' is not supported",
|
||||
},
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user