Fix AI and config profile handlers broken in v5 single-tenant mode

The single-tenant lockdown (499ab812e) set mtPersistence to nil but
only patched AISettingsHandler with a legacy fallback. AIHandler (chat
service) and ConfigProfileHandler were missed, so AI features (Patrol,
Chat) failed with "chat service not available" and config profiles
would panic on nil dereference. Wire legacy persistence into both
handlers and add the same fallback to ProfileSuggestionHandler.

Fixes #1322
This commit is contained in:
rcourtman 2026-03-06 10:42:59 +00:00
parent 73bf2c1c7b
commit 743ef17b79
5 changed files with 52 additions and 21 deletions

View file

@ -18,6 +18,7 @@ import (
// ConfigProfileHandler handles configuration profile operations
type ConfigProfileHandler struct {
mtPersistence *config.MultiTenantPersistence
legacyPersistence *config.ConfigPersistence
validator *models.ProfileValidator
mu sync.RWMutex
suggestionHandler *ProfileSuggestionHandler
@ -31,15 +32,26 @@ func NewConfigProfileHandler(mtp *config.MultiTenantPersistence) *ConfigProfileH
}
}
// SetLegacyPersistence sets the single-tenant persistence fallback.
func (h *ConfigProfileHandler) SetLegacyPersistence(p *config.ConfigPersistence) {
h.legacyPersistence = p
}
// getPersistence resolves the persistence instance for the current tenant
func (h *ConfigProfileHandler) getPersistence(ctx context.Context) (*config.ConfigPersistence, error) {
orgID := GetOrgID(ctx)
return h.mtPersistence.GetPersistence(orgID)
if h.mtPersistence != nil {
orgID := GetOrgID(ctx)
return h.mtPersistence.GetPersistence(orgID)
}
if h.legacyPersistence != nil {
return h.legacyPersistence, nil
}
return nil, fmt.Errorf("no persistence available")
}
// SetAIHandler sets the AI handler for profile suggestions
func (h *ConfigProfileHandler) SetAIHandler(aiHandler *AIHandler) {
h.suggestionHandler = NewProfileSuggestionHandler(h.mtPersistence, aiHandler)
h.suggestionHandler = NewProfileSuggestionHandler(h.mtPersistence, h.legacyPersistence, aiHandler)
}
// ServeHTTP implements the http.Handler interface