chore: 初始化仓库,导入项目基线代码
Academy v0.8.3 完整代码基线:Go 后端(internal/cmd/cli/mcp-server/docreader)、 Vue 前端(frontend)、数据库迁移(migrations)、部署编排(docker/helm/deploy)与文档。 今日开发的培训推送管理改动随后单独提交。
This commit is contained in:
commit
7ec21f35b0
5767 files changed
+1436788
No files matched your search
@@ -0,0 +1,93 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"academy/internal/types"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// TenantResponse is the viewer-safe tenant profile shape. Secret-bearing
|
||||
// columns are omitted or redacted unless the caller has Admin+.
|
||||
type TenantResponse struct {
|
||||
ID uint64 `json:"id" extensions:"x-agent=workspace_id"`
|
||||
Name string `json:"name" extensions:"x-agent"`
|
||||
Description string `json:"description" extensions:"x-agent"`
|
||||
Status string `json:"status" extensions:"x-agent"`
|
||||
RetrieverEngines types.RetrieverEngines `json:"retriever_engines"`
|
||||
Business string `json:"business"`
|
||||
StorageQuota int64 `json:"storage_quota" extensions:"x-agent"`
|
||||
StorageUsed int64 `json:"storage_used" extensions:"x-agent"`
|
||||
ContextConfig *types.ContextConfig `json:"context_config,omitempty"`
|
||||
WebSearchConfig *types.WebSearchConfig `json:"web_search_config,omitempty"`
|
||||
ParserEngineConfig *types.ParserEngineConfig `json:"parser_engine_config,omitempty"`
|
||||
Credentials *types.CredentialsConfig `json:"credentials,omitempty"`
|
||||
StorageEngineConfig *types.StorageEngineConfig `json:"storage_engine_config,omitempty"`
|
||||
ChatHistoryConfig *types.ChatHistoryConfig `json:"chat_history_config,omitempty"`
|
||||
RetrievalConfig *types.RetrievalConfig `json:"retrieval_config,omitempty"`
|
||||
MemoryConfig *types.MemoryConfig `json:"memory_config,omitempty"`
|
||||
AssistantConfig *types.AssistantConfig `json:"assistant_config,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at" extensions:"x-agent"`
|
||||
UpdatedAt time.Time `json:"updated_at" extensions:"x-agent"`
|
||||
DeletedAt gorm.DeletedAt `json:"deleted_at"`
|
||||
}
|
||||
|
||||
// NewTenantResponse converts a stored tenant into its HTTP response shape.
|
||||
func NewTenantResponse(ctx context.Context, tenant *types.Tenant) *TenantResponse {
|
||||
return NewTenantResponseWithRole(tenant, RoleFromContext(ctx))
|
||||
}
|
||||
|
||||
// NewTenantResponseWithRole converts a stored tenant using an explicit role
|
||||
// (for auth flows where tenant role is not yet in request context).
|
||||
func NewTenantResponseWithRole(tenant *types.Tenant, role types.TenantRole) *TenantResponse {
|
||||
if tenant == nil {
|
||||
return nil
|
||||
}
|
||||
includeSecrets := role.HasPermission(types.TenantRoleAdmin)
|
||||
resp := &TenantResponse{
|
||||
ID: tenant.ID,
|
||||
Name: tenant.Name,
|
||||
Description: tenant.Description,
|
||||
Status: tenant.Status,
|
||||
RetrieverEngines: tenant.RetrieverEngines,
|
||||
Business: tenant.Business,
|
||||
StorageQuota: tenant.StorageQuota,
|
||||
StorageUsed: tenant.StorageUsed,
|
||||
ContextConfig: tenant.ContextConfig,
|
||||
ChatHistoryConfig: tenant.ChatHistoryConfig,
|
||||
RetrievalConfig: tenant.RetrievalConfig,
|
||||
MemoryConfig: tenant.MemoryConfig,
|
||||
AssistantConfig: tenant.AssistantConfig,
|
||||
CreatedAt: tenant.CreatedAt,
|
||||
UpdatedAt: tenant.UpdatedAt,
|
||||
DeletedAt: tenant.DeletedAt,
|
||||
}
|
||||
if includeSecrets {
|
||||
resp.WebSearchConfig = types.WebSearchConfigForResponse(tenant.WebSearchConfig, true)
|
||||
resp.ParserEngineConfig = types.ParserEngineConfigForResponse(tenant.ParserEngineConfig, true)
|
||||
resp.Credentials = types.CredentialsConfigForResponse(tenant.Credentials, true)
|
||||
resp.StorageEngineConfig = types.StorageEngineConfigForResponse(tenant.StorageEngineConfig, true)
|
||||
}
|
||||
return resp
|
||||
}
|
||||
|
||||
// NewTenantResponses is the slice convenience wrapper.
|
||||
func NewTenantResponses(ctx context.Context, tenants []*types.Tenant) []*TenantResponse {
|
||||
out := make([]*TenantResponse, 0, len(tenants))
|
||||
for _, t := range tenants {
|
||||
out = append(out, NewTenantResponse(ctx, t))
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// NewTenantResponsesCrossTenant redacts every tenant as Viewer regardless of
|
||||
// the caller's active-tenant role. Used by cross-tenant list/search endpoints
|
||||
// where the caller's home-tenant role must not unlock other tenants' secrets.
|
||||
func NewTenantResponsesCrossTenant(tenants []*types.Tenant) []*TenantResponse {
|
||||
out := make([]*TenantResponse, 0, len(tenants))
|
||||
for _, t := range tenants {
|
||||
out = append(out, NewTenantResponseWithRole(t, types.TenantRoleViewer))
|
||||
}
|
||||
return out
|
||||
}
|
||||
Reference in new issue
Block a user