Extract Grammaratur, Dregarnuhr, Geduldh, Mestionora, Ordoschnellic, Schutzaria, Kunstzeal and Seheweit behind compatible application contracts. Include accumulated editor resilience, navigation and theme UX, remote CLI, storage/schema and DR groundwork, tests and design/operations documentation. Verified: uncached full Go suite; go vet ./...; race tests for all eight components; 11 targeted Chromium tests; Node suites; 19 Python CLI tests; reproducible editor build. No push, release tag or deployment in this checkpoint.
127 lines
3.9 KiB
Go
127 lines
3.9 KiB
Go
package server
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"pageswiki/internal/store"
|
|
)
|
|
|
|
// City locality metadata requires read permission on its boundary; Page edges
|
|
// have their own checks. Never expose a hidden Page via a portal, count, nearby
|
|
// relation or editable destination list even when its Spot is visible.
|
|
func filterCityProjection(city store.CityMap, allowed func(string) bool) store.CityMap {
|
|
result := store.CityMap{DomainUUID: city.DomainUUID, Version: city.Version, Quartiers: []store.CityQuartier{}, Relations: []store.CitySpotRelation{}}
|
|
visible := map[string]bool{}
|
|
for _, quartier := range city.Quartiers {
|
|
if !allowed(quartier.PathPrefix) {
|
|
continue
|
|
}
|
|
quartier.DetailHref = cityDetailHref("quartier", quartier.Name, "", quartier.UUID)
|
|
streets := []store.CityStreet{}
|
|
for _, street := range quartier.Streets {
|
|
if !allowed(street.PathPrefix) {
|
|
continue
|
|
}
|
|
street.DetailHref = cityDetailHref("street", street.Name, quartier.Name, street.UUID)
|
|
spots := []store.CitySpot{}
|
|
for _, spot := range street.Spots {
|
|
if !allowed(spot.PathPrefix) {
|
|
continue
|
|
}
|
|
spot.DetailHref = cityDetailHref("spot", spot.Name, quartier.Name, spot.UUID)
|
|
parentTitle := street.Title
|
|
if parentTitle == "" {
|
|
parentTitle = street.Name
|
|
}
|
|
spot.DisplayTitle = store.CitySpotDisplayTitle(spot.Name, spot.Title, spot.PathPrefix, parentTitle)
|
|
pages := []store.CityPagePlacement{}
|
|
unique := map[string]bool{}
|
|
spot.PortalPath, spot.PortalPageUUID = "", ""
|
|
portalPriority := -1
|
|
for _, page := range spot.Pages {
|
|
if page.Path == "" || !allowed(page.Path) {
|
|
continue
|
|
}
|
|
pages = append(pages, page)
|
|
unique[page.PageUUID] = true
|
|
priority := 0
|
|
if page.EdgeType == "primary" {
|
|
priority = 1
|
|
}
|
|
if page.Path == spot.PathPrefix {
|
|
priority = 2
|
|
}
|
|
if priority > portalPriority {
|
|
spot.PortalPath, spot.PortalPageUUID = page.Path, page.PageUUID
|
|
portalPriority = priority
|
|
}
|
|
}
|
|
spot.Pages, spot.PageCount = pages, len(unique)
|
|
visible[spot.UUID] = true
|
|
spots = append(spots, spot)
|
|
}
|
|
street.Spots = spots
|
|
streets = append(streets, street)
|
|
}
|
|
quartier.Streets = streets
|
|
result.Quartiers = append(result.Quartiers, quartier)
|
|
}
|
|
for _, relation := range city.Relations {
|
|
if visible[relation.SourceSpotUUID] && visible[relation.TargetSpotUUID] {
|
|
result.Relations = append(result.Relations, relation)
|
|
}
|
|
}
|
|
return result
|
|
}
|
|
|
|
func (s *Server) cityProjectionForRequest(r *http.Request) (store.CityMap, error) {
|
|
city, err := s.navigationCity(r.Context(), s.domainUUIDForRequest(r))
|
|
if err != nil {
|
|
return city, err
|
|
}
|
|
return filterCityProjection(city, s.pathReadFilter(r)), nil
|
|
}
|
|
|
|
func (s *Server) spotPagesForRequest(r *http.Request, spotUUID string) ([]store.CityPagePlacement, error) {
|
|
domain := s.domainUUIDForRequest(r)
|
|
spot, err := s.store.CityNodeContext(r.Context(), domain, "spot", "uuid:"+spotUUID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if !canReadCityNode(spot, s.pathReadFilter(r)) {
|
|
return nil, store.ErrAccessDenied
|
|
}
|
|
pages, err := s.store.ListSpotPagesContext(r.Context(), domain, spotUUID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out := []store.CityPagePlacement{}
|
|
allowed := s.pathReadFilter(r)
|
|
for _, page := range pages {
|
|
if page.Path != "" && allowed(page.Path) {
|
|
out = append(out, page)
|
|
}
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
func privateCityResponse(w http.ResponseWriter) {
|
|
w.Header().Set("Cache-Control", "private, no-store")
|
|
w.Header().Add("Vary", "Cookie, Authorization")
|
|
}
|
|
|
|
func (s *Server) pageSpotAppearancesForRequest(r *http.Request, objectUUID string) ([]store.CitySpotAppearance, error) {
|
|
spots, err := s.store.ListPageSpotAppearances(s.domainUUIDForRequest(r), objectUUID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out := []store.CitySpotAppearance{}
|
|
allowed := s.pathReadFilter(r)
|
|
for _, spot := range spots {
|
|
if allowed(spot.PathPrefix) && allowed(spot.StreetPath) && allowed(spot.QuartierPath) {
|
|
out = append(out, spot)
|
|
}
|
|
}
|
|
return out, nil
|
|
}
|