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:
+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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user