mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-08-05 15:20:30 +08:00
@@ -215,10 +215,10 @@ func (h *Handler) ListUsers(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
ctx := c.Request.Context()
|
||||
var users []map[string]interface{}
|
||||
switch common.GetRAGFlowType() {
|
||||
case common.OpenSourceVersion:
|
||||
ctx := c.Request.Context()
|
||||
users, err = h.service.ListUsers(ctx, pageInt, pageSizeInt, name, status, sort, orderBy)
|
||||
if err != nil {
|
||||
common.ErrorWithCode(c, common.CodeServerError, err.Error())
|
||||
@@ -228,7 +228,7 @@ func (h *Handler) ListUsers(c *gin.Context) {
|
||||
common.SuccessWithData(c, users, "List users")
|
||||
return
|
||||
case common.EnterpriseEdition:
|
||||
users, err = h.service.ListUsersEE(pageInt, pageSizeInt, name, status, role, sort, orderBy, plan, topInt, daysInt, quotaPtr)
|
||||
users, err = h.service.ListUsersEE(ctx, pageInt, pageSizeInt, name, status, role, sort, orderBy, plan, topInt, daysInt, quotaPtr)
|
||||
if err != nil {
|
||||
common.ErrorWithCode(c, common.CodeServerError, err.Error())
|
||||
return
|
||||
@@ -865,7 +865,7 @@ func (h *Handler) HandleNoRoute(c *gin.Context) {
|
||||
|
||||
// GetLogLevel returns the current log level
|
||||
func (h *Handler) GetLogLevel(c *gin.Context) {
|
||||
level := common.GetLevel()
|
||||
level := common.GetLogLevel()
|
||||
common.SuccessWithData(c, gin.H{"level": level}, "SUCCESS")
|
||||
}
|
||||
|
||||
@@ -882,7 +882,7 @@ func (h *Handler) SetLogLevel(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := common.SetLevel(req.Level); err != nil {
|
||||
if err := common.SetLogLevel(req.Level); err != nil {
|
||||
common.ErrorWithCode(c, common.CodeBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
@@ -1095,11 +1095,12 @@ func (h *Handler) ListIngestionTasks(c *gin.Context) {
|
||||
var err error
|
||||
var tasks []map[string]interface{}
|
||||
var req ListIngestionTasksRequest
|
||||
ctx := c.Request.Context()
|
||||
|
||||
if err = c.ShouldBindJSON(&req); err != nil {
|
||||
ctx := c.Request.Context()
|
||||
tasks, err = h.service.ListIngestionTasks(ctx)
|
||||
} else {
|
||||
tasks, err = h.service.ListIngestionTasksByCondition(req.Email, req.Status)
|
||||
tasks, err = h.service.ListIngestionTasksByCondition(ctx, req.Email, req.Status)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
|
||||
@@ -887,7 +887,9 @@ func (h *Handler) ShowUserSummary(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
userSummary, err := h.service.ShowUserSummary(username)
|
||||
ctx := c.Request.Context()
|
||||
|
||||
userSummary, err := h.service.ShowUserSummary(ctx, username)
|
||||
if err != nil {
|
||||
if errors.Is(err, common.ErrUserNotFound) {
|
||||
common.ErrorWithCode(c, common.CodeNotFound, "User not found")
|
||||
@@ -927,7 +929,9 @@ func (h *Handler) ShowUserQuota(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
userQuota, err := h.service.ShowUserQuota(username)
|
||||
ctx := c.Request.Context()
|
||||
|
||||
userQuota, err := h.service.ShowUserQuota(ctx, username)
|
||||
if err != nil {
|
||||
if errors.Is(err, common.ErrUserNotFound) {
|
||||
common.ErrorWithCode(c, common.CodeNotFound, "User not found")
|
||||
@@ -1923,7 +1927,9 @@ func (h *Handler) GetTokenStats(c *gin.Context) {
|
||||
}
|
||||
granularity = strings.ToLower(granularity)
|
||||
|
||||
stats, err := h.service.GetTokenStats(userName, fromDate, toDate, granularity)
|
||||
ctx := c.Request.Context()
|
||||
|
||||
stats, err := h.service.GetTokenStats(ctx, userName, fromDate, toDate, granularity)
|
||||
if err != nil {
|
||||
common.ErrorWithCode(c, common.CodeDataError, err.Error())
|
||||
return
|
||||
@@ -1990,8 +1996,9 @@ func (h *Handler) ListLogs(c *gin.Context) {
|
||||
common.ErrorWithCode(c, common.CodeBadRequest, "Invalid days")
|
||||
return
|
||||
}
|
||||
ctx := c.Request.Context()
|
||||
|
||||
stats, err := h.service.ListLogs(userName, daysInt)
|
||||
stats, err := h.service.ListLogs(ctx, userName, daysInt)
|
||||
if err != nil {
|
||||
common.ErrorWithCode(c, common.CodeDataError, err.Error())
|
||||
return
|
||||
|
||||
@@ -441,10 +441,10 @@ func (s *Service) ShowUserDatasetSummary(email, dataset string) (map[string]inte
|
||||
}
|
||||
|
||||
// ShowUserSummary show user summary for enterprise edition
|
||||
func (s *Service) ShowUserSummary(email string) (map[string]interface{}, error) {
|
||||
func (s *Service) ShowUserSummary(ctx context.Context, email string) (map[string]interface{}, error) {
|
||||
// Query user by email
|
||||
var user entity.User
|
||||
err := dao.DB.Where("email = ?", email).First(&user).Error
|
||||
err := dao.DB.WithContext(ctx).Where("email = ?", email).First(&user).Error
|
||||
if err != nil {
|
||||
return nil, common.ErrUserNotFound
|
||||
}
|
||||
@@ -477,10 +477,10 @@ func (s *Service) ShowUserStorage(email string) (map[string]interface{}, error)
|
||||
}
|
||||
|
||||
// ShowUserQuota show user quota for enterprise edition
|
||||
func (s *Service) ShowUserQuota(email string) (map[string]interface{}, error) {
|
||||
func (s *Service) ShowUserQuota(ctx context.Context, email string) (map[string]interface{}, error) {
|
||||
// Query user by email
|
||||
var user entity.User
|
||||
err := dao.DB.Where("email = ?", email).First(&user).Error
|
||||
err := dao.DB.WithContext(ctx).Where("email = ?", email).First(&user).Error
|
||||
if err != nil {
|
||||
return nil, common.ErrUserNotFound
|
||||
}
|
||||
@@ -794,7 +794,7 @@ func (s *Service) ShowUsersActivity(days, windows *int) (map[string]interface{},
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (s *Service) ListUsersEE(pageIndex, pageSize int, name string, status, role, sort, orderBy, plan string, top, days int, quota *int) ([]map[string]interface{}, error) {
|
||||
func (s *Service) ListUsersEE(ctx context.Context, pageIndex, pageSize int, name string, status, role, sort, orderBy, plan string, top, days int, quota *int) ([]map[string]interface{}, error) {
|
||||
item := map[string]interface{}{}
|
||||
item["pageIndex"] = pageIndex
|
||||
item["pageSize"] = pageSize
|
||||
@@ -1119,7 +1119,7 @@ func (s *Service) ListUserAPIKeys(ctx context.Context, username string) ([]map[s
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (s *Service) ListIngestionTasksByCondition(email, status *string) ([]map[string]interface{}, error) {
|
||||
func (s *Service) ListIngestionTasksByCondition(ctx context.Context, email, status *string) ([]map[string]interface{}, error) {
|
||||
|
||||
if email == nil && status == nil {
|
||||
return nil, fmt.Errorf("email or status are required")
|
||||
@@ -1299,7 +1299,7 @@ func (s *Service) BatchDeleteWhiteList(ids []int) (map[string]interface{}, error
|
||||
}
|
||||
|
||||
// GetTokenStats returns API token statistics for the user.
|
||||
func (s *Service) GetTokenStats(userName, fromDate, toDate, granularity string) ([]map[string]interface{}, error) {
|
||||
func (s *Service) GetTokenStats(ctx context.Context, userName, fromDate, toDate, granularity string) ([]map[string]interface{}, error) {
|
||||
result := []map[string]interface{}{
|
||||
{
|
||||
"command": "get_token_stats",
|
||||
@@ -1340,7 +1340,7 @@ func (s *Service) GetTokenStatsSummary(fromDate, toDate string) (map[string]inte
|
||||
}
|
||||
|
||||
// ListLogs lists operation logs for the user.
|
||||
func (s *Service) ListLogs(userName string, days int) ([]map[string]interface{}, error) {
|
||||
func (s *Service) ListLogs(ctx context.Context, userName string, days int) ([]map[string]interface{}, error) {
|
||||
result := []map[string]interface{}{
|
||||
{
|
||||
"command": "list_logs",
|
||||
|
||||
Reference in New Issue
Block a user