CI / Web-Barrierefreiheitspruefung (axe, Tastatur, Reflow, Textabstaende) (pull_request) Canceled after 0s
CI / Web-Barrierefreiheitspruefung (axe, Tastatur, Reflow, Textabstaende) (push) Canceled after 0s
CI / Core-Modul (Build/Vet/Test) (pull_request) Canceled after 0s
CI / DMS Security-Test-Gate (AC5, Merge-Gate) (pull_request) Canceled after 0s
CI / Core-Modul (Build/Vet/Test) (push) Canceled after 0s
CI / DMS Security-Test-Gate (AC5, Merge-Gate) (push) Canceled after 0s
CI / DMS-Modul Supply-Chain-Scan (govulncheck) (push) Canceled after 0s
CI / Web (dms-browser) (push) Canceled after 0s
CI / Web (pdf-viewer) (push) Canceled after 0s
CI / Web (shl) (push) Canceled after 0s
Supply-Chain-Scan (Go) / govulncheck (push) Canceled after 0s
CI / DMS-Modul Supply-Chain-Scan (govulncheck) (pull_request) Canceled after 0s
CI / Web (dms-browser) (pull_request) Canceled after 0s
CI / Web (pdf-viewer) (pull_request) Canceled after 0s
CI / Web (shl) (pull_request) Canceled after 0s
Core-Schnittstellen-Vertragstests / contract-tests (pull_request) Canceled after 0s
Supply-Chain-Scan (Go) / govulncheck (pull_request) Canceled after 0s
Supply-Chain-Scan (npm) / npm-audit (pull_request) Canceled after 0s
Core-Pflichttest-Gate / pflichttest-gate (pull_request) Canceled after 0s
RBAC-Rollenhierarchie-Pflichtgate / rbac-policy-invariant (pull_request) Canceled after 0s
CI / DMS-Modul (Lint/Build/Test/Coverage/Artefakt) (push) Canceled after 0s
CI / DMS-Modul (Lint/Build/Test/Coverage/Artefakt) (pull_request) Canceled after 0s
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
67 lines
2.0 KiB
Go
67 lines
2.0 KiB
Go
// Package backchannelapi ist die HTTP-Bindung der Rueckkanal-API
|
|
// (VOR-04). Nutzeridentitaet kommt uebergangsweise aus X-User-Id, wie
|
|
// bereits bei caseapi (VOR-01) und approvalapi (APR-01) etabliert.
|
|
// X-Tenant-Slug traegt den Tenant-Kontext des urspruenglich anfragenden
|
|
// Nutzers (VOR-06) -- unabhaengig vom Geltungsbereich des Service-
|
|
// Credentials, mit dem DMS/Mail selbst gegenueber Workflow authentifiziert
|
|
// sind.
|
|
package backchannelapi
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"net/http"
|
|
|
|
"gitea.perlbach24.de/scripte/nexarch/workflow/internal/backchannel"
|
|
)
|
|
|
|
type Server struct {
|
|
svc *backchannel.Service
|
|
}
|
|
|
|
func NewServer(svc *backchannel.Service) *Server {
|
|
return &Server{svc: svc}
|
|
}
|
|
|
|
// RegisterRoutes bindet GET /objects/{module}/{type}/{id}/context.
|
|
func (s *Server) RegisterRoutes(mux *http.ServeMux) {
|
|
mux.HandleFunc("GET /objects/{module}/{objectType}/{id}/context", s.handleContext)
|
|
}
|
|
|
|
func (s *Server) handleContext(w http.ResponseWriter, r *http.Request) {
|
|
userID := r.Header.Get("X-User-Id")
|
|
if userID == "" {
|
|
writeError(w, http.StatusUnauthorized, "X-User-Id fehlt")
|
|
return
|
|
}
|
|
tenantSlug := r.Header.Get("X-Tenant-Slug")
|
|
if tenantSlug == "" {
|
|
writeError(w, http.StatusUnauthorized, "X-Tenant-Slug fehlt")
|
|
return
|
|
}
|
|
|
|
moduleName := r.PathValue("module")
|
|
objectType := r.PathValue("objectType")
|
|
id := r.PathValue("id")
|
|
|
|
ctxResult, err := s.svc.ForObject(r.Context(), moduleName, objectType, id, userID, tenantSlug)
|
|
switch {
|
|
case err == nil:
|
|
writeJSON(w, http.StatusOK, ctxResult)
|
|
case errors.Is(err, backchannel.ErrForbidden):
|
|
writeError(w, http.StatusForbidden, "nicht berechtigt")
|
|
default:
|
|
writeError(w, http.StatusInternalServerError, "kontext konnte nicht gelesen werden")
|
|
}
|
|
}
|
|
|
|
func writeJSON(w http.ResponseWriter, status int, v any) {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(status)
|
|
_ = json.NewEncoder(w).Encode(v)
|
|
}
|
|
|
|
func writeError(w http.ResponseWriter, status int, message string) {
|
|
writeJSON(w, status, map[string]string{"error": message})
|
|
}
|