This commit is contained in:
David Schroeder
2026-07-25 14:55:41 -05:00
parent cd61add56f
commit d5faf998f4
4 changed files with 61 additions and 10 deletions
+12 -8
View File
@@ -110,14 +110,7 @@ func New(cfg Config) (*Server, error) {
return nil, fmt.Errorf("database: %w", err)
}
templates, err := template.New("").Funcs(template.FuncMap{
"formatTime": func(value time.Time) string {
return value.Local().Format("Jan 2, 2006 3:04 PM")
},
"isActive": func(record authorizationRecord) bool {
return !record.RevokedAt.Valid && time.Now().Before(record.ExpiresAt)
},
}).ParseFS(webFiles, "templates/*.html")
templates, err := parseTemplates()
if err != nil {
_ = db.Close()
return nil, err
@@ -154,6 +147,17 @@ func New(cfg Config) (*Server, error) {
}, nil
}
func parseTemplates() (*template.Template, error) {
return template.New("").Funcs(template.FuncMap{
"formatTime": func(value time.Time) string {
return value.Local().Format("Jan 2, 2006 3:04 PM")
},
"isActive": func(record authorizationRecord) bool {
return !record.RevokedAt.Valid && time.Now().Before(record.ExpiresAt)
},
}).ParseFS(webFiles, "templates/*.html")
}
func (s *Server) Close() error {
return s.db.Close()
}
+41
View File
@@ -0,0 +1,41 @@
package app
import (
"io"
"testing"
"time"
)
func TestPortalTemplateExecutes(t *testing.T) {
t.Parallel()
templates, err := parseTemplates()
if err != nil {
t.Fatal(err)
}
err = templates.ExecuteTemplate(io.Discard, "portal.html", pageData{
Title: "Test",
Technician: &technician{DisplayName: "Technician"},
Packages: []packageRecord{{
ID: 1,
Slug: "sentinelone-linux",
DisplayName: "SentinelOne Linux Agent",
PackageVersion: "26.1.1.31",
Enabled: true,
}},
Actions: []actionRecord{{
Slug: "install-rmm",
DisplayName: "Install RMM",
Enabled: true,
}},
Authorizations: []authorizationRecord{{
ID: 1,
CreatedBy: "taiadmin",
ExpiresAt: time.Now().Add(time.Hour),
Packages: "SentinelOne Linux Agent",
Actions: "Install RMM",
}},
})
if err != nil {
t.Fatal(err)
}
}
+4
View File
@@ -184,6 +184,10 @@ func (s *Server) streamPackageToGitea(
response, err := s.packageClient.Do(request)
if err != nil {
var maxBytesError *http.MaxBytesError
if errors.As(err, &maxBytesError) {
return "", int64(size), http.StatusRequestEntityTooLarge, maxBytesError
}
return "", int64(size), http.StatusBadGateway, errors.New("package registry upload failed")
}
defer response.Body.Close()