fix: auditor immer globalen Index nutzen, tenant_id ignorieren

auditor-Rolle hat evtl. tenant_id gesetzt (historisch), soll aber
trotzdem immer den globalen Index durchsuchen und nur No-Tenant-Mails
sehen. tenant_id auf auditor-User per DB-Migration auf NULL gesetzt.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
sysops
2026-04-04 19:51:42 +02:00
parent 994e5d16fc
commit 48cfb7cfa6
+4 -2
View File
@@ -94,10 +94,12 @@ func (s *Server) handleSearch(w http.ResponseWriter, r *http.Request) {
// PROJ-21 Phase 4: Use per-tenant index when available; fall back to // PROJ-21 Phase 4: Use per-tenant index when available; fall back to
// global index + post-filter when the tenant index manager is not wired. // global index + post-filter when the tenant index manager is not wired.
// auditor always uses the global index — they see no-tenant mails only,
// regardless of any tenant_id on their user record.
tenantID := tenantFromCtx(r.Context()) tenantID := tenantFromCtx(r.Context())
searchIdx := s.idx searchIdx := s.idx
usedTenantIndex := false usedTenantIndex := false
if s.idxMgr != nil && tenantID != nil { if s.idxMgr != nil && tenantID != nil && sess.Role != userstore.RoleAuditor {
searchIdx = s.idxMgr.ForTenant(tenantID) searchIdx = s.idxMgr.ForTenant(tenantID)
usedTenantIndex = true usedTenantIndex = true
} }
@@ -111,7 +113,7 @@ func (s *Server) handleSearch(w http.ResponseWriter, r *http.Request) {
// Fallback tenant isolation: post-filter when we used the global index // Fallback tenant isolation: post-filter when we used the global index
// but the user belongs to a tenant. This is the legacy path; the per-tenant // but the user belongs to a tenant. This is the legacy path; the per-tenant
// index path above makes this unnecessary. // index path above makes this unnecessary.
if tenantID != nil && !usedTenantIndex && len(result.Hits) > 0 { if tenantID != nil && !usedTenantIndex && len(result.Hits) > 0 && sess.Role != userstore.RoleAuditor {
allowedIDs, idErr := s.store.GetAllIDsByTenant(r.Context(), tenantID) allowedIDs, idErr := s.store.GetAllIDsByTenant(r.Context(), tenantID)
if idErr == nil { if idErr == nil {
allowed := make(map[string]struct{}, len(allowedIDs)) allowed := make(map[string]struct{}, len(allowedIDs))