This repository has been archived on 2026-04-03. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
core/server/handlers/profile_bootstrap.go
Jeffrey Smith 64890bf12f
Some checks failed
CI/CD / detect-changes (pull_request) Successful in 4s
CI/CD / test-frontend (pull_request) Failing after 5s
CI/CD / test-go-pg (pull_request) Failing after 2m37s
CI/CD / test-sqlite (pull_request) Successful in 2m51s
CI/CD / build-and-deploy (pull_request) Has been skipped
Feat v0.2.6 admin settings audit (#10)
Roadmap reorder: Extension Lifecycle moved to v0.3.x, settings audit
milestones renumbered (v0.2.7→v0.2.6, v0.2.8→v0.2.7, v0.2.9→v0.2.8).
Added v0.2.9 for builtin extension retirement — 6 chat-centric
extensions (csv-table, diff-viewer, js-sandbox, katex, mermaid, regex)
are dormant until a chat surface ships; roadmap tracks converting them
to regular packages and removing the auto-seed mechanism.

Admin settings E2E verified — all 7 sections (default surface,
registration, banner, message bar, footer, vault, email) render and
save correctly. Packages surface verified (17/17 loaded).

Dead code removed:
- sectionCategory(): AI/routing/channel cases, default→system
- PublicSettings(): system_prompt, retention_ttl, paste_to_file,
  allow_user_personas
- PolicyDefaults: allow_raw_model_access, default_model
- Profile handlers: allow_raw_model_access, kb_direct_access lookups
- Test seeds: model_roles setting, allow_raw_model_access policy
- packages.js: 'chat' from CORE_IDS

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 15:03:10 +00:00

107 lines
3.1 KiB
Go

package handlers
// profile_bootstrap.go — Single-call boot payload for the SDK.
//
// GET /api/v1/profile/bootstrap
//
// Collapses what previously required 3-4 sequential requests
// (profile, permissions, teams/mine, settings) into one call.
// The SDK calls this at startup and on token refresh.
//
// v0.37.15
import (
"net/http"
"sort"
"github.com/gin-gonic/gin"
"switchboard-core/auth"
"switchboard-core/store"
)
// ProfileBootstrapHandler serves the combined boot payload.
type ProfileBootstrapHandler struct {
stores store.Stores
}
func NewProfileBootstrapHandler(s store.Stores) *ProfileBootstrapHandler {
return &ProfileBootstrapHandler{stores: s}
}
// GetBootstrap returns everything the shell needs at startup.
// GET /api/v1/profile/bootstrap
func (h *ProfileBootstrapHandler) GetBootstrap(c *gin.Context) {
userID := getUserID(c)
ctx := c.Request.Context()
// ── User profile ────────────────────────
user, err := h.stores.Users.GetByID(ctx, userID)
if err != nil {
c.JSON(http.StatusNotFound, gin.H{"error": "user not found"})
return
}
userPayload := gin.H{
"id": user.ID,
"username": user.Username,
"display_name": user.DisplayName,
"email": user.Email,
}
if user.AvatarURL != "" {
userPayload["avatar"] = user.AvatarURL
}
// ── Permissions ─────────────────────────
perms, err := auth.ResolvePermissions(ctx, h.stores, userID)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to resolve permissions"})
return
}
permList := make([]string, 0, len(perms))
for p := range perms {
permList = append(permList, p)
}
sort.Strings(permList)
// ── Groups ──────────────────────────────
groupIDs, _ := h.stores.Groups.GetUserGroupIDs(ctx, userID)
if groupIDs == nil {
groupIDs = []string{}
}
// ── Teams ───────────────────────────────
teams, _ := h.stores.Teams.ListForUser(ctx, userID)
teamData := make([]gin.H, 0, len(teams))
for _, t := range teams {
teamData = append(teamData, gin.H{
"id": t.ID,
"name": t.Name,
"my_role": t.MyRole,
})
}
// ── Policies ────────────────────────────
policies := make(map[string]bool)
if ps := h.stores.Policies; ps != nil {
policies["allow_user_byok"], _ = ps.GetBool(ctx, "allow_user_byok")
policies["allow_user_personas"], _ = ps.GetBool(ctx, "allow_user_personas")
}
// ── Settings ────────────────────────────
settings := make(map[string]interface{})
if user.Settings != nil {
settings = user.Settings
}
// ── Response ────────────────────────────
c.JSON(http.StatusOK, gin.H{
"user": userPayload,
"permissions": permList,
"groups": groupIDs,
"teams": teamData,
"policies": policies,
"settings": settings,
})
}