Files
Agent-System/internal/server/software_project_handlers.go
weichenandCursor f6034fad37 feat(api): SWBOOT-05..08 wizard hooks and SWBOOT-10 allowlist stub
Add project-types/compliance catalogs, creation-preview, software create
fields, and fail-closed repo allowlist stub without real patch/merge.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-16 15:43:13 +00:00

61 lines
1.9 KiB
Go

package server
import (
"encoding/json"
"net/http"
"time"
"chat-agent-system/internal/swboot"
)
// handleProjectTypesCatalog GET /api/v1/project-types/catalog
func (s *Server) handleProjectTypesCatalog(w http.ResponseWriter, r *http.Request) {
if _, ok := s.requirePrincipal(w, r); !ok {
return
}
writeJSONResponse(w, http.StatusOK, map[string]any{
"project_types": swboot.ProjectTypesCatalog(),
})
}
// handleComplianceProfilesCatalog GET /api/v1/compliance-profiles/catalog
func (s *Server) handleComplianceProfilesCatalog(w http.ResponseWriter, r *http.Request) {
if _, ok := s.requirePrincipal(w, r); !ok {
return
}
writeJSONResponse(w, http.StatusOK, map[string]any{
"compliance_profiles": swboot.ComplianceProfilesCatalog(),
})
}
// handleProjectCreationPreview POST /api/v1/projects/creation-preview
func (s *Server) handleProjectCreationPreview(w http.ResponseWriter, r *http.Request) {
user, err := s.authenticateUser(r)
if err != nil || user == nil {
writeSafeError(w, r, http.StatusUnauthorized, `{"error":"ERR_UNAUTHENTICATED","message":"请先登录"}`)
return
}
if ok, permErr := s.userHasSystemPermission(r.Context(), user, "project:create"); permErr != nil {
writeSafeError(w, r, http.StatusInternalServerError, `{"error":"ERR_INTERNAL","message":"`+permErr.Error()+`"}`)
return
} else if !ok {
writeJSONResponse(w, http.StatusForbidden, map[string]string{
"error_code": "ERR_FORBIDDEN",
"message": "无权创建项目",
})
return
}
var req swboot.CreationPreviewInput
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
writeSafeError(w, r, http.StatusBadRequest, `{"error":"ERR_INVALID_PARAM","message":"无效的 JSON 请求体"}`)
return
}
res := swboot.BuildCreationPreview(req, time.Now().UTC())
status := http.StatusOK
if !res.Valid {
status = http.StatusBadRequest
}
writeJSONResponse(w, status, res)
}