package server import ( "encoding/json" "net/http" "strings" "pageswiki/internal/store" ) func (s *Server) handleDeleteObjectAPI( w http.ResponseWriter, r *http.Request, ) { if !requirePathMutationPost(w, r) { return } var req struct { ObjectUUID string `json:"object_uuid"` } r.Body = http.MaxBytesReader(w, r.Body, 4096) err := json.NewDecoder( r.Body, ).Decode(&req) if err != nil { http.Error(w, err.Error(), 400) return } req.ObjectUUID = strings.TrimSpace(req.ObjectUUID) if req.ObjectUUID == "" { http.Error(w, "object_uuid is required", 400) return } domainUUID := s.domainUUIDForRequest(r) mode, err := s.store.GetConfigInDomain(domainUUID, "authorization_mode") if err != nil { writePathMutationError(w, err) return } var principal *store.Principal if mode == "enforcing" { principal, err = s.store.PrincipalForSession(domainUUID, s.authTokenFromRequest(r)) if err != nil { http.Error(w, "forbidden", http.StatusForbidden) return } } snapshot, err := s.store.SnapshotObjectDeletionInDomain(domainUUID, req.ObjectUUID) if err != nil { writePathMutationError(w, err) return } if principal != nil { for _, path := range snapshot.Paths() { if s.authorizePrincipalPath(domainUUID, principal.UUID, "delete", path) != nil { http.Error(w, "forbidden", http.StatusForbidden) return } } } if err := s.store.DeleteObjectInDomainChecked(domainUUID, req.ObjectUUID, snapshot); err != nil { writePathMutationError(w, err) return } w.WriteHeader(http.StatusNoContent) }