Fix notification queries to exclude tasks from inactive residences

- task_repo.go: Add is_active filter to residence subquery in UserIDs filter
- handler.go: Add is_active filter to daily digest residence join
- onboarding_email_service.go: Fix Django table names and task status filter
- task_repo_test.go: Add regression tests for inactive residence filtering

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Trey t
2025-12-22 14:47:37 -06:00
parent 8cd41a145f
commit 37a04db82e
4 changed files with 124 additions and 12 deletions

View File

@@ -62,9 +62,9 @@ func (r *TaskRepository) applyFilterOptions(query *gorm.DB, opts TaskFilterOptio
} else if len(opts.ResidenceIDs) > 0 {
query = query.Where("task_task.residence_id IN ?", opts.ResidenceIDs)
} else if len(opts.UserIDs) > 0 {
// For notifications: tasks assigned to users OR owned by users
// For notifications: tasks assigned to users OR owned by users (only from active residences)
query = query.Where(
"(task_task.assigned_to_id IN ? OR task_task.residence_id IN (SELECT id FROM residence_residence WHERE owner_id IN ?))",
"(task_task.assigned_to_id IN ? OR task_task.residence_id IN (SELECT id FROM residence_residence WHERE owner_id IN ? AND is_active = true))",
opts.UserIDs, opts.UserIDs,
)
}