update gui

This commit is contained in:
2026-07-28 21:07:30 -05:00
parent f56ac6a2c4
commit 6c4ce8f6df
7 changed files with 164 additions and 6 deletions
+41
View File
@@ -787,6 +787,47 @@ func (s *Server) handleUpsertPackage(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/portal/packages?notice=Package+saved", http.StatusSeeOther)
}
func (s *Server) handleSetPackageStatus(w http.ResponseWriter, r *http.Request) {
tech, _ := s.currentTechnician(r)
slug := strings.TrimSpace(r.FormValue("slug"))
if !validSlug(slug) {
http.Error(w, "invalid package ID", http.StatusBadRequest)
return
}
enabled := r.FormValue("enabled") == "1"
result, err := s.db.ExecContext(
r.Context(),
`UPDATE packages
SET enabled = ?,
updated_at = CURRENT_TIMESTAMP
WHERE slug = ?`,
enabled, slug,
)
if err != nil {
http.Error(w, "unable to update package status", http.StatusInternalServerError)
return
}
updated, err := result.RowsAffected()
if err != nil {
http.Error(w, "unable to confirm package status", http.StatusInternalServerError)
return
}
if updated == 0 {
http.Error(w, "package not found", http.StatusNotFound)
return
}
eventType := "package_disabled"
notice := "Package+distribution+disabled"
if enabled {
eventType = "package_enabled"
notice = "Package+distribution+enabled"
}
_ = s.audit(r.Context(), eventType, tech.Login, nil, "", slug, s.clientIP(r),
fmt.Sprintf("enabled=%t", enabled))
http.Redirect(w, r, "/portal/packages?notice="+notice, http.StatusSeeOther)
}
func (s *Server) savePackage(
r *http.Request,
slug string,