Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

refactor(admin): isolate user agent and dataset listings in EE files (#21210)

adws354090279ba3
diff --git a/internal/admin/handler_ee.go b/internal/admin/handler_ee.go
index 90a110f757..1ebe6d2c1d 100644
--- a/internal/admin/handler_ee.go
+++ b/internal/admin/handler_ee.go
@@ -1101,46 +1101,14 @@ func (h *Handler) ShowUserPermission(c *gin.Context) {
common.SuccessWithData(c, permissions, "")
}
-// ListUserDatasets handle show user datasets
+// ListUserDatasets requires the enterprise edition.
func (h *Handler) ListUserDatasets(c *gin.Context) {
- username, err := getUserName(c)
- if err != nil {
- return
- }
- ctx := c.Request.Context()
-
- datasets, err := h.service.ListUserDatasets(ctx, username)
- if err != nil {
- if errors.Is(err, common.ErrUserNotFound) {
- common.ErrorWithCode(c, common.CodeNotFound, "User not found")
- return
- }
- common.ErrorWithCode(c, common.CodeServerError, err.Error())
- return
- }
-
- common.SuccessWithData(c, datasets, "")
+ common.ResponseWithHttpCodeData(c, http.StatusNotImplemented, common.CodeNotImplemented, nil, "listing user datasets is only available in the enterprise edition")
}
-// ListUserAgents handle show user agents
+// ListUserAgents requires the enterprise edition.
func (h *Handler) ListUserAgents(c *gin.Context) {
- username, err := getUserName(c)
- if err != nil {
- return
- }
- ctx := c.Request.Context()
-
- agents, err := h.service.ListUserAgents(ctx, username)
- if err != nil {
- if errors.Is(err, common.ErrUserNotFound) {
- common.ErrorWithCode(c, common.CodeNotFound, "User not found")
- return
- }
- common.ErrorWithCode(c, common.CodeServerError, err.Error())
- return
- }
-
- common.SuccessWithData(c, agents, "")
+ common.ResponseWithHttpCodeData(c, http.StatusNotImplemented, common.CodeNotImplemented, nil, "listing user agents is only available in the enterprise edition")
}
// ListUserChats handle show user chats
diff --git a/internal/admin/service_ee.go b/internal/admin/service_ee.go
index 5aa2485e9e..01edb94647 100644
--- a/internal/admin/service_ee.go
+++ b/internal/admin/service_ee.go
@@ -21,15 +21,10 @@ import (
"errors"
"fmt"
"mime/multipart"
- "sort"
- "strings"
"ragflow/internal/common"
"ragflow/internal/dao"
"ragflow/internal/entity"
- "ragflow/internal/permission"
-
- "gorm.io/gorm"
)
func UpdateServer(serverName string, status *common.BaseMessage) (common.ErrorCode, map[string]interface{}, string) {
@@ -589,96 +584,14 @@ func (s *Service) ShowUserPermission(ctx context.Context, email string) (map[str
return result, nil
}
-// ListUserDatasets show user datasets for enterprise edition
+// ListUserDatasets requires the enterprise edition.
func (s *Service) ListUserDatasets(ctx context.Context, email string) ([]map[string]interface{}, error) {
- user, err := s.userDAO.GetByEmail(ctx, dao.DB, email)
- if err != nil {
- if errors.Is(err, gorm.ErrRecordNotFound) {
- return nil, common.ErrUserNotFound
- }
- return nil, fmt.Errorf("failed to get user: %w", err)
- }
-
- scope, err := permission.NewDatabaseChecker(dao.DB).Scope(ctx, permission.Subject{UserID: user.ID}, permission.ScopeQuery{
- Kind: permission.ResourceKindDataset, Operation: permission.OperationRead,
- })
- if err != nil {
- return nil, fmt.Errorf("failed to resolve user dataset permissions: %w", err)
- }
-
- var datasets []*entity.Knowledgebase
- if scope.Mode == permission.ScopeIDs {
- datasets, err = s.kbDAO.GetByIDs(ctx, dao.DB, scope.ResourceIDs)
- if err != nil {
- return nil, fmt.Errorf("failed to get user datasets: %w", err)
- }
- sort.SliceStable(datasets, func(i, j int) bool {
- if datasets[i].CreateTime == nil {
- return datasets[j].CreateTime != nil
- }
- if datasets[j].CreateTime == nil {
- return false
- }
- return *datasets[i].CreateTime < *datasets[j].CreateTime
- })
- }
-
- result := make([]map[string]interface{}, 0, len(datasets))
- for _, dataset := range datasets {
- status := ""
- if dataset.Status != nil {
- status = *dataset.Status
- }
- result = append(result, map[string]interface{}{
- "name": dataset.Name,
- "avatar": dataset.Avatar,
- "language": dataset.Language,
- "permission": dataset.Permission,
- "doc_num": dataset.DocNum,
- "token_num": dataset.TokenNum,
- "chunk_num": dataset.ChunkNum,
- "status": status,
- "create_date": dataset.CreateDate,
- "update_date": dataset.UpdateDate,
- })
- }
- return result, nil
-}
-
-// ListUserAgents show user agents for enterprise edition
-func (s *Service) ListUserAgents(ctx context.Context, email string) ([]map[string]interface{}, error) {
- user, err := s.userDAO.GetByEmail(ctx, dao.DB, email)
- if err != nil {
- if errors.Is(err, gorm.ErrRecordNotFound) {
- return nil, common.ErrUserNotFound
- }
- return nil, fmt.Errorf("failed to get user: %w", err)
- }
-
- tenantIDs, err := s.userTenantDAO.GetTenantIDsByUserID(ctx, dao.DB, user.ID)
- if err != nil {
- return nil, fmt.Errorf("failed to get user tenants: %w", err)
- }
-
- agents, err := s.canvasDAO.GetAllCanvasesByTenantIDs(ctx, dao.DB, tenantIDs, user.ID)
- if err != nil {
- return nil, fmt.Errorf("failed to get user agents: %w", err)
- }
+ return nil, errors.New("listing user datasets is only available in the enterprise edition")
+}
- result := make([]map[string]interface{}, 0, len(agents))
- for _, agent := range agents {
- title := ""
- if agent.Title != nil {
- title = *agent.Title
- }
- result = append(result, map[string]interface{}{
- "title": title,
- "permission": agent.Permission,
- "canvas_category": strings.SplitN(agent.CanvasCategory, "_", 2)[0],
- "avatar": agent.Avatar,
- })
- }
- return result, nil
+// ListUserAgents requires the enterprise edition.
+func (s *Service) ListUserAgents(ctx context.Context, email, canvasCategory string, page, pageSize int) ([]map[string]interface{}, int64, error) {
+ return nil, 0, errors.New("listing user agents is only available in the enterprise edition")
}
// ListUserChats show user chats for enterprise edition
diff --git a/internal/admin/user_detail_ee_test.go b/internal/admin/user_detail_ee_test.go
new file mode 100644
index 0000000000..dd4ef869c8
--- /dev/null
+++ b/internal/admin/user_detail_ee_test.go
@@ -0,0 +1,76 @@
+//
+// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+package admin
+
+import (
+ "encoding/json"
+ "net/http"
+ "net/http/httptest"
+ "testing"
+
+ "ragflow/internal/common"
+
+ "github.com/gin-gonic/gin"
+)
+
+func TestUserAgentsRouteRequiresEE(t *testing.T) {
+ engine := gin.New()
+ RegisterEERouter(engine.Group("/api/v1/admin"), NewRouter(&Handler{}))
+
+ response := httptest.NewRecorder()
+ request := httptest.NewRequest(http.MethodGet, "/api/v1/admin/users/user%40example.com/agents", nil)
+ engine.ServeHTTP(response, request)
+ if response.Code != http.StatusNotImplemented {
+ t.Fatalf("HTTP status = %d, want %d; body = %s", response.Code, http.StatusNotImplemented, response.Body.String())
+ }
+
+ var result struct {
+ Code common.ErrorCode `json:"code"`
+ Data json.RawMessage `json:"data"`
+ Message string `json:"message"`
+ }
+ if err := json.Unmarshal(response.Body.Bytes(), &result); err != nil {
+ t.Fatal(err)
+ }
+ if result.Code != common.CodeNotImplemented || string(result.Data) != "null" || result.Message != "listing user agents is only available in the enterprise edition" {
+ t.Fatalf("response = %s, want enterprise edition error with null data", response.Body.String())
+ }
+}
+
+func TestUserDatasetsRouteRequiresEE(t *testing.T) {
+ engine := gin.New()
+ RegisterEERouter(engine.Group("/api/v1/admin"), NewRouter(&Handler{}))
+
+ response := httptest.NewRecorder()
+ request := httptest.NewRequest(http.MethodGet, "/api/v1/admin/users/user%40example.com/datasets", nil)
+ engine.ServeHTTP(response, request)
+ if response.Code != http.StatusNotImplemented {
+ t.Fatalf("HTTP status = %d, want %d; body = %s", response.Code, http.StatusNotImplemented, response.Body.String())
+ }
+
+ var result struct {
+ Code common.ErrorCode `json:"code"`
+ Data json.RawMessage `json:"data"`
+ Message string `json:"message"`
+ }
+ if err := json.Unmarshal(response.Body.Bytes(), &result); err != nil {
+ t.Fatal(err)
+ }
+ if result.Code != common.CodeNotImplemented || string(result.Data) != "null" || result.Message != "listing user datasets is only available in the enterprise edition" {
+ t.Fatalf("response = %s, want enterprise edition error with null data", response.Body.String())
+ }
+}
diff --git a/internal/admin/user_detail_test.go b/internal/admin/user_detail_test.go
index 4e58457811..059e6933ef 100644
--- a/internal/admin/user_detail_test.go
+++ b/internal/admin/user_detail_test.go
@@ -39,9 +39,6 @@ func setupAdminUserDetailTest(t *testing.T) *Handler {
t.Helper()
db := testutil.SetupTestDB(t,
&entity.User{},
- &entity.UserTenant{},
- &entity.Knowledgebase{},
- &entity.UserCanvas{},
)
t.Cleanup(testutil.ReplaceDBForTest(t, db))
@@ -67,44 +64,6 @@ func setupAdminUserDetailTest(t *testing.T) *Handler {
t.Fatalf("create user: %v", err)
}
- membership := entity.UserTenant{
- ID: "membership-1",
- UserID: user.ID,
- TenantID: "tenant-2",
- Role: "normal",
- InvitedBy: "tenant-2",
- Status: &statusValid,
- }
- if err := db.Create(&membership).Error; err != nil {
- t.Fatalf("create membership: %v", err)
- }
- ownerMemberships := []entity.UserTenant{
- {ID: "membership-owner-user", UserID: user.ID, TenantID: user.ID, Role: "owner", InvitedBy: user.ID, Status: &statusValid},
- {ID: "membership-owner-tenant-2", UserID: "tenant-2", TenantID: "tenant-2", Role: "owner", InvitedBy: "tenant-2", Status: &statusValid},
- }
- if err := db.Create(&ownerMemberships).Error; err != nil {
- t.Fatalf("create owner memberships: %v", err)
- }
-
- datasets := []entity.Knowledgebase{
- {ID: "dataset-own", TenantID: user.ID, Name: "Own dataset", EmbdID: "embedding", Permission: "me", CreatedBy: user.ID, Status: &statusValid},
- {ID: "dataset-team", TenantID: "tenant-2", Name: "Team dataset", EmbdID: "embedding", Permission: "team", CreatedBy: "tenant-2", Status: &statusValid},
- {ID: "dataset-private", TenantID: "tenant-2", Name: "Private dataset", EmbdID: "embedding", Permission: "me", CreatedBy: "tenant-2", Status: &statusValid},
- {ID: "dataset-invalid", TenantID: user.ID, Name: "Invalid dataset", EmbdID: "embedding", Permission: "me", CreatedBy: user.ID, Status: testutil.StrPtr(string(entity.StatusInvalid))},
- }
- if err := db.Create(&datasets).Error; err != nil {
- t.Fatalf("create datasets: %v", err)
- }
-
- agents := []entity.UserCanvas{
- {ID: "agent-own", UserID: user.ID, Title: testutil.StrPtr("Own agent"), Permission: "me", CanvasCategory: "agent_canvas"},
- {ID: "agent-team", UserID: "tenant-2", Title: testutil.StrPtr("Team agent"), Permission: "team", CanvasCategory: "agent_canvas"},
- {ID: "agent-private", UserID: "tenant-2", Title: testutil.StrPtr("Private agent"), Permission: "me", CanvasCategory: "agent_canvas"},
- }
- if err := db.Create(&agents).Error; err != nil {
- t.Fatalf("create agents: %v", err)
- }
-
return NewHandler(NewService())
}
@@ -126,7 +85,7 @@ func callAdminUserHandler(t *testing.T, handler func(*gin.Context)) adminTestRes
return response
}
-func TestGetUserReturnsPythonCompatibleDetailList(t *testing.T) {
+func TestGetUserReturnsDetailList(t *testing.T) {
gin.SetMode(gin.TestMode)
handler := setupAdminUserDetailTest(t)
response := callAdminUserHandler(t, handler.GetUser)
@@ -147,71 +106,3 @@ func TestGetUserReturnsPythonCompatibleDetailList(t *testing.T) {
t.Fatalf("unexpected user details: %+v", details[0])
}
}
-
-func TestListUserDatasetsReturnsAccessibleDatasets(t *testing.T) {
- gin.SetMode(gin.TestMode)
- handler := setupAdminUserDetailTest(t)
- response := callAdminUserHandler(t, handler.ListUserDatasets)
-
- var datasets []struct {
- Name string `json:"name"`
- Permission string `json:"permission"`
- Status string `json:"status"`
- }
- if err := json.Unmarshal(response.Data, &datasets); err != nil {
- t.Fatalf("decode datasets: %v", err)
- }
- if len(datasets) != 2 {
- t.Fatalf("datasets length = %d, want 2: %+v", len(datasets), datasets)
- }
- datasetsByName := make(map[string]struct {
- Permission string
- Status string
- }, len(datasets))
- for _, dataset := range datasets {
- datasetsByName[dataset.Name] = struct {
- Permission string
- Status string
- }{Permission: dataset.Permission, Status: dataset.Status}
- }
- if dataset := datasetsByName["Own dataset"]; dataset.Permission != "me" || dataset.Status != "1" {
- t.Fatalf("unexpected own dataset: %+v", dataset)
- }
- if dataset := datasetsByName["Team dataset"]; dataset.Permission != "team" || dataset.Status != "1" {
- t.Fatalf("unexpected team dataset: %+v", dataset)
- }
-}
-
-func TestListUserAgentsReturnsAccessibleAgents(t *testing.T) {
- gin.SetMode(gin.TestMode)
- handler := setupAdminUserDetailTest(t)
- response := callAdminUserHandler(t, handler.ListUserAgents)
-
- var agents []struct {
- Title string `json:"title"`
- Permission string `json:"permission"`
- CanvasCategory string `json:"canvas_category"`
- }
- if err := json.Unmarshal(response.Data, &agents); err != nil {
- t.Fatalf("decode agents: %v", err)
- }
- if len(agents) != 2 {
- t.Fatalf("agents length = %d, want 2: %+v", len(agents), agents)
- }
- agentsByTitle := make(map[string]struct {
- Permission string
- CanvasCategory string
- }, len(agents))
- for _, agent := range agents {
- agentsByTitle[agent.Title] = struct {
- Permission string
- CanvasCategory string
- }{Permission: agent.Permission, CanvasCategory: agent.CanvasCategory}
- }
- if agent := agentsByTitle["Own agent"]; agent.Permission != "me" || agent.CanvasCategory != "agent" {
- t.Fatalf("unexpected own agent: %+v", agent)
- }
- if agent := agentsByTitle["Team agent"]; agent.Permission != "team" || agent.CanvasCategory != "agent" {
- t.Fatalf("unexpected team agent: %+v", agent)
- }
-}
diff --git a/internal/cli/admin_command.go b/internal/cli/admin_command.go
index aaa4beb350..8919a6fbff 100644
--- a/internal/cli/admin_command.go
+++ b/internal/cli/admin_command.go
@@ -1019,53 +1019,6 @@ func (c *CLI) AdminDropUserAPIKeyCommand(commandCount int, cmd *Command) (Respon
return HandleCommonDataResponse(resp, "drop API key")
}
-// ListUserDatasets lists datasets for a specific user (admin mode)
-// Returns (result_map, error) - result_map is non-nil for benchmark mode
-func (c *CLI) ListUserDatasets(commandCount int, cmd *Command) (ResponseIf, error) {
- if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
- return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
- }
-
- userName, ok := cmd.Params["user_name"].(string)
- if !ok {
- return nil, fmt.Errorf("user_name not provided")
- }
-
- encodedUserName := url.PathEscape(userName)
- apiURL := fmt.Sprintf("/admin/users/%s/datasets", encodedUserName)
-
- resp, err := c.AdminServerClient.Request(commandCount, "GET", apiURL, "admin", nil, nil)
- if err != nil {
- return nil, fmt.Errorf("failed to list datasets: %w", err)
- }
-
- if resp.StatusCode != 200 {
- return nil, fmt.Errorf("failed to list datasets: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
- }
-
- resJSON, err := resp.JSON()
- if err != nil {
- return nil, fmt.Errorf("invalid JSON response: %w", err)
- }
-
- data, ok := resJSON["data"].([]interface{})
- if !ok {
- return nil, fmt.Errorf("invalid response format")
- }
-
- // Convert to slice of maps and remove avatar
- tableData := make([]map[string]interface{}, 0, len(data))
- for _, item := range data {
- if itemMap, ok := item.(map[string]interface{}); ok {
- delete(itemMap, "avatar")
- tableData = append(tableData, itemMap)
- }
- }
-
- PrintTableSimple(tableData)
- return nil, nil
-}
-
// ShowUserPermission shows user's permissions (admin mode only)
func (c *CLI) ShowUserPermission(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
@@ -2286,48 +2239,6 @@ func (c *CLI) AdminListUserIngestionTasksCommand(commandCount int, cmd *Command)
return &result, nil
}
-func (c *CLI) AdminListUserDatasetsCommand(commandCount int, cmd *Command) (ResponseIf, error) {
-
- if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
- return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
- }
-
- userName, ok := cmd.Params["user_name"].(string)
- if !ok {
- return nil, fmt.Errorf("user_name not provided")
- }
-
- encodedUserName := url.PathEscape(userName)
- apiURL := fmt.Sprintf("/admin/users/%s/datasets", encodedUserName)
-
- resp, err := c.AdminServerClient.Request(commandCount, "GET", apiURL, "admin", nil, nil)
- if err != nil {
- return nil, fmt.Errorf("failed to list user %s datasets: %w", userName, err)
- }
-
- return HandleCommonResponse(resp, fmt.Sprintf("list user %s datasets", userName))
-}
-func (c *CLI) AdminListUserAgentsCommand(commandCount int, cmd *Command) (ResponseIf, error) {
-
- if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
- return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
- }
-
- userName, ok := cmd.Params["user_name"].(string)
- if !ok {
- return nil, fmt.Errorf("user_name not provided")
- }
-
- encodedUserName := url.PathEscape(userName)
- apiURL := fmt.Sprintf("/admin/users/%s/agents", encodedUserName)
-
- resp, err := c.AdminServerClient.Request(commandCount, "GET", apiURL, "admin", nil, nil)
- if err != nil {
- return nil, fmt.Errorf("failed to list user %s agents: %w", userName, err)
- }
-
- return HandleCommonResponse(resp, fmt.Sprintf("list user %s agents", userName))
-}
func (c *CLI) AdminListUserChatsCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
diff --git a/internal/cli/admin_command_ee.go b/internal/cli/admin_command_ee.go
new file mode 100644
index 0000000000..7fba1a0e76
--- /dev/null
+++ b/internal/cli/admin_command_ee.go
@@ -0,0 +1,37 @@
+//
+// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+package cli
+
+import "errors"
+
+// AdminListUserAgentsCommand is available only in the enterprise edition.
+func (c *CLI) AdminListUserAgentsCommand(commandCount int, cmd *Command) (ResponseIf, error) {
+ return nil, errors.New("listing user agents is only available in the enterprise edition")
+}
+
+func (p *Parser) parseAdminListUserAgentsEE(userName string) (*Command, error) {
+ return nil, errors.New("listing user agents is only available in the enterprise edition")
+}
+
+// AdminListUserDatasetsCommand is available only in the enterprise edition.
+func (c *CLI) AdminListUserDatasetsCommand(commandCount int, cmd *Command) (ResponseIf, error) {
+ return nil, errors.New("listing user datasets is only available in the enterprise edition")
+}
+
+func (p *Parser) parseAdminListUserDatasetsEE(userName string) (*Command, error) {
+ return nil, errors.New("listing user datasets is only available in the enterprise edition")
+}
diff --git a/internal/cli/admin_command_ee_test.go b/internal/cli/admin_command_ee_test.go
new file mode 100644
index 0000000000..4e1d910bdb
--- /dev/null
+++ b/internal/cli/admin_command_ee_test.go
@@ -0,0 +1,74 @@
+//
+// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+package cli
+
+import (
+ "strings"
+ "testing"
+)
+
+func TestParseAdminListUserAgentsRequiresEE(t *testing.T) {
+ cmd, err := NewParser("LIST USER '[email protected]' AGENTS;").Parse(AdminMode)
+ if cmd != nil || err == nil || !strings.Contains(err.Error(), "enterprise edition") {
+ t.Fatalf("Parse() = (%v, %v), want nil command and enterprise edition error", cmd, err)
+ }
+}
+
+func TestAdminListUserAgentsRequiresEE(t *testing.T) {
+ cmd := NewCommand("admin_list_user_agents")
+ cmd.Params["user_name"] = "[email protected]"
+ response, err := (&CLI{}).AdminListUserAgentsCommand(1, cmd)
+ if response != nil || err == nil || !strings.Contains(err.Error(), "enterprise edition") {
+ t.Fatalf("AdminListUserAgentsCommand() = (%v, %v), want nil response and enterprise edition error", response, err)
+ }
+}
+
+func TestParseAPIListAgents(t *testing.T) {
+ cmd, err := NewParser("LIST AGENTS;").Parse(APIMode)
+ if err != nil {
+ t.Fatalf("Parse() error = %v", err)
+ }
+ if cmd == nil || cmd.Type != "api_list_agents" {
+ t.Fatalf("Parse() command = %v, want api_list_agents", cmd)
+ }
+}
+
+func TestParseAdminListUserDatasetsRequiresEE(t *testing.T) {
+ cmd, err := NewParser("LIST USER '[email protected]' DATASETS;").Parse(AdminMode)
+ if cmd != nil || err == nil || !strings.Contains(err.Error(), "enterprise edition") {
+ t.Fatalf("Parse() = (%v, %v), want nil command and enterprise edition error", cmd, err)
+ }
+}
+
+func TestAdminListUserDatasetsRequiresEE(t *testing.T) {
+ cmd := NewCommand("admin_list_user_datasets")
+ cmd.Params["user_name"] = "[email protected]"
+ response, err := (&CLI{}).AdminListUserDatasetsCommand(1, cmd)
+ if response != nil || err == nil || !strings.Contains(err.Error(), "enterprise edition") {
+ t.Fatalf("AdminListUserDatasetsCommand() = (%v, %v), want nil response and enterprise edition error", response, err)
+ }
+}
+
+func TestParseAPIListDatasets(t *testing.T) {
+ cmd, err := NewParser("LIST DATASETS;").Parse(APIMode)
+ if err != nil {
+ t.Fatalf("Parse() error = %v", err)
+ }
+ if cmd == nil || cmd.Type != "api_list_datasets" {
+ t.Fatalf("Parse() command = %v, want api_list_datasets", cmd)
+ }
+}
diff --git a/internal/cli/admin_parser.go b/internal/cli/admin_parser.go
index 79055cfe46..2b79a71422 100644
--- a/internal/cli/admin_parser.go
+++ b/internal/cli/admin_parser.go
@@ -3239,8 +3239,6 @@ commandLoop:
}
// LIST USER '[email protected]' INGESTION TASKS;
-// LIST USER '[email protected]' DATASETS;
-// LIST USER '[email protected]' AGENTS;
// LIST USER '[email protected]' CHATS;
// LIST USER '[email protected]' SEARCHES;
// LIST USER '[email protected]' MODELS; // all added models
@@ -3262,11 +3260,9 @@ func (p *Parser) parseAdminListUserCommand() (*Command, error) {
case TokenIngestion:
return p.parseAdminListUserIngestionTasks(userName)
case TokenDatasets:
- p.nextToken()
- cmd = NewCommand("admin_list_user_datasets")
+ return p.parseAdminListUserDatasetsEE(userName)
case TokenAgents:
- p.nextToken()
- cmd = NewCommand("admin_list_user_agents")
+ return p.parseAdminListUserAgentsEE(userName)
case TokenChats:
p.nextToken()
cmd = NewCommand("admin_list_user_chats")
diff --git a/internal/cli/benchmark.go b/internal/cli/benchmark.go
index 38e5df7367..253d31285f 100644
--- a/internal/cli/benchmark.go
+++ b/internal/cli/benchmark.go
@@ -18,7 +18,6 @@ package cli
import (
"fmt"
- "ragflow/internal/cli/utils"
"strings"
"sync"
"time"
@@ -165,17 +164,6 @@ func (c *CLI) runBenchmarkConcurrent(concurrency, iterations int, nestedCmd *Com
go func(idx int) {
defer wg.Done()
- //// Create a new client for each goroutine to avoid race conditions
- //workerClient, err := NewCLIWithConfig(Arguments)
- //if err != nil {
- // fmt.Printf("fail to create worker client: %s", err)
- // return
- //}
- //workerClient.AdminServerClient = c.AdminServerClient
- //workerClient.APIServerClientMap = c.APIServerClientMap
-
- // Execute benchmark silently (no output)
- //responseList := workerClient.executeBenchmarkSilent(nestedCmd, iterations)
benchmarkResponse, _ := c.runBenchmarkSingle(iterations, nestedCmd)
results[idx] = map[string]interface{}{
@@ -212,81 +200,3 @@ func (c *CLI) runBenchmarkConcurrent(concurrency, iterations int, nestedCmd *Com
return &benchmarkResponse, nil
}
-
-// executeBenchmarkSilent executes a command for benchmark without printing output
-func (c *CLI) executeBenchmarkSilent(cmd *Command, iterations int) []*Response {
- responseList := make([]*Response, 0, iterations)
-
- httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
-
- for i := 0; i < iterations; i++ {
- var resp *Response
- var err error
-
- switch cmd.Type {
- case "ping":
- resp, err = httpClient.Request(1, "GET", "/system/ping", "web", nil, nil)
- case "list_user_datasets":
- resp, err = httpClient.Request(1, "POST", "/kb/list", "web", nil, nil)
- case "api_list_datasets":
- userName, _ := cmd.Params["user_name"].(string)
- resp, err = httpClient.Request(1, "GET", utils.APIPath("/admin/users", userName, "datasets"), "admin", nil, nil)
- case "search_on_datasets":
- question, _ := cmd.Params["question"].(string)
- datasetIDs, _ := cmd.Params["dataset_ids"].([]string)
- payload := map[string]interface{}{
- "dataset_ids": datasetIDs,
- "question": question,
- "similarity_threshold": 0.2,
- "vector_similarity_weight": 0.3,
- }
- resp, err = httpClient.Request(1, "POST", "/datasets/search", "web", nil, payload)
- default:
- // For other commands, we would need to add specific handling
- // For now, mark as failed
- resp = &Response{StatusCode: 0}
- }
-
- if err != nil {
- resp = &Response{StatusCode: 0}
- }
-
- responseList = append(responseList, resp)
- }
-
- return responseList
-}
-
-// isSuccess checks if a response is successful based on command type
-func isSuccess(resp *Response, commandType string) bool {
- if resp == nil {
- return false
- }
-
- switch commandType {
- case "ping":
- return resp.StatusCode == 200 && string(resp.Body) == "pong"
- case "list_user_datasets", "api_list_datasets", "search_on_datasets":
- // Check status code and JSON response code for dataset commands
- if resp.StatusCode != 200 {
- return false
- }
- resJSON, err := resp.JSON()
- if err != nil {
- return false
- }
- code, ok := resJSON["code"].(float64)
- return ok && code == 0
- default:
- // For other commands, check status code and response code
- if resp.StatusCode != 200 {
- return false
- }
- resJSON, err := resp.JSON()
- if err != nil {
- return false
- }
- code, ok := resJSON["code"].(float64)
- return ok && code == 0
- }
-}
diff --git a/internal/cli/cli_http.go b/internal/cli/cli_http.go
index 91deb0f7a9..53a9b052d0 100644
--- a/internal/cli/cli_http.go
+++ b/internal/cli/cli_http.go
@@ -123,8 +123,6 @@ func (c *CLI) ExecuteAdminCommand(commandCount int, cmd *Command) (ResponseIf, e
return c.AdminSetLogLevelCommand(commandCount, cmd)
case "admin_reset_role_default_model":
return c.AdminResetRoleDefaultModelsCommand(commandCount, cmd)
- case "list_user_datasets":
- return c.ListUserDatasets(commandCount, cmd)
case "admin_list_resources_command":
return c.AdminListResourcesCommand(commandCount, cmd)
case "admin_list_roles_command":
diff --git a/internal/dao/user_canvas.go b/internal/dao/user_canvas.go
index 6c0ec44f10..61cdfe2d49 100644
--- a/internal/dao/user_canvas.go
+++ b/internal/dao/user_canvas.go
@@ -180,21 +180,6 @@ func (dao *UserCanvasDAO) GetList(ctx context.Context, db *gorm.DB, tenantID str
return canvases, err
}
-// GetAllCanvasesByTenantIDs get all permitted canvases by tenant IDs
-// Similar to Python UserCanvasService.get_all_agents_by_tenant_ids
-func (dao *UserCanvasDAO) GetAllCanvasesByTenantIDs(ctx context.Context, db *gorm.DB, tenantIDs []string, userID string) ([]*CanvasBasicInfo, error) {
-
- query := db.WithContext(ctx).Model(&entity.UserCanvas{}).
- Select("id, avatar, title, permission, canvas_type, canvas_category").
- Where("user_id IN (?) AND permission = ?", tenantIDs, "team").
- Or("user_id = ?", userID).
- Order("create_time ASC")
-
- var results []*CanvasBasicInfo
- err := query.Scan(&results).Error
- return results, err
-}
-
// UserCanvasListItem is the joined row returned by ListByIDs.
type UserCanvasListItem struct {
ID string `gorm:"column:id"`
@@ -357,16 +342,6 @@ func (dao *UserCanvasDAO) GetByCanvasID(ctx context.Context, db *gorm.DB, canvas
return dao.GetByID(ctx, db, canvasID)
}
-// CanvasBasicInfo basic canvas information for list responses
-type CanvasBasicInfo struct {
- ID string `gorm:"column:id" json:"id"`
- Avatar *string `gorm:"column:avatar" json:"avatar,omitempty"`
- Title *string `gorm:"column:title" json:"title,omitempty"`
- Permission string `gorm:"column:permission" json:"permission"`
- CanvasType *string `gorm:"column:canvas_type" json:"canvas_type,omitempty"`
- CanvasCategory string `gorm:"column:canvas_category" json:"canvas_category"`
-}
-
// DeleteByUserID deletes all canvases by user ID (hard delete)
func (dao *UserCanvasDAO) DeleteByUserID(ctx context.Context, db *gorm.DB, userID string) (int64, error) {
result := db.WithContext(ctx).Unscoped().Where("user_id = ?", userID).Delete(&entity.UserCanvas{})