Skip to content

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

Fix: move to stub (#21678)

Lynn4b7add5f8efc
diff --git a/internal/handler/error.go b/internal/handler/error.go
index db364940f4..3e0dfb34b2 100644
--- a/internal/handler/error.go
+++ b/internal/handler/error.go
@@ -41,13 +41,11 @@ func jsonInternalError(c *gin.Context, err error) {
// HandleNoRoute handles requests to undefined routes
func HandleNoRoute(c *gin.Context) {
- // Python parity: GET /api/v1/auth/login/ (an empty OAuth channel) resolves
- // to a Werkzeug MethodNotAllowed in the Python API, which
- // server_error_response renders as HTTP 200 / code 100 with the
- // exception's repr() as the message. gin instead falls through to
- // NoRoute, so emit the same body here to keep the auth error paths
- // byte-for-byte aligned.
- if (c.Request.Method == http.MethodGet && c.Request.URL.Path == "/api/v1/auth/login/") ||
+ // Python parity: requests that resolve to a Werkzeug MethodNotAllowed in
+ // the Python API render as HTTP 200 / code 100 with the exception's repr()
+ // as the message. gin instead falls through to NoRoute, so emit the same
+ // body here to keep the error paths byte-for-byte aligned.
+ if isOAuthLoginNoRoute(c) ||
(c.Request.Method == http.MethodPost && c.Request.URL.Path == "/api/v1/chats//sessions") ||
(c.Request.Method == http.MethodPatch && strings.HasSuffix(c.Request.URL.Path, "/sessions/")) {
common.ResponseWithCodeData(c, common.CodeExceptionError, false, "<MethodNotAllowed '405: Method Not Allowed'>")
diff --git a/internal/handler/error_stub_test.go b/internal/handler/error_stub_test.go
new file mode 100644
index 0000000000..fa8dd325dd
--- /dev/null
+++ b/internal/handler/error_stub_test.go
@@ -0,0 +1,38 @@
+//go:build !ee
+
+package handler
+
+import (
+ "encoding/json"
+ "net/http"
+ "net/http/httptest"
+ "testing"
+
+ "ragflow/internal/common"
+
+ "github.com/gin-gonic/gin"
+)
+
+// TestHandleNoRouteMatchesPythonEmptyOAuthChannel pins the community edition:
+// with no OAuth routes, GET /api/v1/auth/login/ reaches NoRoute and has to
+// reproduce the Python MethodNotAllowed body. The enterprise build supplies
+// its own isOAuthLoginNoRoute, so this assertion is community-only.
+func TestHandleNoRouteMatchesPythonEmptyOAuthChannel(t *testing.T) {
+ gin.SetMode(gin.TestMode)
+ recorder := httptest.NewRecorder()
+ context, _ := gin.CreateTestContext(recorder)
+ context.Request = httptest.NewRequest(http.MethodGet, "/api/v1/auth/login/", nil)
+
+ HandleNoRoute(context)
+
+ if recorder.Code != http.StatusOK {
+ t.Fatalf("status=%d, want %d", recorder.Code, http.StatusOK)
+ }
+ var body map[string]interface{}
+ if err := json.Unmarshal(recorder.Body.Bytes(), &body); err != nil {
+ t.Fatalf("decode response: %v", err)
+ }
+ if body["code"] != float64(common.CodeExceptionError) || body["message"] != "<MethodNotAllowed '405: Method Not Allowed'>" {
+ t.Fatalf("body=%v", body)
+ }
+}
diff --git a/internal/handler/stub.go b/internal/handler/stub.go
index 3f711bc7ae..feb9aed24d 100644
--- a/internal/handler/stub.go
+++ b/internal/handler/stub.go
@@ -20,6 +20,7 @@ package handler
import (
"errors"
+ "net/http"
"ragflow/internal/common"
"ragflow/internal/entity"
@@ -45,6 +46,13 @@ func billingEnforceApps(_ *gin.Context, _ string) bool { return true }
// storage quota.
func billingEnforceStorage(_ *gin.Context, _ string, _ int64) bool { return true }
+// isOAuthLoginNoRoute reports the OAuth login URL with an empty channel: the
+// Python API resolves it to a Werkzeug MethodNotAllowed, and the community
+// edition has no OAuth routes, so HandleNoRoute has to reproduce that body.
+func isOAuthLoginNoRoute(c *gin.Context) bool {
+ return c.Request.Method == http.MethodGet && c.Request.URL.Path == "/api/v1/auth/login/"
+}
+
// issueUserAccessToken mints the access token returned after a successful
// login.
func issueUserAccessToken(user *entity.User, secretKey string) (string, error) {
@@ -70,8 +78,25 @@ func (h *SystemHandler) GetConcurrency(c *gin.Context) { eeNotImplemented(c, "Ge
func (h *SystemHandler) SetConcurrency(c *gin.Context) { eeNotImplemented(c, "Set concurrency") }
func (h *SystemHandler) GetQuota(c *gin.Context) { eeNotImplemented(c, "Get quota") }
-func (h *UserHandler) IsAdmin(c *gin.Context) { eeNotImplemented(c, "IsAdmin") }
-func (h *UserHandler) GetMeta(c *gin.Context) { eeNotImplemented(c, "GetMeta") }
+func (h *UserHandler) IsAdmin(c *gin.Context) { eeNotImplemented(c, "IsAdmin") }
+func (h *UserHandler) GetMeta(c *gin.Context) { eeNotImplemented(c, "GetMeta") }
+
+// GetLoginChannelsDeprecated lists the OAuth authentication channels. The
+// community edition offers password login only, so the list is empty.
+// @Summary Get Login Channels
+// @Description Get all supported OAuth authentication channels
+// @Tags users
+// @Success 200 {object} map[string]interface{}
+// @Router /v1/user/login/channels [get]
+func (h *UserHandler) GetLoginChannelsDeprecated(c *gin.Context) {
+ channels, code, err := h.userService.GetLoginChannels()
+ if err != nil {
+ common.ResponseWithCodeData(c, code, []interface{}{}, "Load channels failure, error: "+err.Error())
+ return
+ }
+
+ common.SuccessWithData(c, channels, "success")
+}
func (h *ProviderHandler) CreateModelGroup(c *gin.Context) { eeNotImplemented(c, "CreateModelGroup") }
func (h *ProviderHandler) DeleteModelGroup(c *gin.Context) { eeNotImplemented(c, "DeleteModelGroup") }
func (h *ProviderHandler) ShowModelGroup(c *gin.Context) { eeNotImplemented(c, "ShowModelGroup") }
diff --git a/internal/handler/user.go b/internal/handler/user.go
index 21de728bc0..e9f1436d65 100644
--- a/internal/handler/user.go
+++ b/internal/handler/user.go
@@ -480,22 +480,6 @@ func (h *UserHandler) ChangePassword(c *gin.Context) {
common.SuccessWithData(c, true, "password changed successfully")
}
-// GetLoginChannels get all supported authentication channels
-// @Summary Get Login Channels
-// @Description Get all supported OAuth authentication channels
-// @Tags users
-// @Success 200 {object} map[string]interface{}
-// @Router /v1/user/login/channels [get]
-func (h *UserHandler) GetLoginChannelsDeprecated(c *gin.Context) {
- channels, code, err := h.userService.GetLoginChannels()
- if err != nil {
- common.ResponseWithCodeData(c, code, []interface{}{}, "Load channels failure, error: "+err.Error())
- return
- }
-
- common.SuccessWithData(c, channels, "success")
-}
-
// SetTenantInfo update tenant information
// @Summary Set Tenant Info
// @Description Update tenant model configuration