// SPDX-License-Identifier: Apache-2.0 package server import ( "crypto/x509" "fmt" "net" "net/http" "strconv" "strings" "sync" "time" "github.com/X4Applegate/caddyui/internal/models" "github.com/go-chi/chi/v5" ) // --- Certificates --- // adminUserList returns the full user list for admins (used by the admin-only // Owner pickers on new/edit forms so an admin can provision a resource for a // specific customer). Returns an empty slice for non-admin viewers so we // don't waste a DB round-trip and so a template leak can't surface email // addresses to non-admins. v2.7.3. // groupPeerIDs returns the other user IDs that share at least one group with // the viewer. Used to expand a non-admin viewer's visibility scope in every // List* call: viewer sees their own rows + globals + any row owned by a peer. // Admins skip this path entirely — their List* branch is unfiltered — so we // return nil immediately for admin/view and for signed-out requests. DB // errors are swallowed to nil so a transient groups-table hiccup degrades to // "no group visibility" rather than breaking the whole list page. func (s *Server) groupPeerIDs(r *http.Request) []int64 { cu := s.currentUser(r) if cu == nil || cu.Role != models.RoleUser { return nil } ids, err := models.GroupPeerIDs(s.DB, cu.ID) if err != nil { return nil } return ids } // adminUserList returns the user-role accounts an admin can assign resources // to. Only admins see anything — nil for non-admin viewers so their templates // can't accidentally leak the user roster via the Owner