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:
@@ -58,7 +58,7 @@ func (s *Server) searchPage(w http.ResponseWriter, r *http.Request) {
|
||||
total := 0
|
||||
if q != "" {
|
||||
var err error
|
||||
groups, err = s.search(q)
|
||||
groups, err = s.search(q, viewerOf(r))
|
||||
if err != nil {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
@@ -77,7 +77,7 @@ func (s *Server) searchPage(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// search looks for q in the inventory, fetched items, posts and settings.
|
||||
// Every word must appear (case-insensitively), in any order.
|
||||
func (s *Server) search(q string) ([]hitGroup, error) {
|
||||
func (s *Server) search(q string, v *viewer) ([]hitGroup, error) {
|
||||
words := strings.Fields(strings.ToLower(q))
|
||||
matches := func(texts ...string) bool {
|
||||
all := strings.ToLower(strings.Join(texts, "\n"))
|
||||
@@ -202,8 +202,9 @@ func (s *Server) search(q string) ([]hitGroup, error) {
|
||||
}
|
||||
|
||||
var groups []hitGroup
|
||||
area := map[string]string{"Posts": "content", "Fetched items": "content", "Market": "market", "Prospects": "prospects", "Settings": areaAdmin}
|
||||
for _, g := range []hitGroup{{"Posts", posts}, {"Fetched items", found}, {"Market", inv}, {"Prospects", prospectHits}, {"Settings", settings}} {
|
||||
if len(g.Hits) > 0 {
|
||||
if len(g.Hits) > 0 && v.can(area[g.Name], false) {
|
||||
groups = append(groups, g)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user