Phase 10, part 5: access enforced on every page, form and fragment
One table maps every address to an area (a module, Settings, anything signed in, or public); each route is checked against it, and the app won't start with a route missing from it. Changing needs edit on the module. For members who may only view, forms that would change something are shown disabled and htmx buttons hidden. The menu, the Overview, Search and the SEO emails follow each person's modules; Settings is for admins. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
@@ -565,3 +566,47 @@ func (s *Server) inviteAccept(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
redirect(w, r, "/", "joined")
|
||||
}
|
||||
|
||||
// mailTeam sends one of the emails people choose (emailKinds) to each
|
||||
// active person who chose it and may still see its module.
|
||||
func (s *Server) mailTeam(ctx context.Context, kind, subject, body string) int {
|
||||
var ek emailKind
|
||||
for _, k := range emailKinds {
|
||||
if k.ID == kind {
|
||||
ek = k
|
||||
}
|
||||
}
|
||||
list, err := users.Members(s.DB, users.Team)
|
||||
if err != nil {
|
||||
s.Log.Warn("mail: listing who gets "+kind, "err", err)
|
||||
return 0
|
||||
}
|
||||
if s.Mail == nil {
|
||||
return 0
|
||||
}
|
||||
sent := 0
|
||||
for _, m := range list {
|
||||
if m.Status != users.Active || m.Kind != users.Person || !m.Can(ek.Module, false) || !has(m.Emails, kind) {
|
||||
continue
|
||||
}
|
||||
mctx, cancel := context.WithTimeout(ctx, 2*time.Minute)
|
||||
err := s.Mail.Send(mctx, appmail.Message{To: m.Email, ToName: m.Name, Subject: subject,
|
||||
Body: body + "\n\n-- \nYou get this because you asked for " + strings.ToLower(ek.Name[:1]) + ek.Name[1:] + ". To stop, untick it under Settings → Your account: " + s.PublicURL + "/settings/account\n"})
|
||||
cancel()
|
||||
if err != nil {
|
||||
s.Log.Warn("mail: not sent", "kind", kind, "to", m.Email, "err", err)
|
||||
continue
|
||||
}
|
||||
sent++
|
||||
}
|
||||
return sent
|
||||
}
|
||||
|
||||
func has(list []string, v string) bool {
|
||||
for _, x := range list {
|
||||
if x == v {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user