refactor(terminology): rename user-facing tenant labels to workspace
Align product copy, API docs, Swagger descriptions, and i18n strings with workspace terminology while keeping internal tenant identifiers and headers unchanged for API compatibility.
This commit is contained in:
@@ -35,11 +35,11 @@ type auditLogListResponse struct {
|
||||
}
|
||||
|
||||
// ListTenantAuditLog godoc
|
||||
// @Summary 获取租户审计日志
|
||||
// @Description 返回该租户最近的审计事件,按 id 倒序。游标分页:将上次响应的 next_cursor 作为下一次请求的 after_id。
|
||||
// @Summary 获取空间审计日志
|
||||
// @Description 返回该空间最近的审计事件,按 id 倒序。游标分页:将上次响应的 next_cursor 作为下一次请求的 after_id。
|
||||
// @Tags 审计日志
|
||||
// @Produce json
|
||||
// @Param id path string true "租户ID"
|
||||
// @Param id path string true "空间ID"
|
||||
// @Param after_id query int false "游标:返回 id 小于此值的记录(默认从最新开始)"
|
||||
// @Param limit query int false "页大小,1-100,默认 50"
|
||||
// @Param action query string false "按 action 精确过滤(如 rbac.member_added / rbac.access_denied)"
|
||||
|
||||
@@ -586,7 +586,7 @@ type updateMyPreferencesRequest struct {
|
||||
EnableMemory *bool `json:"enable_memory"`
|
||||
// LastActiveTenantID lets the SPA persist "after a fresh login,
|
||||
// drop me back into this workspace" across devices. Send a positive
|
||||
// tenant id to set / replace, or 0 to clear. Membership is validated
|
||||
// workspace id to set / replace, or 0 to clear. Membership is validated
|
||||
// at next login, not here. Nil = field omitted from the PATCH and
|
||||
// stays untouched.
|
||||
LastActiveTenantID *uint64 `json:"last_active_tenant_id"`
|
||||
@@ -717,15 +717,15 @@ func (h *AuthHandler) GetAuthConfig(c *gin.Context) {
|
||||
}
|
||||
|
||||
// SwitchTenant godoc
|
||||
// @Summary 切换激活租户
|
||||
// @Description 为当前用户在目标租户重新签发访问令牌;要求该用户在目标租户存在 active 成员关系
|
||||
// @Summary 切换激活空间
|
||||
// @Description 为当前用户在目标空间重新签发访问令牌;要求该用户在目标空间存在 active 成员关系
|
||||
// @Tags 认证
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param request body object{tenant_id=integer,refresh_token=string} true "切换请求"
|
||||
// @Success 200 {object} types.LoginResponse
|
||||
// @Failure 400 {object} errors.AppError "参数错误"
|
||||
// @Failure 403 {object} errors.AppError "无该租户成员关系"
|
||||
// @Failure 403 {object} errors.AppError "无该空间成员关系"
|
||||
// @Security Bearer
|
||||
// @Router /auth/switch-tenant [post]
|
||||
//
|
||||
@@ -740,7 +740,7 @@ func (h *AuthHandler) SwitchTenant(c *gin.Context) {
|
||||
RefreshToken string `json:"refresh_token"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
appErr := errors.NewValidationError("Invalid switch-tenant request").WithDetails(err.Error())
|
||||
appErr := errors.NewValidationError("Invalid workspace switch request").WithDetails(err.Error())
|
||||
c.Error(appErr)
|
||||
return
|
||||
}
|
||||
@@ -755,7 +755,7 @@ func (h *AuthHandler) SwitchTenant(c *gin.Context) {
|
||||
resp, err := h.userService.SwitchTenant(ctx, user, req.TenantID, req.RefreshToken)
|
||||
if err != nil {
|
||||
logger.Errorf(ctx, "SwitchTenant failed user=%s target=%d: %v", user.ID, req.TenantID, err)
|
||||
appErr := errors.NewForbiddenError("switch tenant failed").WithDetails(err.Error())
|
||||
appErr := errors.NewForbiddenError("workspace switch failed").WithDetails(err.Error())
|
||||
c.Error(appErr)
|
||||
return
|
||||
}
|
||||
@@ -764,7 +764,7 @@ func (h *AuthHandler) SwitchTenant(c *gin.Context) {
|
||||
}
|
||||
|
||||
// @Summary 自动初始化(Lite 桌面版)
|
||||
// @Description Lite 版专用:首次启动时自动创建默认用户和租户并返回令牌,后续启动直接签发令牌,免除手动注册/登录流程
|
||||
// @Description Lite 版专用:首次启动时自动创建默认用户和空间并返回令牌,后续启动直接签发令牌,免除手动注册/登录流程
|
||||
// @Tags 认证
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
|
||||
@@ -49,7 +49,7 @@ type invitationLookupRequest struct {
|
||||
|
||||
// LookupInvitationByToken godoc
|
||||
// @Summary 解析共享邀请链接 token
|
||||
// @Description 根据邀请链接中的 token 返回邀请上下文(租户名 / 角色 / 过期时间),
|
||||
// @Description 根据邀请链接中的 token 返回邀请上下文(空间名 / 角色 / 过期时间),
|
||||
// @Description 供注册页展示。无认证;token 无效或被撤销返回 410。
|
||||
// @Description 使用 POST + body 而非 GET + path,避免 token 落入访问日志 / 浏览器历史 / tracing。
|
||||
// @Tags 认证
|
||||
@@ -107,7 +107,7 @@ func (h *AuthHandler) LookupInvitationByToken(c *gin.Context) {
|
||||
// RegisterByInvite godoc
|
||||
// @Summary 使用共享链接注册
|
||||
// @Description 通过 Owner 生成的共享邀请链接 token 完成注册,绕过 invite_only 模式拦截。
|
||||
// @Description 注册者自填邮箱(与 token 不绑定);注册成功后自动加入对应租户。
|
||||
// @Description 注册者自填邮箱(与 token 不绑定);注册成功后自动加入对应空间。
|
||||
// @Tags 认证
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
|
||||
@@ -171,7 +171,7 @@ func (h *CustomAgentHandler) GetAgent(c *gin.Context) {
|
||||
|
||||
// ListAgents godoc
|
||||
// @Summary 获取智能体列表
|
||||
// @Description 获取当前租户的所有智能体(包括内置智能体)
|
||||
// @Description 获取当前空间的所有智能体(包括内置智能体)
|
||||
// @Tags 智能体
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
@@ -222,14 +222,14 @@ func (h *CustomAgentHandler) ListAgents(c *gin.Context) {
|
||||
// Per-tenant "disabled by me" for own agents (only affects this tenant's conversation dropdown)
|
||||
tenantIDVal, exists := c.Get(types.TenantIDContextKey.String())
|
||||
if !exists {
|
||||
logger.Error(ctx, "Tenant ID not found in context")
|
||||
c.Error(errors.NewUnauthorizedError("Missing tenant context"))
|
||||
logger.Error(ctx, "Workspace ID not found in context")
|
||||
c.Error(errors.NewUnauthorizedError("Missing workspace context"))
|
||||
return
|
||||
}
|
||||
tenantID, ok := tenantIDVal.(uint64)
|
||||
if !ok {
|
||||
logger.Errorf(ctx, "Tenant ID has unexpected type %T in context", tenantIDVal)
|
||||
c.Error(errors.NewInternalServerError("Invalid tenant context type"))
|
||||
c.Error(errors.NewInternalServerError("Invalid workspace context type"))
|
||||
return
|
||||
}
|
||||
disabledOwnIDs, err := h.disabledRepo.ListDisabledOwnAgentIDs(ctx, tenantID)
|
||||
@@ -241,7 +241,7 @@ func (h *CustomAgentHandler) ListAgents(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// 批量回填 creator_name,作用同 KB 列表:让前端能区分「我创建」与「同租户其他成员」。
|
||||
// 批量回填 creator_name,作用同 KB 列表:让前端能区分「我创建」与「同空间其他成员」。
|
||||
// 内建 agent(IsBuiltin=true, CreatedBy="")不会有 creator_name,前端按 builtin
|
||||
// 分支单独渲染。
|
||||
enrichAgentCreatorNames(ctx, h.userService, agents)
|
||||
|
||||
@@ -94,7 +94,7 @@ func (h *DataSourceHandler) CreateDataSource(c *gin.Context) {
|
||||
// Extract tenant ID from context (set by auth middleware)
|
||||
tenantID := c.GetUint64(types.TenantIDContextKey.String())
|
||||
if tenantID == 0 {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthorized: tenant context missing"})
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthorized: workspace context missing"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ func (h *DataSourceHandler) ListDataSources(c *gin.Context) {
|
||||
// Extract tenant ID from context
|
||||
tenantID := c.GetUint64(types.TenantIDContextKey.String())
|
||||
if tenantID == 0 {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthorized: tenant context missing"})
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthorized: workspace context missing"})
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ func (h *DataSourceCredentialsHandler) ownDataSource(c *gin.Context) (*types.Dat
|
||||
ctx := c.Request.Context()
|
||||
tenantID := c.GetUint64(types.TenantIDContextKey.String())
|
||||
if tenantID == 0 {
|
||||
c.Error(errors.NewBadRequestError("Tenant ID cannot be empty"))
|
||||
c.Error(errors.NewBadRequestError("Workspace ID cannot be empty"))
|
||||
return nil, false
|
||||
}
|
||||
id := c.Param("id")
|
||||
|
||||
@@ -362,7 +362,7 @@ func (h *InitializationHandler) UpdateKBConfig(c *gin.Context) {
|
||||
kb.VLMConfig.CustomInstructions = strings.TrimSpace(req.VLMConfig.CustomInstructions)
|
||||
}
|
||||
|
||||
// 存储引擎:仅写入 provider 到新字段,参数从租户全局 StorageEngineConfig 读取
|
||||
// 存储引擎:仅写入 provider 到新字段,参数从空间全局 StorageEngineConfig 读取
|
||||
provider := strings.ToLower(strings.TrimSpace(req.StorageProvider))
|
||||
if provider == "" {
|
||||
provider = "local"
|
||||
@@ -1696,7 +1696,7 @@ func (h *InitializationHandler) buildTestModel(
|
||||
}
|
||||
}
|
||||
|
||||
// resolveTenantWeKnoraCloudCreds 从当前租户上下文里取出 WeKnoraCloud 凭证,
|
||||
// resolveTenantWeKnoraCloudCreds 从当前空间上下文里取出 WeKnoraCloud 凭证,
|
||||
// 供测试连接端点补齐 appID/appSecret。与 service.resolveWeKnoraCloudCredentials
|
||||
// 对应,但因为 handler 还没有被注入 tenantService(历史原因),暂时从
|
||||
// TenantInfoFromContext 读取,等效果相同。
|
||||
@@ -1751,7 +1751,7 @@ func (h *InitializationHandler) CheckRemoteModel(c *gin.Context) {
|
||||
appID, appSecret, ok := h.resolveTenantWeKnoraCloudCreds(ctx)
|
||||
if !ok {
|
||||
logger.Error(ctx, "Tenant info not found")
|
||||
c.Error(errors.NewBadRequestError("租户信息未找到"))
|
||||
c.Error(errors.NewBadRequestError("空间信息未找到"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1825,7 +1825,7 @@ func (h *InitializationHandler) TestEmbeddingModel(c *gin.Context) {
|
||||
appID, appSecret, ok := h.resolveTenantWeKnoraCloudCreds(ctx)
|
||||
if !ok {
|
||||
logger.Error(ctx, "Tenant info not found")
|
||||
c.Error(errors.NewBadRequestError("租户信息未找到"))
|
||||
c.Error(errors.NewBadRequestError("空间信息未找到"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1977,7 +1977,7 @@ func (h *InitializationHandler) CheckRerankModel(c *gin.Context) {
|
||||
appID, appSecret, ok := h.resolveTenantWeKnoraCloudCreds(ctx)
|
||||
if !ok {
|
||||
logger.Error(ctx, "Tenant info not found")
|
||||
c.Error(errors.NewBadRequestError("租户信息未找到"))
|
||||
c.Error(errors.NewBadRequestError("空间信息未找到"))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -1002,7 +1002,7 @@ func (h *KnowledgeHandler) DeleteKnowledge(c *gin.Context) {
|
||||
effectiveTenantID, _ := effCtx.Value(types.TenantIDContextKey).(uint64)
|
||||
if effectiveTenantID == 0 {
|
||||
logger.Error(ctx, "Effective tenant ID missing after access validation")
|
||||
c.Error(errors.NewInternalServerError("tenant context unavailable"))
|
||||
c.Error(errors.NewInternalServerError("workspace context unavailable"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1341,13 +1341,13 @@ type GetKnowledgeBatchRequest struct {
|
||||
|
||||
// GetKnowledgeBatch godoc
|
||||
// @Summary 批量获取知识
|
||||
// @Description 根据ID列表批量获取知识条目。可选 kb_id:指定时按该知识库校验权限并用于共享知识库的租户解析;可选 agent_id:使用共享智能体时传此参数,后端按智能体所属租户查询(用于刷新后恢复共享知识库下的文件)
|
||||
// @Description 根据ID列表批量获取知识条目。可选 kb_id:指定时按该知识库校验权限并用于共享知识库的空间解析;可选 agent_id:使用共享智能体时传此参数,后端按智能体所属空间查询(用于刷新后恢复共享知识库下的文件)
|
||||
// @Tags 知识管理
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param ids query []string true "知识ID列表"
|
||||
// @Param kb_id query string false "可选,知识库ID(用于共享知识库时指定范围)"
|
||||
// @Param agent_id query string false "可选,共享智能体ID(用于按智能体租户批量拉取文件详情)"
|
||||
// @Param agent_id query string false "可选,共享智能体ID(用于按智能体空间批量拉取文件详情)"
|
||||
// @Success 200 {object} map[string]interface{} "知识列表"
|
||||
// @Failure 400 {object} errors.AppError "请求参数错误"
|
||||
// @Security Bearer
|
||||
@@ -1709,7 +1709,7 @@ type knowledgeTagBatchRequest struct {
|
||||
|
||||
// UpdateKnowledgeTagBatch godoc
|
||||
// @Summary 批量更新知识标签
|
||||
// @Description 批量更新知识条目的标签。可选 kb_id:指定时按该知识库校验编辑权限并用于共享知识库的租户解析
|
||||
// @Description 批量更新知识条目的标签。可选 kb_id:指定时按该知识库校验编辑权限并用于共享知识库的空间解析
|
||||
// @Tags 知识管理
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
@@ -1898,7 +1898,7 @@ func (h *KnowledgeHandler) SearchKnowledge(c *gin.Context) {
|
||||
_ = userIDVal
|
||||
currentTenantID := c.GetUint64(types.TenantIDContextKey.String())
|
||||
if currentTenantID == 0 {
|
||||
c.Error(errors.NewUnauthorizedError("tenant ID not found"))
|
||||
c.Error(errors.NewUnauthorizedError("workspace ID not found"))
|
||||
return
|
||||
}
|
||||
callerTenantRole := types.TenantRoleFromContext(ctx)
|
||||
|
||||
@@ -472,7 +472,7 @@ func (h *KnowledgeBaseHandler) validateAndGetKnowledgeBase(c *gin.Context) (*typ
|
||||
agent, err := h.agentShareService.GetSharedAgentForTenant(ctx, currentTenantID, callerTenantRole, agentID)
|
||||
if err == nil && agent != nil {
|
||||
if kb.TenantID != agent.TenantID {
|
||||
logger.Warnf(ctx, "Shared agent tenant mismatch, KB %s tenant: %d, agent tenant: %d", id, kb.TenantID, agent.TenantID)
|
||||
logger.Warnf(ctx, "Shared agent workspace mismatch, KB %s tenant: %d, agent tenant: %d", id, kb.TenantID, agent.TenantID)
|
||||
} else {
|
||||
mode := agent.Config.KBSelectionMode
|
||||
if mode == "none" {
|
||||
@@ -549,7 +549,7 @@ func (h *KnowledgeBaseHandler) GetKnowledgeBase(c *gin.Context) {
|
||||
|
||||
// ListKnowledgeBases godoc
|
||||
// @Summary 获取知识库列表
|
||||
// @Description 获取当前租户的所有知识库;或当传入 agent_id(共享智能体)时,校验权限后返回该智能体配置的知识库范围(用于 @ 提及)
|
||||
// @Description 获取当前空间的所有知识库;或当传入 agent_id(共享智能体)时,校验权限后返回该智能体配置的知识库范围(用于 @ 提及)
|
||||
// @Tags 知识库
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
@@ -572,7 +572,7 @@ func (h *KnowledgeBaseHandler) ListKnowledgeBases(c *gin.Context) {
|
||||
_ = userIDVal
|
||||
currentTenantID := c.GetUint64(types.TenantIDContextKey.String())
|
||||
if currentTenantID == 0 {
|
||||
c.Error(apperrors.NewUnauthorizedError("tenant ID not found"))
|
||||
c.Error(apperrors.NewUnauthorizedError("workspace ID not found"))
|
||||
return
|
||||
}
|
||||
callerTenantRole := types.TenantRoleFromContext(ctx)
|
||||
@@ -700,7 +700,7 @@ func (h *KnowledgeBaseHandler) ListKnowledgeBases(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// 批量回填 creator_name,让前端列表能区分「我创建」与「同租户其他成员创建」。
|
||||
// 批量回填 creator_name,让前端列表能区分「我创建」与「同空间其他成员创建」。
|
||||
// 仅在 list 接口里回填,详情 / 编辑场景不依赖这个字段;解析失败(用户已删除、
|
||||
// CreatorID 为空的老数据)就让字段为空,前端按 fallback 渲染。
|
||||
enrichKBCreatorNames(ctx, h.userService, kbs)
|
||||
|
||||
@@ -68,7 +68,7 @@ func (h *MCPCredentialsHandler) Put(c *gin.Context) {
|
||||
serviceID := c.Param("id")
|
||||
tenantID := c.GetUint64(types.TenantIDContextKey.String())
|
||||
if tenantID == 0 {
|
||||
c.Error(errors.NewBadRequestError("Tenant ID cannot be empty"))
|
||||
c.Error(errors.NewBadRequestError("Workspace ID cannot be empty"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ func (h *MCPCredentialsHandler) DeleteField(c *gin.Context) {
|
||||
field := c.Param("field")
|
||||
tenantID := c.GetUint64(types.TenantIDContextKey.String())
|
||||
if tenantID == 0 {
|
||||
c.Error(errors.NewBadRequestError("Tenant ID cannot be empty"))
|
||||
c.Error(errors.NewBadRequestError("Workspace ID cannot be empty"))
|
||||
return
|
||||
}
|
||||
if field != "api_key" && field != "token" {
|
||||
|
||||
@@ -286,7 +286,7 @@ func (h *MCPOAuthHandler) ResolveMCPOAuth(c *gin.Context) {
|
||||
case stderrors.Is(err, approval.ErrAlreadyResolved):
|
||||
c.Error(errors.NewBadRequestError("pending authorization already resolved (timeout / cancel raced your action)"))
|
||||
case stderrors.Is(err, approval.ErrTenantMismatch):
|
||||
c.Error(errors.NewBadRequestError("tenant mismatch"))
|
||||
c.Error(errors.NewBadRequestError("workspace mismatch"))
|
||||
case stderrors.Is(err, approval.ErrUserMismatch):
|
||||
c.Error(errors.NewBadRequestError("user mismatch: only the session owner may resolve this prompt"))
|
||||
default:
|
||||
@@ -325,7 +325,7 @@ func (h *MCPOAuthHandler) ResolveMCPOAuth(c *gin.Context) {
|
||||
case stderrors.Is(err, approval.ErrAlreadyResolved):
|
||||
c.Error(errors.NewBadRequestError("pending authorization already resolved (timeout / cancel raced your action)"))
|
||||
case stderrors.Is(err, approval.ErrTenantMismatch):
|
||||
c.Error(errors.NewBadRequestError("tenant mismatch"))
|
||||
c.Error(errors.NewBadRequestError("workspace mismatch"))
|
||||
case stderrors.Is(err, approval.ErrUserMismatch):
|
||||
c.Error(errors.NewBadRequestError("user mismatch: only the session owner may resolve this prompt"))
|
||||
default:
|
||||
@@ -376,7 +376,7 @@ func (h *MCPOAuthHandler) CancelMCPOAuth(c *gin.Context) {
|
||||
case stderrors.Is(err, approval.ErrAlreadyResolved):
|
||||
c.Error(errors.NewBadRequestError("pending authorization already resolved (timeout / cancel raced your action)"))
|
||||
case stderrors.Is(err, approval.ErrTenantMismatch):
|
||||
c.Error(errors.NewBadRequestError("tenant mismatch"))
|
||||
c.Error(errors.NewBadRequestError("workspace mismatch"))
|
||||
case stderrors.Is(err, approval.ErrUserMismatch):
|
||||
c.Error(errors.NewBadRequestError("user mismatch: only the session owner may resolve this prompt"))
|
||||
default:
|
||||
|
||||
@@ -61,7 +61,7 @@ func (h *MCPServiceHandler) CreateMCPService(c *gin.Context) {
|
||||
tenantID := c.GetUint64(types.TenantIDContextKey.String())
|
||||
if tenantID == 0 {
|
||||
logger.Error(ctx, "Tenant ID is empty")
|
||||
c.Error(errors.NewBadRequestError("Tenant ID cannot be empty"))
|
||||
c.Error(errors.NewBadRequestError("Workspace ID cannot be empty"))
|
||||
return
|
||||
}
|
||||
service.TenantID = tenantID
|
||||
@@ -91,7 +91,7 @@ func (h *MCPServiceHandler) CreateMCPService(c *gin.Context) {
|
||||
|
||||
// ListMCPServices godoc
|
||||
// @Summary 获取MCP服务列表
|
||||
// @Description 获取当前租户的所有MCP服务
|
||||
// @Description 获取当前空间的所有MCP服务
|
||||
// @Tags MCP服务
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
@@ -106,7 +106,7 @@ func (h *MCPServiceHandler) ListMCPServices(c *gin.Context) {
|
||||
tenantID := c.GetUint64(types.TenantIDContextKey.String())
|
||||
if tenantID == 0 {
|
||||
logger.Error(ctx, "Tenant ID is empty")
|
||||
c.Error(errors.NewBadRequestError("Tenant ID cannot be empty"))
|
||||
c.Error(errors.NewBadRequestError("Workspace ID cannot be empty"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ func (h *MCPServiceHandler) GetMCPService(c *gin.Context) {
|
||||
tenantID := c.GetUint64(types.TenantIDContextKey.String())
|
||||
if tenantID == 0 {
|
||||
logger.Error(ctx, "Tenant ID is empty")
|
||||
c.Error(errors.NewBadRequestError("Tenant ID cannot be empty"))
|
||||
c.Error(errors.NewBadRequestError("Workspace ID cannot be empty"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -182,7 +182,7 @@ func (h *MCPServiceHandler) UpdateMCPService(c *gin.Context) {
|
||||
tenantID := c.GetUint64(types.TenantIDContextKey.String())
|
||||
if tenantID == 0 {
|
||||
logger.Error(ctx, "Tenant ID is empty")
|
||||
c.Error(errors.NewBadRequestError("Tenant ID cannot be empty"))
|
||||
c.Error(errors.NewBadRequestError("Workspace ID cannot be empty"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -374,7 +374,7 @@ func (h *MCPServiceHandler) DeleteMCPService(c *gin.Context) {
|
||||
tenantID := c.GetUint64(types.TenantIDContextKey.String())
|
||||
if tenantID == 0 {
|
||||
logger.Error(ctx, "Tenant ID is empty")
|
||||
c.Error(errors.NewBadRequestError("Tenant ID cannot be empty"))
|
||||
c.Error(errors.NewBadRequestError("Workspace ID cannot be empty"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -410,7 +410,7 @@ func (h *MCPServiceHandler) TestMCPService(c *gin.Context) {
|
||||
tenantID := c.GetUint64(types.TenantIDContextKey.String())
|
||||
if tenantID == 0 {
|
||||
logger.Error(ctx, "Tenant ID is empty")
|
||||
c.Error(errors.NewBadRequestError("Tenant ID cannot be empty"))
|
||||
c.Error(errors.NewBadRequestError("Workspace ID cannot be empty"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -455,7 +455,7 @@ func (h *MCPServiceHandler) GetMCPServiceTools(c *gin.Context) {
|
||||
tenantID := c.GetUint64(types.TenantIDContextKey.String())
|
||||
if tenantID == 0 {
|
||||
logger.Error(ctx, "Tenant ID is empty")
|
||||
c.Error(errors.NewBadRequestError("Tenant ID cannot be empty"))
|
||||
c.Error(errors.NewBadRequestError("Workspace ID cannot be empty"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -491,7 +491,7 @@ func (h *MCPServiceHandler) GetMCPServiceResources(c *gin.Context) {
|
||||
tenantID := c.GetUint64(types.TenantIDContextKey.String())
|
||||
if tenantID == 0 {
|
||||
logger.Error(ctx, "Tenant ID is empty")
|
||||
c.Error(errors.NewBadRequestError("Tenant ID cannot be empty"))
|
||||
c.Error(errors.NewBadRequestError("Workspace ID cannot be empty"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -514,7 +514,7 @@ func (h *MCPServiceHandler) ListMCPToolApprovals(c *gin.Context) {
|
||||
serviceID := secutils.SanitizeForLog(c.Param("id"))
|
||||
tenantID := c.GetUint64(types.TenantIDContextKey.String())
|
||||
if tenantID == 0 {
|
||||
c.Error(errors.NewBadRequestError("Tenant ID cannot be empty"))
|
||||
c.Error(errors.NewBadRequestError("Workspace ID cannot be empty"))
|
||||
return
|
||||
}
|
||||
if h.mcpToolApprovalService == nil {
|
||||
@@ -565,7 +565,7 @@ func (h *MCPServiceHandler) SetMCPToolApproval(c *gin.Context) {
|
||||
toolName := c.Param("tool_name")
|
||||
tenantID := c.GetUint64(types.TenantIDContextKey.String())
|
||||
if tenantID == 0 {
|
||||
c.Error(errors.NewBadRequestError("Tenant ID cannot be empty"))
|
||||
c.Error(errors.NewBadRequestError("Workspace ID cannot be empty"))
|
||||
return
|
||||
}
|
||||
if h.mcpToolApprovalService == nil {
|
||||
@@ -611,7 +611,7 @@ func (h *MCPServiceHandler) ResolveToolApproval(c *gin.Context) {
|
||||
pendingID := c.Param("pending_id")
|
||||
tenantID := c.GetUint64(types.TenantIDContextKey.String())
|
||||
if tenantID == 0 {
|
||||
c.Error(errors.NewBadRequestError("Tenant ID cannot be empty"))
|
||||
c.Error(errors.NewBadRequestError("Workspace ID cannot be empty"))
|
||||
return
|
||||
}
|
||||
if h.toolApprovalGate == nil {
|
||||
@@ -661,7 +661,7 @@ func (h *MCPServiceHandler) ResolveToolApproval(c *gin.Context) {
|
||||
case stderrors.Is(err, approval.ErrAlreadyResolved):
|
||||
c.Error(errors.NewBadRequestError("pending approval already resolved (timeout / cancel raced your action)"))
|
||||
case stderrors.Is(err, approval.ErrTenantMismatch):
|
||||
c.Error(errors.NewBadRequestError("tenant mismatch"))
|
||||
c.Error(errors.NewBadRequestError("workspace mismatch"))
|
||||
case stderrors.Is(err, approval.ErrUserMismatch):
|
||||
c.Error(errors.NewBadRequestError("user mismatch: only the session owner may resolve this approval"))
|
||||
default:
|
||||
|
||||
@@ -77,7 +77,7 @@ func (h *ModelHandler) CreateModel(c *gin.Context) {
|
||||
tenantID := c.GetUint64(types.TenantIDContextKey.String())
|
||||
if tenantID == 0 {
|
||||
logger.Error(ctx, "Tenant ID is empty")
|
||||
c.Error(errors.NewBadRequestError("Tenant ID cannot be empty"))
|
||||
c.Error(errors.NewBadRequestError("Workspace ID cannot be empty"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -169,7 +169,7 @@ func (h *ModelHandler) GetModel(c *gin.Context) {
|
||||
|
||||
// ListModels godoc
|
||||
// @Summary 获取模型列表
|
||||
// @Description 获取当前租户的所有模型
|
||||
// @Description 获取当前空间的所有模型
|
||||
// @Tags 模型管理
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
@@ -186,7 +186,7 @@ func (h *ModelHandler) ListModels(c *gin.Context) {
|
||||
tenantID := c.GetUint64(types.TenantIDContextKey.String())
|
||||
if tenantID == 0 {
|
||||
logger.Error(ctx, "Tenant ID is empty")
|
||||
c.Error(errors.NewBadRequestError("Tenant ID cannot be empty"))
|
||||
c.Error(errors.NewBadRequestError("Workspace ID cannot be empty"))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ func (h *ModelCredentialsHandler) Put(c *gin.Context) {
|
||||
id := c.Param("id")
|
||||
tenantID := c.GetUint64(types.TenantIDContextKey.String())
|
||||
if tenantID == 0 {
|
||||
c.Error(errors.NewBadRequestError("Tenant ID cannot be empty"))
|
||||
c.Error(errors.NewBadRequestError("Workspace ID cannot be empty"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ func (h *ModelCredentialsHandler) DeleteField(c *gin.Context) {
|
||||
field := c.Param("field")
|
||||
tenantID := c.GetUint64(types.TenantIDContextKey.String())
|
||||
if tenantID == 0 {
|
||||
c.Error(errors.NewBadRequestError("Tenant ID cannot be empty"))
|
||||
c.Error(errors.NewBadRequestError("Workspace ID cannot be empty"))
|
||||
return
|
||||
}
|
||||
if field != "api_key" && field != "app_secret" {
|
||||
|
||||
@@ -148,7 +148,7 @@ func (h *OrganizationHandler) GetOrganization(c *gin.Context) {
|
||||
// ListMyOrganizations lists organizations that the current tenant belongs to.
|
||||
// Response includes resource_counts (per-org KB/agent counts) for list sidebar so frontend does not need a separate GET /me/resource-counts.
|
||||
// @Summary 获取我的组织列表
|
||||
// @Description 获取当前租户所属的所有组织,并附带各空间内知识库/智能体数量
|
||||
// @Description 获取当前空间所属的所有组织,并附带各空间内知识库/智能体数量
|
||||
// @Tags 组织管理
|
||||
// @Produce json
|
||||
// @Success 200 {object} types.ListOrganizationsResponse
|
||||
@@ -370,7 +370,7 @@ func (h *OrganizationHandler) DeleteOrganization(c *gin.Context) {
|
||||
|
||||
// ListMembers lists all tenant-members of an organization
|
||||
// @Summary 获取组织成员列表
|
||||
// @Description 获取组织的所有成员(按租户)
|
||||
// @Description 获取组织的所有成员(按空间)
|
||||
// @Tags 组织管理
|
||||
// @Produce json
|
||||
// @Param id path string true "组织ID"
|
||||
@@ -389,7 +389,7 @@ func (h *OrganizationHandler) ListMembers(c *gin.Context) {
|
||||
// get 403 — mirrors ListOrgShares / ListOrgAgentShares which already
|
||||
// gate on GetTenantMember.
|
||||
if _, err := h.orgService.GetTenantMember(ctx, orgID, tenantID); err != nil {
|
||||
c.Error(apperrors.NewForbiddenError("Your tenant is not a member of this organization"))
|
||||
c.Error(apperrors.NewForbiddenError("Your workspace is not a member of this organization"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -439,12 +439,12 @@ func (h *OrganizationHandler) ListMembers(c *gin.Context) {
|
||||
|
||||
// UpdateMemberRole updates a tenant-member's role
|
||||
// @Summary 更新成员角色
|
||||
// @Description 更新组织成员(租户)的角色(需要管理员权限)
|
||||
// @Description 更新组织成员(空间)的角色(需要管理员权限)
|
||||
// @Tags 组织管理
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path string true "组织ID"
|
||||
// @Param tenant_id path string true "成员租户ID"
|
||||
// @Param tenant_id path string true "成员空间ID"
|
||||
// @Param request body types.UpdateMemberRoleRequest true "角色信息"
|
||||
// @Success 200 {object} map[string]interface{}
|
||||
// @Failure 403 {object} apperrors.AppError
|
||||
@@ -457,7 +457,7 @@ func (h *OrganizationHandler) UpdateMemberRole(c *gin.Context) {
|
||||
memberTenantIDStr := c.Param("tenant_id")
|
||||
memberTenantID, err := strconv.ParseUint(memberTenantIDStr, 10, 64)
|
||||
if err != nil {
|
||||
c.Error(apperrors.NewValidationError("Invalid tenant ID"))
|
||||
c.Error(apperrors.NewValidationError("Invalid workspace ID"))
|
||||
return
|
||||
}
|
||||
operatorUserID := c.GetString(types.UserIDContextKey.String())
|
||||
@@ -483,10 +483,10 @@ func (h *OrganizationHandler) UpdateMemberRole(c *gin.Context) {
|
||||
|
||||
// RemoveMember removes a tenant-member from an organization
|
||||
// @Summary 移除成员
|
||||
// @Description 从组织中移除成员租户(需要管理员权限)
|
||||
// @Description 从组织中移除成员空间(需要管理员权限)
|
||||
// @Tags 组织管理
|
||||
// @Param id path string true "组织ID"
|
||||
// @Param tenant_id path string true "成员租户ID"
|
||||
// @Param tenant_id path string true "成员空间ID"
|
||||
// @Success 200 {object} map[string]interface{}
|
||||
// @Failure 403 {object} apperrors.AppError
|
||||
// @Security Bearer
|
||||
@@ -498,7 +498,7 @@ func (h *OrganizationHandler) RemoveMember(c *gin.Context) {
|
||||
memberTenantIDStr := c.Param("tenant_id")
|
||||
memberTenantID, err := strconv.ParseUint(memberTenantIDStr, 10, 64)
|
||||
if err != nil {
|
||||
c.Error(apperrors.NewValidationError("Invalid tenant ID"))
|
||||
c.Error(apperrors.NewValidationError("Invalid workspace ID"))
|
||||
return
|
||||
}
|
||||
operatorUserID := c.GetString(types.UserIDContextKey.String())
|
||||
@@ -681,7 +681,7 @@ func (h *OrganizationHandler) SubmitJoinRequest(c *gin.Context) {
|
||||
// Check if caller's tenant is already a member
|
||||
_, memberErr := h.orgService.GetTenantMember(ctx, org.ID, tenantID)
|
||||
if memberErr == nil {
|
||||
c.Error(apperrors.NewValidationError("Your tenant is already a member of this organization"))
|
||||
c.Error(apperrors.NewValidationError("Your workspace is already a member of this organization"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1225,7 +1225,7 @@ func (h *OrganizationHandler) ListOrgShares(c *gin.Context) {
|
||||
// Check if caller's tenant is a member and get its role for effective-permission calculation
|
||||
member, err := h.orgService.GetTenantMember(ctx, orgID, tenantID)
|
||||
if err != nil {
|
||||
c.Error(apperrors.NewForbiddenError("Your tenant is not a member of this organization"))
|
||||
c.Error(apperrors.NewForbiddenError("Your workspace is not a member of this organization"))
|
||||
return
|
||||
}
|
||||
myRoleInOrg := member.Role
|
||||
@@ -1436,7 +1436,7 @@ func (h *OrganizationHandler) ListOrgAgentShares(c *gin.Context) {
|
||||
tenantID := c.GetUint64(types.TenantIDContextKey.String())
|
||||
member, err := h.orgService.GetTenantMember(ctx, orgID, tenantID)
|
||||
if err != nil {
|
||||
c.Error(apperrors.NewForbiddenError("Your tenant is not a member of this organization"))
|
||||
c.Error(apperrors.NewForbiddenError("Your workspace is not a member of this organization"))
|
||||
return
|
||||
}
|
||||
myRoleInOrg := member.Role
|
||||
@@ -1622,7 +1622,7 @@ func (h *OrganizationHandler) listSpaceKnowledgeBasesInOrganization(ctx context.
|
||||
SourceTenantID: sourceTenantID,
|
||||
SharedAt: agentItem.SharedAt,
|
||||
},
|
||||
// 即便 KB 是「被共享智能体捎带进来」的,只要它属于当前租户
|
||||
// 即便 KB 是「被共享智能体捎带进来」的,只要它属于当前空间
|
||||
// 就应该归到「我共享的」分组——否则用户会在共享空间里看到
|
||||
// 自己的 KB 出现在「共享给我·仅查看」组里,非常迷惑。
|
||||
IsMine: sourceTenantID == tenantID,
|
||||
@@ -1656,7 +1656,7 @@ func (h *OrganizationHandler) ListOrganizationSharedKnowledgeBases(c *gin.Contex
|
||||
list, err := h.listSpaceKnowledgeBasesInOrganization(ctx, orgID, tenantID, callerTenantRole)
|
||||
if err != nil {
|
||||
if errors.Is(err, service.ErrTenantNotInOrg) {
|
||||
c.Error(apperrors.NewForbiddenError("Your tenant is not a member of this organization"))
|
||||
c.Error(apperrors.NewForbiddenError("Your workspace is not a member of this organization"))
|
||||
return
|
||||
}
|
||||
logger.Errorf(ctx, "Failed to list organization shared knowledge bases: %v", err)
|
||||
@@ -1703,7 +1703,7 @@ func (h *OrganizationHandler) ListOrganizationSharedAgents(c *gin.Context) {
|
||||
list, err := h.agentShareService.ListSharedAgentsInOrganization(ctx, orgID, tenantID, callerTenantRole)
|
||||
if err != nil {
|
||||
if errors.Is(err, service.ErrTenantNotInOrg) {
|
||||
c.Error(apperrors.NewForbiddenError("Your tenant is not a member of this organization"))
|
||||
c.Error(apperrors.NewForbiddenError("Your workspace is not a member of this organization"))
|
||||
return
|
||||
}
|
||||
logger.Errorf(ctx, "Failed to list organization shared agents: %v", err)
|
||||
@@ -1833,12 +1833,12 @@ func (h *OrganizationHandler) toOrgResponse(ctx context.Context, org *types.Orga
|
||||
// canonical name, filters out tenants already in the org, and returns one row
|
||||
// per candidate tenant with one representative user attached for display.
|
||||
//
|
||||
// @Summary 搜索可邀请的租户
|
||||
// @Description 搜索租户(排除已加入的租户)用于邀请加入组织;按租户去重,附带代表用户
|
||||
// @Summary 搜索可邀请的空间
|
||||
// @Description 搜索空间(排除已加入的空间)用于邀请加入组织;按空间去重,附带代表用户
|
||||
// @Tags 组织管理
|
||||
// @Produce json
|
||||
// @Param id path string true "组织ID"
|
||||
// @Param q query string true "搜索关键词(租户名、用户名或邮箱)"
|
||||
// @Param q query string true "搜索关键词(空间名、用户名或邮箱)"
|
||||
// @Param limit query int false "返回数量限制" default(10)
|
||||
// @Success 200 {object} map[string]interface{}
|
||||
// @Failure 403 {object} apperrors.AppError
|
||||
@@ -2048,7 +2048,7 @@ func (h *OrganizationHandler) InviteMember(c *gin.Context) {
|
||||
// Tenant-id path: validate the tenant exists; pick a sensible
|
||||
// representative when the caller didn't pin one.
|
||||
if _, err := h.tenantService.GetTenantByID(ctx, targetTenantID); err != nil {
|
||||
c.Error(apperrors.NewNotFoundError("Tenant not found"))
|
||||
c.Error(apperrors.NewNotFoundError("Workspace not found"))
|
||||
return
|
||||
}
|
||||
if representativeUserID == "" {
|
||||
@@ -2086,7 +2086,7 @@ func (h *OrganizationHandler) InviteMember(c *gin.Context) {
|
||||
|
||||
// Check if target tenant is already a member of this org.
|
||||
if _, memberErr := h.orgService.GetTenantMember(ctx, orgID, targetTenantID); memberErr == nil {
|
||||
c.Error(apperrors.NewValidationError("Tenant is already a member of this organization"))
|
||||
c.Error(apperrors.NewValidationError("Workspace is already a member of this organization"))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -39,9 +39,9 @@ func (h *KnowledgeBaseHandler) KBCreatorLookup(c *gin.Context) (string, error) {
|
||||
ctx := c.Request.Context()
|
||||
tenantID, ok := types.TenantIDFromContext(ctx)
|
||||
if !ok {
|
||||
// 没有租户上下文意味着 auth 中间件未完成;当作 lookup 失败让上层 503,
|
||||
// 没有空间上下文意味着 auth 中间件未完成;当作 lookup 失败让上层 503,
|
||||
// 而不是 silently 走 fail-open 给一个不该有的访问。
|
||||
return "", errors.New("tenant context missing")
|
||||
return "", errors.New("workspace context missing")
|
||||
}
|
||||
kb, err := h.service.GetKnowledgeBaseByID(ctx, id)
|
||||
if err != nil {
|
||||
@@ -53,8 +53,8 @@ func (h *KnowledgeBaseHandler) KBCreatorLookup(c *gin.Context) (string, error) {
|
||||
if kb == nil {
|
||||
return "", middleware.ErrResourceNotFound
|
||||
}
|
||||
// 显式重校验租户:repo.GetKnowledgeBaseByID 不带 tenant 过滤,
|
||||
// 万一未来 :id 被攻击者从他人租户 UUID 试探到,也不会借由
|
||||
// 显式重校验空间:repo.GetKnowledgeBaseByID 不带 tenant 过滤,
|
||||
// 万一未来 :id 被攻击者从他人空间 UUID 试探到,也不会借由
|
||||
// "ownership match" 通过中间件。
|
||||
if kb.TenantID != tenantID {
|
||||
return "", middleware.ErrResourceNotFound
|
||||
@@ -77,7 +77,7 @@ func (h *KnowledgeBaseHandler) KBCreatorLookupFromKbIDParam(c *gin.Context) (str
|
||||
ctx := c.Request.Context()
|
||||
tenantID, ok := types.TenantIDFromContext(ctx)
|
||||
if !ok {
|
||||
return "", errors.New("tenant context missing")
|
||||
return "", errors.New("workspace context missing")
|
||||
}
|
||||
kb, err := h.service.GetKnowledgeBaseByID(ctx, id)
|
||||
if err != nil {
|
||||
@@ -112,7 +112,7 @@ func (h *CustomAgentHandler) AgentCreatorLookup(c *gin.Context) (string, error)
|
||||
ctx := c.Request.Context()
|
||||
tenantID, ok := types.TenantIDFromContext(ctx)
|
||||
if !ok {
|
||||
return "", errors.New("tenant context missing")
|
||||
return "", errors.New("workspace context missing")
|
||||
}
|
||||
agent, err := h.service.GetAgentByID(ctx, id)
|
||||
if err != nil {
|
||||
@@ -195,7 +195,7 @@ func (h *ChunkHandler) KBCreatorLookupFromChunkIDParam(c *gin.Context) (string,
|
||||
ctx := c.Request.Context()
|
||||
tenantID, ok := types.TenantIDFromContext(ctx)
|
||||
if !ok {
|
||||
return "", errors.New("tenant context missing")
|
||||
return "", errors.New("workspace context missing")
|
||||
}
|
||||
chunk, err := h.service.GetChunkByIDOnly(ctx, chunkID)
|
||||
if err != nil {
|
||||
@@ -207,7 +207,7 @@ func (h *ChunkHandler) KBCreatorLookupFromChunkIDParam(c *gin.Context) (string,
|
||||
if chunk == nil {
|
||||
return "", middleware.ErrResourceNotFound
|
||||
}
|
||||
// 显式重校验租户:GetChunkByIDOnly 无租户过滤,必须在此挡住跨租户 chunk
|
||||
// 显式重校验空间:GetChunkByIDOnly 无空间过滤,必须在此挡住跨空间 chunk
|
||||
// id 撞库通过 ownership 匹配获取本不该有的访问。
|
||||
if chunk.TenantID != tenantID {
|
||||
return "", middleware.ErrResourceNotFound
|
||||
@@ -229,7 +229,7 @@ func (h *WikiPageHandler) KBCreatorLookupFromKBPath(c *gin.Context) (string, err
|
||||
ctx := c.Request.Context()
|
||||
tenantID, ok := types.TenantIDFromContext(ctx)
|
||||
if !ok {
|
||||
return "", errors.New("tenant context missing")
|
||||
return "", errors.New("workspace context missing")
|
||||
}
|
||||
kb, err := h.kbService.GetKnowledgeBaseByID(ctx, kbID)
|
||||
if err != nil {
|
||||
@@ -258,7 +258,7 @@ func resolveKBCreatorByKBID(
|
||||
ctx := c.Request.Context()
|
||||
tenantID, ok := types.TenantIDFromContext(ctx)
|
||||
if !ok {
|
||||
return "", errors.New("tenant context missing")
|
||||
return "", errors.New("workspace context missing")
|
||||
}
|
||||
kb, err := kbService.GetKnowledgeBaseByID(ctx, kbID)
|
||||
if err != nil {
|
||||
@@ -291,7 +291,7 @@ func resolveKBCreatorByKnowledgeID(
|
||||
// Same fail-closed reasoning as KBCreatorLookup: no tenant
|
||||
// context means auth didn't complete, and we'd rather have the
|
||||
// caller see a 503 than a silent fail-open.
|
||||
return "", errors.New("tenant context missing")
|
||||
return "", errors.New("workspace context missing")
|
||||
}
|
||||
creatorID, err := kgService.GetOwningKBCreatorID(ctx, knowledgeID)
|
||||
if err != nil {
|
||||
|
||||
@@ -103,7 +103,7 @@ func TestKBCreatorLookup_MissingTenantContext(t *testing.T) {
|
||||
}}
|
||||
_, err := h.KBCreatorLookup(c)
|
||||
if err == nil {
|
||||
t.Fatalf("expected error when tenant context missing")
|
||||
t.Fatalf("expected error when workspace context missing")
|
||||
}
|
||||
if errors.Is(err, middleware.ErrResourceNotFound) {
|
||||
t.Fatalf("missing tenant must not be reported as not-found: %v", err)
|
||||
@@ -279,7 +279,7 @@ func TestKBCreatorLookupFromKnowledgeID_MissingTenantContext(t *testing.T) {
|
||||
}}
|
||||
_, err := h.KBCreatorLookupFromKnowledgeID(c)
|
||||
if err == nil {
|
||||
t.Fatalf("expected error when tenant context missing")
|
||||
t.Fatalf("expected error when workspace context missing")
|
||||
}
|
||||
if errors.Is(err, middleware.ErrResourceNotFound) {
|
||||
t.Fatalf("missing tenant must not be reported as not-found: %v", err)
|
||||
|
||||
@@ -191,7 +191,7 @@ func (h *Handler) GetSession(c *gin.Context) {
|
||||
|
||||
// GetSessionsByTenant godoc
|
||||
// @Summary 获取会话列表
|
||||
// @Description 获取当前租户的会话列表,支持分页、关键字搜索、按来源/Agent 筛选
|
||||
// @Description 获取当前空间的会话列表,支持分页、关键字搜索、按来源/Agent 筛选
|
||||
// @Tags 会话
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
@@ -405,7 +405,7 @@ type batchDeleteRequest struct {
|
||||
|
||||
// BatchDeleteSessions godoc
|
||||
// @Summary 批量删除会话
|
||||
// @Description 根据ID列表批量删除对话会话,或设置 delete_all=true 删除当前租户的所有会话
|
||||
// @Description 根据ID列表批量删除对话会话,或设置 delete_all=true 删除当前空间的所有会话
|
||||
// @Tags 会话
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
|
||||
@@ -46,7 +46,7 @@ type CreateKnowledgeQARequest struct {
|
||||
KnowledgeBaseIDs []string `json:"knowledge_base_ids"` // Selected knowledge base ID for this request
|
||||
KnowledgeIds []string `json:"knowledge_ids"` // Selected knowledge ID for this request
|
||||
AgentEnabled bool `json:"agent_enabled"` // Whether agent mode is enabled for this request
|
||||
AgentID string `json:"agent_id"` // Selected custom agent ID (backend resolves shared agent and its tenant from share relation)
|
||||
AgentID string `json:"agent_id"` // Selected custom agent ID (backend resolves shared agent and its workspace from share relation)
|
||||
WebSearchEnabled bool `json:"web_search_enabled"` // Whether web search is enabled for this request
|
||||
SummaryModelID string `json:"summary_model_id"` // Optional summary model ID for this request (overrides session default)
|
||||
MCPServiceIDs []string `json:"mcp_service_ids"` // Per-request MCP services selected via @mention
|
||||
|
||||
@@ -1453,7 +1453,7 @@ func (h *SystemHandler) ResetUserPassword(c *gin.Context) {
|
||||
// ListSystemSettings godoc
|
||||
// @Summary List all system settings
|
||||
// @Description Return every row in the system_settings table (system-scope,
|
||||
// @Description not tenant-scope). SystemAdmin only.
|
||||
// @Description not workspace-scoped). SystemAdmin only.
|
||||
// @Tags System Admin
|
||||
// @Produce json
|
||||
// @Success 200 {array} types.SystemSetting "list of settings"
|
||||
@@ -2015,11 +2015,11 @@ func (h *SystemHandler) UpdateSystemSetting(c *gin.Context) {
|
||||
}
|
||||
|
||||
// ApplyDefaultStorageQuotaToAllTenants godoc
|
||||
// @Summary Apply the default storage quota to every existing tenant
|
||||
// @Summary Apply the default storage quota to every existing workspace
|
||||
// @Description Reads the current value of `tenant.default_storage_quota_gb`
|
||||
// @Description (3-tier resolver: DB > ENV > default) and writes that many
|
||||
// @Description GiB into storage_quota for every row in tenants. Bypasses
|
||||
// @Description the per-tenant PUT whitelist, which forbids storage_quota
|
||||
// @Description the per-workspace PUT whitelist, which forbids storage_quota
|
||||
// @Description edits by Owners. SystemAdmin only.
|
||||
// @Description Idempotent — running twice with the same setting is a no-op.
|
||||
// @Tags System Admin
|
||||
|
||||
+114
-114
@@ -199,17 +199,17 @@ func (h *TenantHandler) resolveMaxOwnedTenantsPerUser(ctx context.Context) int {
|
||||
}
|
||||
|
||||
// CreateTenant godoc
|
||||
// @Summary 创建租户
|
||||
// @Description 创建新的租户。任意已登录用户均可调用以建立自己的新工作区,
|
||||
// @Description 调用方会被自动设为该租户的 Owner。跨租户超管仍可像以前一样
|
||||
// @Description 通过本接口创建任意租户。
|
||||
// @Summary 创建空间
|
||||
// @Description 创建新的空间。任意已登录用户均可调用以建立自己的新工作区,
|
||||
// @Description 调用方会被自动设为该空间的 Owner。跨空间超管仍可像以前一样
|
||||
// @Description 通过本接口创建任意空间。
|
||||
// @Description 当 tenant.auto_create_api_key(或 WEKNORA_TENANT_AUTO_CREATE_API_KEY)
|
||||
// @Description 开启时,会自动创建一个 full_access API Key,并在响应体的 data.api_key 字段返回其明文 token。
|
||||
// @Tags 租户管理
|
||||
// @Tags 空间管理
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param request body handler.createTenantRequest true "租户信息"
|
||||
// @Success 201 {object} map[string]interface{} "创建的租户(可选含 api_key)"
|
||||
// @Param request body handler.createTenantRequest true "空间信息"
|
||||
// @Success 201 {object} map[string]interface{} "创建的空间(可选含 api_key)"
|
||||
// @Failure 400 {object} errors.AppError "请求参数错误"
|
||||
// @Security Bearer
|
||||
// @Router /tenants [post]
|
||||
@@ -278,7 +278,7 @@ func (h *TenantHandler) CreateTenant(c *gin.Context) {
|
||||
memberships, listErr := h.memberService.ListByUser(ctx, caller.ID)
|
||||
if listErr != nil {
|
||||
logger.Errorf(ctx, "Failed to count owned tenants for user %s: %v", caller.ID, listErr)
|
||||
c.Error(errors.NewInternalServerError("Failed to validate tenant quota").WithDetails(listErr.Error()))
|
||||
c.Error(errors.NewInternalServerError("Failed to validate workspace quota").WithDetails(listErr.Error()))
|
||||
return
|
||||
}
|
||||
ownedCount := 0
|
||||
@@ -294,7 +294,7 @@ func (h *TenantHandler) CreateTenant(c *gin.Context) {
|
||||
caller.ID, ownedCount, cap,
|
||||
)
|
||||
c.Error(errors.NewTooManyRequestsError(
|
||||
"reached self-service tenant quota; contact an administrator to raise the limit",
|
||||
"reached self-service workspace quota; contact an administrator to raise the limit",
|
||||
))
|
||||
return
|
||||
}
|
||||
@@ -335,11 +335,11 @@ func (h *TenantHandler) CreateTenant(c *gin.Context) {
|
||||
if err != nil {
|
||||
// Check if this is an application-specific error
|
||||
if appErr, ok := errors.IsAppError(err); ok {
|
||||
logger.Error(ctx, "Failed to create tenant: application error", appErr)
|
||||
logger.Error(ctx, "Failed to create workspace: application error", appErr)
|
||||
c.Error(appErr)
|
||||
} else {
|
||||
logger.ErrorWithFields(ctx, err, nil)
|
||||
c.Error(errors.NewInternalServerError("Failed to create tenant").WithDetails(err.Error()))
|
||||
c.Error(errors.NewInternalServerError("Failed to create workspace").WithDetails(err.Error()))
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -363,7 +363,7 @@ func (h *TenantHandler) CreateTenant(c *gin.Context) {
|
||||
createdTenant.ID, delErr,
|
||||
)
|
||||
}
|
||||
c.Error(errors.NewInternalServerError("Failed to finalise tenant ownership").WithDetails(err.Error()))
|
||||
c.Error(errors.NewInternalServerError("Failed to finalise workspace ownership").WithDetails(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -405,7 +405,7 @@ func (h *TenantHandler) CreateTenant(c *gin.Context) {
|
||||
)
|
||||
}
|
||||
c.Error(errors.NewTooManyRequestsError(
|
||||
"reached self-service tenant quota; contact an administrator to raise the limit",
|
||||
"reached self-service workspace quota; contact an administrator to raise the limit",
|
||||
))
|
||||
return
|
||||
}
|
||||
@@ -425,7 +425,7 @@ func (h *TenantHandler) CreateTenant(c *gin.Context) {
|
||||
_ = h.memberService.RemoveMember(ctx, caller.ID, createdTenant.ID)
|
||||
}
|
||||
_ = h.service.DeleteTenant(ctx, createdTenant.ID)
|
||||
c.Error(errors.NewInternalServerError("Failed to finalise default tenant").WithDetails(err.Error()))
|
||||
c.Error(errors.NewInternalServerError("Failed to finalise default workspace").WithDetails(err.Error()))
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -510,15 +510,15 @@ func (h *TenantHandler) autoCreateTenantAPIKey(ctx context.Context) bool {
|
||||
}
|
||||
|
||||
// GetTenant godoc
|
||||
// @Summary 获取租户详情
|
||||
// @Description 根据ID获取租户详情
|
||||
// @Tags 租户管理
|
||||
// @Summary 获取空间详情
|
||||
// @Description 根据ID获取空间详情
|
||||
// @Tags 空间管理
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path int true "租户ID"
|
||||
// @Success 200 {object} map[string]interface{} "租户详情"
|
||||
// @Param id path int true "空间ID"
|
||||
// @Success 200 {object} map[string]interface{} "空间详情"
|
||||
// @Failure 400 {object} errors.AppError "请求参数错误"
|
||||
// @Failure 404 {object} errors.AppError "租户不存在"
|
||||
// @Failure 404 {object} errors.AppError "空间不存在"
|
||||
// @Security Bearer
|
||||
// @Security ApiKeyAuth
|
||||
// @Router /tenants/{id} [get]
|
||||
@@ -527,19 +527,19 @@ func (h *TenantHandler) GetTenant(c *gin.Context) {
|
||||
|
||||
id, err := strconv.ParseUint(c.Param("id"), 10, 64)
|
||||
if err != nil {
|
||||
logger.Errorf(ctx, "Invalid tenant ID: %s", secutils.SanitizeForLog(c.Param("id")))
|
||||
c.Error(errors.NewBadRequestError("Invalid tenant ID"))
|
||||
logger.Errorf(ctx, "Invalid workspace ID: %s", secutils.SanitizeForLog(c.Param("id")))
|
||||
c.Error(errors.NewBadRequestError("Invalid workspace ID"))
|
||||
return
|
||||
}
|
||||
|
||||
tenant, err := h.service.GetTenantByID(ctx, id)
|
||||
if err != nil {
|
||||
if appErr, ok := errors.IsAppError(err); ok {
|
||||
logger.Error(ctx, "Failed to retrieve tenant: application error", appErr)
|
||||
logger.Error(ctx, "Failed to retrieve workspace: application error", appErr)
|
||||
c.Error(appErr)
|
||||
} else {
|
||||
logger.ErrorWithFields(ctx, err, nil)
|
||||
c.Error(errors.NewInternalServerError("Failed to retrieve tenant").WithDetails(err.Error()))
|
||||
c.Error(errors.NewInternalServerError("Failed to retrieve workspace").WithDetails(err.Error()))
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -551,14 +551,14 @@ func (h *TenantHandler) GetTenant(c *gin.Context) {
|
||||
}
|
||||
|
||||
// UpdateTenant godoc
|
||||
// @Summary 更新租户
|
||||
// @Description 更新租户信息
|
||||
// @Tags 租户管理
|
||||
// @Summary 更新空间
|
||||
// @Description 更新空间信息
|
||||
// @Tags 空间管理
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path int true "租户ID"
|
||||
// @Param request body types.Tenant true "租户信息"
|
||||
// @Success 200 {object} map[string]interface{} "更新后的租户"
|
||||
// @Param id path int true "空间ID"
|
||||
// @Param request body types.Tenant true "空间信息"
|
||||
// @Success 200 {object} map[string]interface{} "更新后的空间"
|
||||
// @Failure 400 {object} errors.AppError "请求参数错误"
|
||||
// @Security Bearer
|
||||
// @Router /tenants/{id} [put]
|
||||
@@ -569,8 +569,8 @@ func (h *TenantHandler) UpdateTenant(c *gin.Context) {
|
||||
|
||||
id, err := strconv.ParseUint(c.Param("id"), 10, 64)
|
||||
if err != nil {
|
||||
logger.Errorf(ctx, "Invalid tenant ID: %s", secutils.SanitizeForLog(c.Param("id")))
|
||||
c.Error(errors.NewBadRequestError("Invalid tenant ID"))
|
||||
logger.Errorf(ctx, "Invalid workspace ID: %s", secutils.SanitizeForLog(c.Param("id")))
|
||||
c.Error(errors.NewBadRequestError("Invalid workspace ID"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -598,7 +598,7 @@ func (h *TenantHandler) UpdateTenant(c *gin.Context) {
|
||||
c.Error(appErr)
|
||||
} else {
|
||||
logger.ErrorWithFields(ctx, err, nil)
|
||||
c.Error(errors.NewInternalServerError("Failed to load tenant").WithDetails(err.Error()))
|
||||
c.Error(errors.NewInternalServerError("Failed to load workspace").WithDetails(err.Error()))
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -620,11 +620,11 @@ func (h *TenantHandler) UpdateTenant(c *gin.Context) {
|
||||
updatedTenant, err := h.service.UpdateTenant(ctx, existing)
|
||||
if err != nil {
|
||||
if appErr, ok := errors.IsAppError(err); ok {
|
||||
logger.Error(ctx, "Failed to update tenant: application error", appErr)
|
||||
logger.Error(ctx, "Failed to update workspace: application error", appErr)
|
||||
c.Error(appErr)
|
||||
} else {
|
||||
logger.ErrorWithFields(ctx, err, nil)
|
||||
c.Error(errors.NewInternalServerError("Failed to update tenant").WithDetails(err.Error()))
|
||||
c.Error(errors.NewInternalServerError("Failed to update workspace").WithDetails(err.Error()))
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -645,7 +645,7 @@ func (h *TenantHandler) ListAPIKeys(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
id, err := strconv.ParseUint(c.Param("id"), 10, 64)
|
||||
if err != nil {
|
||||
c.Error(errors.NewBadRequestError("Invalid tenant ID"))
|
||||
c.Error(errors.NewBadRequestError("Invalid workspace ID"))
|
||||
return
|
||||
}
|
||||
keys, err := h.apiKeyService.ListAPIKeys(ctx, id)
|
||||
@@ -664,7 +664,7 @@ func (h *TenantHandler) CreateAPIKey(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
id, err := strconv.ParseUint(c.Param("id"), 10, 64)
|
||||
if err != nil {
|
||||
c.Error(errors.NewBadRequestError("Invalid tenant ID"))
|
||||
c.Error(errors.NewBadRequestError("Invalid workspace ID"))
|
||||
return
|
||||
}
|
||||
var req tenantAPIKeyCreateRequest
|
||||
@@ -710,7 +710,7 @@ func (h *TenantHandler) DeleteAPIKey(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
tenantID, err := strconv.ParseUint(c.Param("id"), 10, 64)
|
||||
if err != nil {
|
||||
c.Error(errors.NewBadRequestError("Invalid tenant ID"))
|
||||
c.Error(errors.NewBadRequestError("Invalid workspace ID"))
|
||||
return
|
||||
}
|
||||
keyID, err := strconv.ParseUint(c.Param("key_id"), 10, 64)
|
||||
@@ -776,7 +776,7 @@ func validateTenantAPIKeyRequest(
|
||||
return errors.NewValidationError("knowledge_base_ids contains an unknown knowledge base")
|
||||
}
|
||||
if kb.TenantID != tenantID {
|
||||
return errors.NewForbiddenError("knowledge_base_ids contains a knowledge base outside this tenant")
|
||||
return errors.NewForbiddenError("knowledge_base_ids contains a knowledge base outside this workspace")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@@ -800,12 +800,12 @@ func apiPrincipalConfigForResponse(cfg *types.APIPrincipalConfig) apiPrincipalCo
|
||||
}
|
||||
|
||||
// GetAPIPrincipalConfig godoc
|
||||
// @Summary 获取租户 API Key 用户身份配置
|
||||
// @Summary 获取空间 API Key 用户身份配置
|
||||
// @Description 返回 X-API-Key 请求如何映射为终端 Principal 的配置(Owner)
|
||||
// @Tags 租户管理
|
||||
// @Tags 空间管理
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path int true "租户ID"
|
||||
// @Param id path int true "空间ID"
|
||||
// @Success 200 {object} map[string]interface{} "API principal 配置"
|
||||
// @Failure 400 {object} errors.AppError "请求参数错误"
|
||||
// @Failure 403 {object} errors.AppError "权限不足"
|
||||
@@ -815,7 +815,7 @@ func (h *TenantHandler) GetAPIPrincipalConfig(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
id, err := strconv.ParseUint(c.Param("id"), 10, 64)
|
||||
if err != nil {
|
||||
c.Error(errors.NewBadRequestError("Invalid tenant ID"))
|
||||
c.Error(errors.NewBadRequestError("Invalid workspace ID"))
|
||||
return
|
||||
}
|
||||
tenant, err := h.service.GetTenantByID(ctx, id)
|
||||
@@ -823,7 +823,7 @@ func (h *TenantHandler) GetAPIPrincipalConfig(c *gin.Context) {
|
||||
if appErr, ok := errors.IsAppError(err); ok {
|
||||
c.Error(appErr)
|
||||
} else {
|
||||
c.Error(errors.NewInternalServerError("Failed to load tenant").WithDetails(err.Error()))
|
||||
c.Error(errors.NewInternalServerError("Failed to load workspace").WithDetails(err.Error()))
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -834,12 +834,12 @@ func (h *TenantHandler) GetAPIPrincipalConfig(c *gin.Context) {
|
||||
}
|
||||
|
||||
// UpdateAPIPrincipalConfig godoc
|
||||
// @Summary 更新租户 API Key 用户身份配置
|
||||
// @Summary 更新空间 API Key 用户身份配置
|
||||
// @Description 配置 X-API-Key 请求如何映射为终端 Principal(Owner)
|
||||
// @Tags 租户管理
|
||||
// @Tags 空间管理
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path int true "租户ID"
|
||||
// @Param id path int true "空间ID"
|
||||
// @Param request body handler.apiPrincipalConfigRequest true "API principal 配置"
|
||||
// @Success 200 {object} map[string]interface{} "更新后的配置"
|
||||
// @Failure 400 {object} errors.AppError "请求参数错误"
|
||||
@@ -850,7 +850,7 @@ func (h *TenantHandler) UpdateAPIPrincipalConfig(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
id, err := strconv.ParseUint(c.Param("id"), 10, 64)
|
||||
if err != nil {
|
||||
c.Error(errors.NewBadRequestError("Invalid tenant ID"))
|
||||
c.Error(errors.NewBadRequestError("Invalid workspace ID"))
|
||||
return
|
||||
}
|
||||
var req apiPrincipalConfigRequest
|
||||
@@ -873,7 +873,7 @@ func (h *TenantHandler) UpdateAPIPrincipalConfig(c *gin.Context) {
|
||||
if appErr, ok := errors.IsAppError(err); ok {
|
||||
c.Error(appErr)
|
||||
} else {
|
||||
c.Error(errors.NewInternalServerError("Failed to load tenant").WithDetails(err.Error()))
|
||||
c.Error(errors.NewInternalServerError("Failed to load workspace").WithDetails(err.Error()))
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -923,11 +923,11 @@ func (h *TenantHandler) UpdateAPIPrincipalConfig(c *gin.Context) {
|
||||
|
||||
// CreateAPIPrincipalTestToken godoc
|
||||
// @Summary 生成 API Playground 测试 JWT
|
||||
// @Description 使用租户已保存的 HMAC 密钥签发短期外部用户 JWT(Owner)
|
||||
// @Tags 租户管理
|
||||
// @Description 使用空间已保存的 HMAC 密钥签发短期外部用户 JWT(Owner)
|
||||
// @Tags 空间管理
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path int true "租户ID"
|
||||
// @Param id path int true "空间ID"
|
||||
// @Param request body handler.apiPrincipalTestTokenRequest true "测试 Token 参数"
|
||||
// @Success 200 {object} map[string]interface{} "短期 JWT"
|
||||
// @Failure 400 {object} errors.AppError "请求参数错误"
|
||||
@@ -938,7 +938,7 @@ func (h *TenantHandler) CreateAPIPrincipalTestToken(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
id, err := strconv.ParseUint(c.Param("id"), 10, 64)
|
||||
if err != nil {
|
||||
c.Error(errors.NewBadRequestError("Invalid tenant ID"))
|
||||
c.Error(errors.NewBadRequestError("Invalid workspace ID"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -959,7 +959,7 @@ func (h *TenantHandler) CreateAPIPrincipalTestToken(c *gin.Context) {
|
||||
if appErr, ok := errors.IsAppError(err); ok {
|
||||
c.Error(appErr)
|
||||
} else {
|
||||
c.Error(errors.NewInternalServerError("Failed to load tenant").WithDetails(err.Error()))
|
||||
c.Error(errors.NewInternalServerError("Failed to load workspace").WithDetails(err.Error()))
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -1026,12 +1026,12 @@ func validateAPIPrincipalExternalUserID(id string) error {
|
||||
}
|
||||
|
||||
// DeleteTenant godoc
|
||||
// @Summary 删除租户
|
||||
// @Description 删除指定的租户
|
||||
// @Tags 租户管理
|
||||
// @Summary 删除空间
|
||||
// @Description 删除指定的空间
|
||||
// @Tags 空间管理
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path int true "租户ID"
|
||||
// @Param id path int true "空间ID"
|
||||
// @Success 200 {object} map[string]interface{} "删除成功"
|
||||
// @Failure 400 {object} errors.AppError "请求参数错误"
|
||||
// @Security Bearer
|
||||
@@ -1043,8 +1043,8 @@ func (h *TenantHandler) DeleteTenant(c *gin.Context) {
|
||||
|
||||
id, err := strconv.ParseUint(c.Param("id"), 10, 64)
|
||||
if err != nil {
|
||||
logger.Errorf(ctx, "Invalid tenant ID: %s", secutils.SanitizeForLog(c.Param("id")))
|
||||
c.Error(errors.NewBadRequestError("Invalid tenant ID"))
|
||||
logger.Errorf(ctx, "Invalid workspace ID: %s", secutils.SanitizeForLog(c.Param("id")))
|
||||
c.Error(errors.NewBadRequestError("Invalid workspace ID"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1052,29 +1052,29 @@ func (h *TenantHandler) DeleteTenant(c *gin.Context) {
|
||||
|
||||
if err := h.service.DeleteTenant(ctx, id); err != nil {
|
||||
if appErr, ok := errors.IsAppError(err); ok {
|
||||
logger.Error(ctx, "Failed to delete tenant: application error", appErr)
|
||||
logger.Error(ctx, "Failed to delete workspace: application error", appErr)
|
||||
c.Error(appErr)
|
||||
} else {
|
||||
logger.ErrorWithFields(ctx, err, nil)
|
||||
c.Error(errors.NewInternalServerError("Failed to delete tenant").WithDetails(err.Error()))
|
||||
c.Error(errors.NewInternalServerError("Failed to delete workspace").WithDetails(err.Error()))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
logger.Infof(ctx, "Tenant deleted successfully, ID: %d", id)
|
||||
logger.Infof(ctx, "Workspace deleted successfully, ID: %d", id)
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": true,
|
||||
"message": "Tenant deleted successfully",
|
||||
"message": "Workspace deleted successfully",
|
||||
})
|
||||
}
|
||||
|
||||
// ListTenants godoc
|
||||
// @Summary 获取租户列表
|
||||
// @Description 获取当前用户可访问的租户列表
|
||||
// @Tags 租户管理
|
||||
// @Summary 获取空间列表
|
||||
// @Description 获取当前用户可访问的空间列表
|
||||
// @Tags 空间管理
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} map[string]interface{} "租户列表"
|
||||
// @Success 200 {object} map[string]interface{} "空间列表"
|
||||
// @Failure 500 {object} errors.AppError "服务器错误"
|
||||
// @Security Bearer
|
||||
// @Router /tenants [get]
|
||||
@@ -1096,12 +1096,12 @@ func (h *TenantHandler) ListTenants(c *gin.Context) {
|
||||
}
|
||||
|
||||
// ListAllTenants godoc
|
||||
// @Summary 获取所有租户列表
|
||||
// @Description 获取系统中所有租户(需要跨租户访问权限)
|
||||
// @Tags 租户管理
|
||||
// @Summary 获取所有空间列表
|
||||
// @Description 获取系统中所有空间(需要跨空间访问权限)
|
||||
// @Tags 空间管理
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} map[string]interface{} "所有租户列表"
|
||||
// @Success 200 {object} map[string]interface{} "所有空间列表"
|
||||
// @Failure 403 {object} errors.AppError "权限不足"
|
||||
// @Security Bearer
|
||||
// @Router /tenants/all [get]
|
||||
@@ -1115,11 +1115,11 @@ func (h *TenantHandler) ListAllTenants(c *gin.Context) {
|
||||
if err != nil {
|
||||
// Check if this is an application-specific error
|
||||
if appErr, ok := errors.IsAppError(err); ok {
|
||||
logger.Error(ctx, "Failed to retrieve all tenants list: application error", appErr)
|
||||
logger.Error(ctx, "Failed to retrieve all workspaces list: application error", appErr)
|
||||
c.Error(appErr)
|
||||
} else {
|
||||
logger.ErrorWithFields(ctx, err, nil)
|
||||
c.Error(errors.NewInternalServerError("Failed to retrieve all tenants list").WithDetails(err.Error()))
|
||||
c.Error(errors.NewInternalServerError("Failed to retrieve all workspaces list").WithDetails(err.Error()))
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -1133,13 +1133,13 @@ func (h *TenantHandler) ListAllTenants(c *gin.Context) {
|
||||
}
|
||||
|
||||
// SearchTenants godoc
|
||||
// @Summary 搜索租户
|
||||
// @Description 分页搜索租户(需要跨租户访问权限)
|
||||
// @Tags 租户管理
|
||||
// @Summary 搜索空间
|
||||
// @Description 分页搜索空间(需要跨空间访问权限)
|
||||
// @Tags 空间管理
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param keyword query string false "搜索关键词"
|
||||
// @Param tenant_id query int false "租户ID筛选"
|
||||
// @Param tenant_id query int false "空间ID筛选"
|
||||
// @Param page query int false "页码" default(1)
|
||||
// @Param page_size query int false "每页数量" default(20)
|
||||
// @Success 200 {object} map[string]interface{} "搜索结果"
|
||||
@@ -1185,11 +1185,11 @@ func (h *TenantHandler) SearchTenants(c *gin.Context) {
|
||||
if err != nil {
|
||||
// Check if this is an application-specific error
|
||||
if appErr, ok := errors.IsAppError(err); ok {
|
||||
logger.Error(ctx, "Failed to search tenants: application error", appErr)
|
||||
logger.Error(ctx, "Failed to search workspaces: application error", appErr)
|
||||
c.Error(appErr)
|
||||
} else {
|
||||
logger.ErrorWithFields(ctx, err, nil)
|
||||
c.Error(errors.NewInternalServerError("Failed to search tenants").WithDetails(err.Error()))
|
||||
c.Error(errors.NewInternalServerError("Failed to search workspaces").WithDetails(err.Error()))
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -1206,9 +1206,9 @@ func (h *TenantHandler) SearchTenants(c *gin.Context) {
|
||||
}
|
||||
|
||||
// GetTenantKV godoc
|
||||
// @Summary 获取租户KV配置
|
||||
// @Description 获取租户级别的KV配置(支持web-search-config、prompt-templates、parser-engine-config、storage-engine-config、chat-history-config、retrieval-config)
|
||||
// @Tags 租户管理
|
||||
// @Summary 获取空间KV配置
|
||||
// @Description 获取空间级别的KV配置(支持web-search-config、prompt-templates、parser-engine-config、storage-engine-config、chat-history-config、retrieval-config)
|
||||
// @Tags 空间管理
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param key path string true "配置键名"
|
||||
@@ -1256,9 +1256,9 @@ func (h *TenantHandler) GetTenantKV(c *gin.Context) {
|
||||
}
|
||||
|
||||
// UpdateTenantKV godoc
|
||||
// @Summary 更新租户KV配置
|
||||
// @Description 更新租户级别的KV配置(支持web-search-config、parser-engine-config、storage-engine-config、chat-history-config、retrieval-config)
|
||||
// @Tags 租户管理
|
||||
// @Summary 更新空间KV配置
|
||||
// @Description 更新空间级别的KV配置(支持web-search-config、parser-engine-config、storage-engine-config、chat-history-config、retrieval-config)
|
||||
// @Tags 空间管理
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param key path string true "配置键名"
|
||||
@@ -1317,8 +1317,8 @@ func (h *TenantHandler) updateTenantWebSearchConfigInternal(c *gin.Context) {
|
||||
|
||||
tenant, _ := types.TenantInfoFromContext(ctx)
|
||||
if tenant == nil {
|
||||
logger.Error(ctx, "Tenant is empty")
|
||||
c.Error(errors.NewBadRequestError("Tenant is empty"))
|
||||
logger.Error(ctx, "Workspace is empty")
|
||||
c.Error(errors.NewBadRequestError("Workspace is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1334,11 +1334,11 @@ func (h *TenantHandler) updateTenantWebSearchConfigInternal(c *gin.Context) {
|
||||
updatedTenant, err := h.service.UpdateTenant(ctx, tenant)
|
||||
if err != nil {
|
||||
if appErr, ok := errors.IsAppError(err); ok {
|
||||
logger.Error(ctx, "Failed to update tenant: application error", appErr)
|
||||
logger.Error(ctx, "Failed to update workspace: application error", appErr)
|
||||
c.Error(appErr)
|
||||
} else {
|
||||
logger.ErrorWithFields(ctx, err, nil)
|
||||
c.Error(errors.NewInternalServerError("Failed to update tenant web search config").WithDetails(err.Error()))
|
||||
c.Error(errors.NewInternalServerError("Failed to update workspace web search config").WithDetails(err.Error()))
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -1350,9 +1350,9 @@ func (h *TenantHandler) updateTenantWebSearchConfigInternal(c *gin.Context) {
|
||||
}
|
||||
|
||||
// GetTenantWebSearchConfig godoc
|
||||
// @Summary 获取租户网络搜索配置
|
||||
// @Description 获取租户的网络搜索配置
|
||||
// @Tags 租户管理
|
||||
// @Summary 获取空间网络搜索配置
|
||||
// @Description 获取空间的网络搜索配置
|
||||
// @Tags 空间管理
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} map[string]interface{} "网络搜索配置"
|
||||
@@ -1366,8 +1366,8 @@ func (h *TenantHandler) GetTenantWebSearchConfig(c *gin.Context) {
|
||||
// Get tenant
|
||||
tenant, _ := types.TenantInfoFromContext(ctx)
|
||||
if tenant == nil {
|
||||
logger.Error(ctx, "Tenant is empty")
|
||||
c.Error(errors.NewBadRequestError("Tenant is empty"))
|
||||
logger.Error(ctx, "Workspace is empty")
|
||||
c.Error(errors.NewBadRequestError("Workspace is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1383,8 +1383,8 @@ func (h *TenantHandler) GetTenantParserEngineConfig(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
tenant, _ := types.TenantInfoFromContext(ctx)
|
||||
if tenant == nil {
|
||||
logger.Error(ctx, "Tenant is empty")
|
||||
c.Error(errors.NewBadRequestError("Tenant is empty"))
|
||||
logger.Error(ctx, "Workspace is empty")
|
||||
c.Error(errors.NewBadRequestError("Workspace is empty"))
|
||||
return
|
||||
}
|
||||
data := types.ParserEngineConfigForResponse(tenant.ParserEngineConfig, true)
|
||||
@@ -1408,8 +1408,8 @@ func (h *TenantHandler) updateTenantParserEngineConfigInternal(c *gin.Context) {
|
||||
}
|
||||
tenant, _ := types.TenantInfoFromContext(ctx)
|
||||
if tenant == nil {
|
||||
logger.Error(ctx, "Tenant is empty")
|
||||
c.Error(errors.NewBadRequestError("Tenant is empty"))
|
||||
logger.Error(ctx, "Workspace is empty")
|
||||
c.Error(errors.NewBadRequestError("Workspace is empty"))
|
||||
return
|
||||
}
|
||||
merged := types.MergeParserEngineConfigForUpdate(&cfg, tenant.ParserEngineConfig)
|
||||
@@ -1424,7 +1424,7 @@ func (h *TenantHandler) updateTenantParserEngineConfigInternal(c *gin.Context) {
|
||||
c.Error(appErr)
|
||||
} else {
|
||||
logger.ErrorWithFields(ctx, err, nil)
|
||||
c.Error(errors.NewInternalServerError("Failed to update tenant parser engine config").WithDetails(err.Error()))
|
||||
c.Error(errors.NewInternalServerError("Failed to update workspace parser engine config").WithDetails(err.Error()))
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -1440,8 +1440,8 @@ func (h *TenantHandler) GetTenantStorageEngineConfig(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
tenant, _ := types.TenantInfoFromContext(ctx)
|
||||
if tenant == nil {
|
||||
logger.Error(ctx, "Tenant is empty")
|
||||
c.Error(errors.NewBadRequestError("Tenant is empty"))
|
||||
logger.Error(ctx, "Workspace is empty")
|
||||
c.Error(errors.NewBadRequestError("Workspace is empty"))
|
||||
return
|
||||
}
|
||||
data := types.StorageEngineConfigForResponse(tenant.StorageEngineConfig, true)
|
||||
@@ -1478,8 +1478,8 @@ func (h *TenantHandler) updateTenantStorageEngineConfigInternal(c *gin.Context)
|
||||
cfg.DefaultProvider = provider
|
||||
tenant, _ := types.TenantInfoFromContext(ctx)
|
||||
if tenant == nil {
|
||||
logger.Error(ctx, "Tenant is empty")
|
||||
c.Error(errors.NewBadRequestError("Tenant is empty"))
|
||||
logger.Error(ctx, "Workspace is empty")
|
||||
c.Error(errors.NewBadRequestError("Workspace is empty"))
|
||||
return
|
||||
}
|
||||
merged := types.MergeStorageEngineConfigForUpdate(&cfg, tenant.StorageEngineConfig)
|
||||
@@ -1490,7 +1490,7 @@ func (h *TenantHandler) updateTenantStorageEngineConfigInternal(c *gin.Context)
|
||||
c.Error(appErr)
|
||||
} else {
|
||||
logger.ErrorWithFields(ctx, err, nil)
|
||||
c.Error(errors.NewInternalServerError("Failed to update tenant storage engine config").WithDetails(err.Error()))
|
||||
c.Error(errors.NewInternalServerError("Failed to update workspace storage engine config").WithDetails(err.Error()))
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -1504,7 +1504,7 @@ func (h *TenantHandler) updateTenantStorageEngineConfigInternal(c *gin.Context)
|
||||
// GetPromptTemplates godoc
|
||||
// @Summary 获取提示词模板
|
||||
// @Description 获取系统配置的提示词模板列表
|
||||
// @Tags 租户管理
|
||||
// @Tags 空间管理
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} map[string]interface{} "提示词模板配置"
|
||||
@@ -1546,8 +1546,8 @@ func (h *TenantHandler) GetTenantChatHistoryConfig(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
tenant, _ := types.TenantInfoFromContext(ctx)
|
||||
if tenant == nil {
|
||||
logger.Error(ctx, "Tenant is empty")
|
||||
c.Error(errors.NewBadRequestError("Tenant is empty"))
|
||||
logger.Error(ctx, "Workspace is empty")
|
||||
c.Error(errors.NewBadRequestError("Workspace is empty"))
|
||||
return
|
||||
}
|
||||
data := tenant.ChatHistoryConfig
|
||||
@@ -1576,8 +1576,8 @@ func (h *TenantHandler) updateTenantChatHistoryConfigInternal(c *gin.Context) {
|
||||
|
||||
tenant, _ := types.TenantInfoFromContext(ctx)
|
||||
if tenant == nil {
|
||||
logger.Error(ctx, "Tenant is empty")
|
||||
c.Error(errors.NewBadRequestError("Tenant is empty"))
|
||||
logger.Error(ctx, "Workspace is empty")
|
||||
c.Error(errors.NewBadRequestError("Workspace is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1643,8 +1643,8 @@ func (h *TenantHandler) GetTenantRetrievalConfig(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
tenant, _ := types.TenantInfoFromContext(ctx)
|
||||
if tenant == nil {
|
||||
logger.Error(ctx, "Tenant is empty")
|
||||
c.Error(errors.NewBadRequestError("Tenant is empty"))
|
||||
logger.Error(ctx, "Workspace is empty")
|
||||
c.Error(errors.NewBadRequestError("Workspace is empty"))
|
||||
return
|
||||
}
|
||||
data := tenant.RetrievalConfig
|
||||
@@ -1692,8 +1692,8 @@ func (h *TenantHandler) updateTenantRetrievalConfigInternal(c *gin.Context) {
|
||||
|
||||
tenant, _ := types.TenantInfoFromContext(ctx)
|
||||
if tenant == nil {
|
||||
logger.Error(ctx, "Tenant is empty")
|
||||
c.Error(errors.NewBadRequestError("Tenant is empty"))
|
||||
logger.Error(ctx, "Workspace is empty")
|
||||
c.Error(errors.NewBadRequestError("Workspace is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -187,11 +187,11 @@ func (h *TenantInvitationHandler) hydrateTenants(c *gin.Context, invs []*types.T
|
||||
}
|
||||
|
||||
// ListTenantInvitations godoc
|
||||
// @Summary 列出租户邀请
|
||||
// @Description 按 tenant 列出待接受 / 历史邀请。query include_terminal=true 时附带 accepted/declined/revoked/expired。
|
||||
// @Tags 租户邀请
|
||||
// @Summary 列出空间邀请
|
||||
// @Description 按空间列出待接受 / 历史邀请。query include_terminal=true 时附带 accepted/declined/revoked/expired。
|
||||
// @Tags 空间邀请
|
||||
// @Produce json
|
||||
// @Param id path string true "租户 ID"
|
||||
// @Param id path string true "空间 ID"
|
||||
// @Param include_terminal query bool false "是否包含终止态行(默认 false)"
|
||||
// @Param page query int false "页码(从 1 起)" default(1)
|
||||
// @Param page_size query int false "每页数量" default(20)
|
||||
@@ -244,12 +244,12 @@ func (h *TenantInvitationHandler) ListTenantInvitations(c *gin.Context) {
|
||||
}
|
||||
|
||||
// CreateInvitation godoc
|
||||
// @Summary 发出租户邀请
|
||||
// @Description Owner 通过邮箱邀请已注册用户加入当前租户;被邀请人需要在 /me/invitations 接受后才会成为成员。
|
||||
// @Tags 租户邀请
|
||||
// @Summary 发出空间邀请
|
||||
// @Description Owner 通过邮箱邀请已注册用户加入当前空间;被邀请人需要在 /me/invitations 接受后才会成为成员。
|
||||
// @Tags 空间邀请
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path string true "租户 ID"
|
||||
// @Param id path string true "空间 ID"
|
||||
// @Param request body createInvitationRequest true "邀请请求"
|
||||
// @Success 201 {object} map[string]interface{}
|
||||
// @Security Bearer
|
||||
@@ -325,9 +325,9 @@ func (h *TenantInvitationHandler) CreateInvitation(c *gin.Context) {
|
||||
// RevokeInvitation godoc
|
||||
// @Summary 撤销待接受邀请
|
||||
// @Description Owner 取消一条还在 pending 的邀请;已 accepted/declined/revoked/expired 的行不可再撤销。
|
||||
// @Tags 租户邀请
|
||||
// @Tags 空间邀请
|
||||
// @Produce json
|
||||
// @Param id path string true "租户 ID"
|
||||
// @Param id path string true "空间 ID"
|
||||
// @Param inv_id path string true "邀请 ID"
|
||||
// @Success 200 {object} map[string]interface{}
|
||||
// @Security Bearer
|
||||
@@ -498,7 +498,7 @@ func (h *TenantInvitationHandler) AcceptMyInvitation(c *gin.Context) {
|
||||
if updateErr := h.userService.UpdateUser(ctx, user); updateErr != nil {
|
||||
logger.Errorf(ctx, "AcceptMyInvitation failed to set default tenant: user=%s tenant=%d err=%v",
|
||||
caller, member.TenantID, updateErr)
|
||||
c.Error(apperrors.NewInternalServerError("invitation accepted but default tenant update failed").WithDetails(updateErr.Error()))
|
||||
c.Error(apperrors.NewInternalServerError("invitation accepted but default workspace update failed").WithDetails(updateErr.Error()))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,12 +54,12 @@ type createInviteLinkRequest struct {
|
||||
|
||||
// CreateInviteLink godoc
|
||||
// @Summary 生成共享邀请链接
|
||||
// @Description 生成一条多次使用的共享邀请链接:谁拿到链接谁就能注册并加入当前租户。
|
||||
// @Description 生成一条多次使用的共享邀请链接:谁拿到链接谁就能注册并加入当前空间。
|
||||
// @Description 链接持续有效,直到过期或被撤销。
|
||||
// @Tags 租户邀请
|
||||
// @Tags 空间邀请
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path string true "租户 ID"
|
||||
// @Param id path string true "空间 ID"
|
||||
// @Param request body createInviteLinkRequest true "共享链接配置"
|
||||
// @Success 201 {object} map[string]interface{}
|
||||
// @Security Bearer
|
||||
|
||||
@@ -73,23 +73,23 @@ type updateMemberRoleRequest struct {
|
||||
func parseTenantIDFromPath(c *gin.Context) (uint64, bool) {
|
||||
raw := strings.TrimSpace(c.Param("id"))
|
||||
if raw == "" {
|
||||
c.Error(apperrors.NewValidationError("tenant id is required"))
|
||||
c.Error(apperrors.NewValidationError("workspace id is required"))
|
||||
return 0, false
|
||||
}
|
||||
v, err := strconv.ParseUint(raw, 10, 64)
|
||||
if err != nil || v == 0 {
|
||||
c.Error(apperrors.NewValidationError("tenant id must be a positive integer"))
|
||||
c.Error(apperrors.NewValidationError("workspace id must be a positive integer"))
|
||||
return 0, false
|
||||
}
|
||||
return v, true
|
||||
}
|
||||
|
||||
// ListMembers godoc
|
||||
// @Summary 列出租户成员
|
||||
// @Description 分页返回当前租户内 active 成员(含每位成员的角色、邮箱、头像);支持 q 按邮箱/用户名筛选
|
||||
// @Tags 租户成员
|
||||
// @Summary 列出空间成员
|
||||
// @Description 分页返回当前空间内 active 成员(含每位成员的角色、邮箱、头像);支持 q 按邮箱/用户名筛选
|
||||
// @Tags 空间成员
|
||||
// @Produce json
|
||||
// @Param id path string true "租户 ID"
|
||||
// @Param id path string true "空间 ID"
|
||||
// @Param q query string false "按邮箱/用户名模糊筛选"
|
||||
// @Param page query int false "页码(从 1 起)" default(1)
|
||||
// @Param page_size query int false "每页数量(最大 100)" default(20)
|
||||
@@ -162,15 +162,15 @@ func (h *TenantMemberHandler) ListMembers(c *gin.Context) {
|
||||
}
|
||||
|
||||
// AddMember godoc
|
||||
// @Summary 直接添加租户成员(直加路径)
|
||||
// @Summary 直接添加空间成员(直加路径)
|
||||
// @Description
|
||||
//
|
||||
// Owner 通过 email 直接把用户作为 active 成员添加进当前租户。
|
||||
// Owner 通过 email 直接把用户作为 active 成员添加进当前空间。
|
||||
//
|
||||
// 这是【直加路径】,被加入的用户没有任何确认机会就出现在租户里——
|
||||
// 这是【直加路径】,被加入的用户没有任何确认机会就出现在空间里——
|
||||
// 保留它是为了三类不需要走邀请确认的场景:
|
||||
// 1. 自动化脚本 / 平台运维 / 数据迁移;
|
||||
// 2. 跨租户超管 (CanAccessAllTenants) 的批量编排;
|
||||
// 2. 跨空间超管 (CanAccessAllTenants) 的批量编排;
|
||||
// 3. 对接外部 IdP 时由身份源单向同步成员。
|
||||
//
|
||||
// 所有由 UI 触发的「邀请伙伴加入」交互应改走
|
||||
@@ -178,10 +178,10 @@ func (h *TenantMemberHandler) ListMembers(c *gin.Context) {
|
||||
// 人在 /me/invitations 主动接受后再写 tenant_members 行(PR #1303 后续)。
|
||||
// 这条路径与 invitations 路径共存而不互相替代。
|
||||
//
|
||||
// @Tags 租户成员
|
||||
// @Tags 空间成员
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path string true "租户 ID"
|
||||
// @Param id path string true "空间 ID"
|
||||
// @Param request body addMemberRequest true "邀请请求"
|
||||
// @Success 201 {object} map[string]interface{}
|
||||
// @Security Bearer
|
||||
@@ -271,12 +271,12 @@ func (h *TenantMemberHandler) AddMember(c *gin.Context) {
|
||||
}
|
||||
|
||||
// UpdateMemberRole godoc
|
||||
// @Summary 修改租户成员角色
|
||||
// @Description Owner 修改某位成员在当前租户内的角色;不能将最后一位 Owner 降级
|
||||
// @Tags 租户成员
|
||||
// @Summary 修改空间成员角色
|
||||
// @Description Owner 修改某位成员在当前空间内的角色;不能将最后一位 Owner 降级
|
||||
// @Tags 空间成员
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path string true "租户 ID"
|
||||
// @Param id path string true "空间 ID"
|
||||
// @Param user_id path string true "用户 ID"
|
||||
// @Param request body updateMemberRoleRequest true "目标角色"
|
||||
// @Success 200 {object} map[string]interface{}
|
||||
@@ -324,11 +324,11 @@ func (h *TenantMemberHandler) UpdateMemberRole(c *gin.Context) {
|
||||
}
|
||||
|
||||
// RemoveMember godoc
|
||||
// @Summary 移除租户成员
|
||||
// @Description Owner 将某位成员从当前租户中移除(软删除 tenant_members 行);不能移除最后一位 Owner
|
||||
// @Tags 租户成员
|
||||
// @Summary 移除空间成员
|
||||
// @Description Owner 将某位成员从当前空间中移除(软删除 tenant_members 行);不能移除最后一位 Owner
|
||||
// @Tags 空间成员
|
||||
// @Produce json
|
||||
// @Param id path string true "租户 ID"
|
||||
// @Param id path string true "空间 ID"
|
||||
// @Param user_id path string true "用户 ID"
|
||||
// @Success 200 {object} map[string]interface{}
|
||||
// @Security Bearer
|
||||
@@ -363,15 +363,15 @@ func (h *TenantMemberHandler) RemoveMember(c *gin.Context) {
|
||||
}
|
||||
|
||||
// LeaveTenant godoc
|
||||
// @Summary 退出当前租户
|
||||
// @Description 调用方主动退出当前租户。等价于以自己的 user_id 调 RemoveMember,
|
||||
// @Summary 退出当前空间
|
||||
// @Description 调用方主动退出当前空间。等价于以自己的 user_id 调 RemoveMember,
|
||||
//
|
||||
// 但不需要 Owner 权限——非 Owner 也可以自助离开。最后一位 Owner 仍然不能离开
|
||||
// (需先把其他成员提升为 Owner),由服务层 ErrLastOwner 拦截。
|
||||
//
|
||||
// @Tags 租户成员
|
||||
// @Tags 空间成员
|
||||
// @Produce json
|
||||
// @Param id path string true "租户 ID"
|
||||
// @Param id path string true "空间 ID"
|
||||
// @Success 200 {object} map[string]interface{}
|
||||
// @Security Bearer
|
||||
// @Router /tenants/{id}/leave [post]
|
||||
@@ -390,13 +390,13 @@ func (h *TenantMemberHandler) LeaveTenant(c *gin.Context) {
|
||||
if err := h.memberService.RemoveMember(ctx, caller, tenantID); err != nil {
|
||||
switch {
|
||||
case errors.Is(err, service.ErrMembershipNotFound):
|
||||
c.Error(apperrors.NewNotFoundError("you are not a member of this tenant"))
|
||||
c.Error(apperrors.NewNotFoundError("you are not a member of this workspace"))
|
||||
case errors.Is(err, service.ErrLastOwner):
|
||||
c.Error(apperrors.NewConflictError(err.Error()))
|
||||
default:
|
||||
logger.Errorf(ctx, "LeaveTenant failed: user=%s tenant=%d err=%v",
|
||||
caller, tenantID, err)
|
||||
c.Error(apperrors.NewInternalServerError("failed to leave tenant").WithDetails(err.Error()))
|
||||
c.Error(apperrors.NewInternalServerError("failed to leave workspace").WithDetails(err.Error()))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ func favoriteContext(c *gin.Context) (string, uint64, bool) {
|
||||
}
|
||||
tenantID := c.GetUint64(types.TenantIDContextKey.String())
|
||||
if tenantID == 0 {
|
||||
c.Error(apperrors.NewUnauthorizedError("tenant ID not found"))
|
||||
c.Error(apperrors.NewUnauthorizedError("workspace ID not found"))
|
||||
return "", 0, false
|
||||
}
|
||||
return userID, tenantID, true
|
||||
@@ -52,7 +52,7 @@ func favoriteContext(c *gin.Context) (string, uint64, bool) {
|
||||
|
||||
// ListFavorites godoc
|
||||
// @Summary List my favorites
|
||||
// @Description Lists this user's starred resources in the current tenant for a given type
|
||||
// @Description Lists this user's starred resources in the current workspace for a given type
|
||||
// @Tags User
|
||||
// @Param type query string true "Resource type (kb | agent)"
|
||||
// @Success 200 {object} map[string]interface{}
|
||||
|
||||
@@ -79,7 +79,7 @@ func envStoreReadonlyError() gin.H {
|
||||
|
||||
// CreateStore godoc
|
||||
// @Summary Create vector store
|
||||
// @Description Create a new vector store configuration for the current tenant
|
||||
// @Description Create a new vector store configuration for the current workspace
|
||||
// @Tags VectorStore
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
@@ -96,7 +96,7 @@ func (h *VectorStoreHandler) CreateStore(c *gin.Context) {
|
||||
|
||||
tenantID := h.getTenantID(c)
|
||||
if tenantID == 0 {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"success": false, "error": "unauthorized: tenant context missing"})
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"success": false, "error": "unauthorized: workspace context missing"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ func (h *VectorStoreHandler) CreateStore(c *gin.Context) {
|
||||
|
||||
// ListStores godoc
|
||||
// @Summary List vector stores
|
||||
// @Description List all vector stores for the current tenant, including environment-configured and user-created stores
|
||||
// @Description List all vector stores for the current workspace, including environment-configured and user-created stores
|
||||
// @Tags VectorStore
|
||||
// @Produce json
|
||||
// @Success 200 {object} map[string]interface{} "List of vector stores (env + DB)"
|
||||
@@ -142,7 +142,7 @@ func (h *VectorStoreHandler) ListStores(c *gin.Context) {
|
||||
|
||||
tenantID := h.getTenantID(c)
|
||||
if tenantID == 0 {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"success": false, "error": "unauthorized: tenant context missing"})
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"success": false, "error": "unauthorized: workspace context missing"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ func (h *VectorStoreHandler) GetStore(c *gin.Context) {
|
||||
|
||||
tenantID := h.getTenantID(c)
|
||||
if tenantID == 0 {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"success": false, "error": "unauthorized: tenant context missing"})
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"success": false, "error": "unauthorized: workspace context missing"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -242,7 +242,7 @@ func (h *VectorStoreHandler) UpdateStore(c *gin.Context) {
|
||||
|
||||
tenantID := h.getTenantID(c)
|
||||
if tenantID == 0 {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"success": false, "error": "unauthorized: tenant context missing"})
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"success": false, "error": "unauthorized: workspace context missing"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -311,7 +311,7 @@ func (h *VectorStoreHandler) DeleteStore(c *gin.Context) {
|
||||
|
||||
tenantID := h.getTenantID(c)
|
||||
if tenantID == 0 {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"success": false, "error": "unauthorized: tenant context missing"})
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"success": false, "error": "unauthorized: workspace context missing"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -369,7 +369,7 @@ func (h *VectorStoreHandler) TestStoreByID(c *gin.Context) {
|
||||
|
||||
tenantID := h.getTenantID(c)
|
||||
if tenantID == 0 {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"success": false, "error": "unauthorized: tenant context missing"})
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"success": false, "error": "unauthorized: workspace context missing"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -434,7 +434,7 @@ func (h *VectorStoreHandler) TestStoreRaw(c *gin.Context) {
|
||||
|
||||
tenantID := h.getTenantID(c)
|
||||
if tenantID == 0 {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"success": false, "error": "unauthorized: tenant context missing"})
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"success": false, "error": "unauthorized: workspace context missing"})
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ func (h *WebSearchProviderHandler) CreateProvider(c *gin.Context) {
|
||||
|
||||
tenantID := h.getTenantID(c)
|
||||
if tenantID == 0 {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"success": false, "error": "unauthorized: tenant context missing"})
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"success": false, "error": "unauthorized: workspace context missing"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ func (h *WebSearchProviderHandler) ListProviders(c *gin.Context) {
|
||||
|
||||
tenantID := h.getTenantID(c)
|
||||
if tenantID == 0 {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"success": false, "error": "unauthorized: tenant context missing"})
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"success": false, "error": "unauthorized: workspace context missing"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ func (h *WebSearchProviderHandler) GetProvider(c *gin.Context) {
|
||||
|
||||
tenantID := h.getTenantID(c)
|
||||
if tenantID == 0 {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"success": false, "error": "unauthorized: tenant context missing"})
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"success": false, "error": "unauthorized: workspace context missing"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -194,7 +194,7 @@ func (h *WebSearchProviderHandler) UpdateProvider(c *gin.Context) {
|
||||
|
||||
tenantID := h.getTenantID(c)
|
||||
if tenantID == 0 {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"success": false, "error": "unauthorized: tenant context missing"})
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"success": false, "error": "unauthorized: workspace context missing"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -287,7 +287,7 @@ func (h *WebSearchProviderHandler) DeleteProvider(c *gin.Context) {
|
||||
|
||||
tenantID := h.getTenantID(c)
|
||||
if tenantID == 0 {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"success": false, "error": "unauthorized: tenant context missing"})
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"success": false, "error": "unauthorized: workspace context missing"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -344,7 +344,7 @@ func (h *WebSearchProviderHandler) TestProviderByID(c *gin.Context) {
|
||||
|
||||
tenantID := h.getTenantID(c)
|
||||
if tenantID == 0 {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"success": false, "error": "unauthorized: tenant context missing"})
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"success": false, "error": "unauthorized: workspace context missing"})
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ func (h *WebSearchProviderCredentialsHandler) Put(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
tenantID := h.tenantID(c)
|
||||
if tenantID == 0 {
|
||||
c.Error(errors.NewBadRequestError("Tenant ID cannot be empty"))
|
||||
c.Error(errors.NewBadRequestError("Workspace ID cannot be empty"))
|
||||
return
|
||||
}
|
||||
id := c.Param("id")
|
||||
@@ -83,7 +83,7 @@ func (h *WebSearchProviderCredentialsHandler) DeleteField(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
tenantID := h.tenantID(c)
|
||||
if tenantID == 0 {
|
||||
c.Error(errors.NewBadRequestError("Tenant ID cannot be empty"))
|
||||
c.Error(errors.NewBadRequestError("Workspace ID cannot be empty"))
|
||||
return
|
||||
}
|
||||
id := c.Param("id")
|
||||
|
||||
@@ -23,11 +23,11 @@ type weKnoraCloudCredentialsRequest struct {
|
||||
}
|
||||
|
||||
// SaveCredentials POST /api/v1/weknoracloud/credentials
|
||||
// 仅保存 APPID/APPSECRET 凭证到租户配置,不自动创建模型
|
||||
// 仅保存 APPID/APPSECRET 凭证到空间配置,不自动创建模型
|
||||
//
|
||||
// SaveCredentials godoc
|
||||
// @Summary 保存 WeKnoraCloud 凭证
|
||||
// @Description 保存 APPID/APPSECRET 到当前租户配置(不自动创建模型)
|
||||
// @Description 保存 APPID/APPSECRET 到当前空间配置(不自动创建模型)
|
||||
// @Tags WeKnoraCloud
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
@@ -53,11 +53,11 @@ func (h *WeKnoraCloudHandler) SaveCredentials(c *gin.Context) {
|
||||
}
|
||||
|
||||
// Status GET /api/v1/models/weknoracloud/status
|
||||
// 检查当前租户的 WeKnoraCloud 凭证是否完好,如需重新初始化则返回 needs_reinit=true
|
||||
// 检查当前空间的 WeKnoraCloud 凭证是否完好,如需重新初始化则返回 needs_reinit=true
|
||||
//
|
||||
// Status godoc
|
||||
// @Summary 检查 WeKnoraCloud 凭证状态
|
||||
// @Description 检查当前租户的 WeKnoraCloud 凭证是否完好;needs_reinit=true 表示需要重新保存
|
||||
// @Description 检查当前空间的 WeKnoraCloud 凭证是否完好;needs_reinit=true 表示需要重新保存
|
||||
// @Tags WeKnoraCloud
|
||||
// @Produce json
|
||||
// @Success 200 {object} map[string]interface{} "凭证状态"
|
||||
|
||||
Reference in New Issue
Block a user