package httpapi import ( "context" "knowledge-governance/internal/dobotaiops" "knowledge-governance/internal/qaopsquality" "net/http" "strings" ) func masterNoStore(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if strings.HasPrefix(r.URL.Path, "/api/v1/qa-ops/master/") || strings.HasPrefix(r.URL.Path, "/api/v1/qa-ops/departments/") { w.Header().Set("Cache-Control", "no-store") w.Header().Set("Pragma", "no-cache") } next.ServeHTTP(w, r) }) } // Master reads and reviews own their state; no source client is accepted as fallback. type qaMasterStore interface { ListMasterRecords(context.Context, dobotaiops.RecordQuery) (dobotaiops.RecordPage, error) GetMasterRecord(context.Context, string, string) (dobotaiops.Record, error) ReadMasterQualityScope(context.Context, dobotaiops.RecordQuery) (dobotaiops.QualityScope, error) MasterQualityStore() *qaopsquality.Store } type qaMasterReader struct { QAOpsReader master qaMasterStore } func (s qaMasterReader) ListRecords(ctx context.Context, q dobotaiops.RecordQuery) (dobotaiops.RecordPage, error) { return s.master.ListMasterRecords(ctx, q) } func (s qaMasterReader) GetRecord(ctx context.Context, tenant, id string) (dobotaiops.Record, error) { return s.master.GetMasterRecord(ctx, tenant, id) } func (s qaMasterReader) ReadQualityScope(ctx context.Context, q dobotaiops.RecordQuery) (dobotaiops.QualityScope, error) { return s.master.ReadMasterQualityScope(ctx, q) } func (s qaMasterReader) ReadStoredQuality(ctx context.Context, keys []dobotaiops.QualityKey) (map[string]qaopsquality.View, error) { if reader, ok := s.master.(interface { ReadMasterQualityViews(context.Context, []dobotaiops.QualityKey) (map[string]qaopsquality.View, error) }); ok { return reader.ReadMasterQualityViews(ctx, keys) } return s.master.MasterQualityStore().ReadViews(ctx, keys) } func withQAMaster(w http.ResponseWriter, r *http.Request, c Config, handler func(http.ResponseWriter, *http.Request, Config)) { if !authorizeQAOps(w, r) { return } master, ok := c.QAOps.(qaMasterStore) if !ok { qaOpsError(w, dobotaiops.ErrUnavailable) return } c.QAOps = qaMasterReader{QAOpsReader: c.QAOps, master: master} c.QAQuality = master.MasterQualityStore() if master.MasterQualityStore() == nil { c.QAQuality = nil } handler(w, r, c) }