From d9a3cac41ea63c1895e69a6c358fc168f93f2913 Mon Sep 17 00:00:00 2001 From: Dan Felder <30899941+felder101@users.noreply.github.com> Date: Tue, 21 Jan 2025 13:44:41 -0500 Subject: [PATCH] Report download bug (#740) * Update report download logic to include all quiz completions for the user bureaus when user selects agency only * removed unused import --- training/repositories/user.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/training/repositories/user.py b/training/repositories/user.py index e25dd47e..bbc4b0f8 100644 --- a/training/repositories/user.py +++ b/training/repositories/user.py @@ -80,7 +80,13 @@ def get_user_quiz_completion_report(self, filter: SmartPayTrainingReportFilter, if filter.bureau_id is not None: query = query.filter(models.User.agency_id == filter.bureau_id) elif filter.agency_id is not None: - query = query.filter(models.User.agency_id == filter.agency_id) + # if agency is selected and not the bureau, return all records associated to agency/bureau the user has access to + all_agencies = self._session.query(models.Agency).all() + selected_agency = [agency for agency in all_agencies if agency.id == filter.agency_id][0] + selected_agency_bureaus_ids = [agency.id for agency in all_agencies if agency.name == selected_agency.name] + allowed_agency_ids = [obj.id for obj in report_user.report_agencies] + filter_agencies = [x for x in allowed_agency_ids if x in selected_agency_bureaus_ids] + query = query.filter(models.User.agency_id.in_(filter_agencies)) else: allowed_agency_ids = [obj.id for obj in report_user.report_agencies] query = query.filter(models.User.agency_id.in_(allowed_agency_ids))