Capture accumulated application, UI, CLI, regression tests and design documentation changes, including task project mapping and default CalDAV list naming. Keep deployment data, backups, local credentials and build artifacts out of Git. Move the Compose enrollment token to an ignored local environment file.
122 lines
3.7 KiB
Go
122 lines
3.7 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)
|
|
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) {
|
|
out = append(out, spot)
|
|
}
|
|
}
|
|
return out, nil
|
|
}
|