test / test (push) Canceled after 0s
- handlers/authz.go: domainIDSet removed, nothing called it (U1000). - handlers_outbound_pages_test.go: two refusals whose status code was assigned and never read (SA4006) now check it is 400 - a custom DMARC report mode without an address, export passwords that differ. - view/pages_test.go: !strings.Contains for a missing box (S1003). - Audit plan line ticked, roadmap 6/61. No CHANGELOG line: nothing an operator sees changes. staticcheck ./... clean afterwards. Evidence on the test server: see the previous commit (same tree run). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
60 lines
1.7 KiB
Go
60 lines
1.7 KiB
Go
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/mixeme/selfpost/internal/dmarc"
|
|
"github.com/mixeme/selfpost/internal/store"
|
|
"github.com/mixeme/selfpost/internal/web/auth"
|
|
"github.com/mixeme/selfpost/internal/web/view"
|
|
)
|
|
|
|
func (h *Handlers) principal(r *http.Request) (auth.Principal, bool) {
|
|
return auth.PrincipalFromRequest(r)
|
|
}
|
|
|
|
func (h *Handlers) requireGlobal(w http.ResponseWriter, r *http.Request) (auth.Principal, bool) {
|
|
p, ok := h.principal(r)
|
|
if !ok || !p.IsGlobal() {
|
|
http.NotFound(w, r)
|
|
return auth.Principal{}, false
|
|
}
|
|
return p, true
|
|
}
|
|
|
|
// shellMeta is what the shell of a page of the component kit needs to know
|
|
// about the person looking at it: their name and which groups of the menu they
|
|
// reach. The page's constructor adds its title and where it sits in the menu.
|
|
func (h *Handlers) shellMeta(r *http.Request) view.Meta {
|
|
p, _ := h.principal(r)
|
|
user := auth.CurrentUser(r)
|
|
if user == "" {
|
|
user = p.Username
|
|
}
|
|
return view.Meta{User: user, IsGlobal: p.IsGlobal(), HasOutbound: p.HasOutbound(), HasInbound: p.HasInbound()}
|
|
}
|
|
|
|
func (h *Handlers) assignedDomains(p auth.Principal) ([]store.Domain, error) {
|
|
if p.IsGlobal() {
|
|
return h.store.ListDomains()
|
|
}
|
|
return h.store.ListDomainsForUser(p.ID)
|
|
}
|
|
|
|
// hostedDMARCAddress is the SelfPost-hosted report mailbox for a sending
|
|
// domain, "" when report ingest is off on this server.
|
|
func (h *Handlers) hostedDMARCAddress(domainName string) string {
|
|
if h.dmarc == nil || !h.cfg.DMARCEnabled {
|
|
return ""
|
|
}
|
|
return dmarc.HostedReportAddress(h.cfg.Hostname, domainName)
|
|
}
|
|
|
|
func domainNameSet(domains []store.Domain) map[string]bool {
|
|
m := make(map[string]bool, len(domains))
|
|
for _, d := range domains {
|
|
m[d.Name] = true
|
|
}
|
|
return m
|
|
}
|