Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Justice Counts] Add an Admin Panel API endpoint for deleting an agen…
…cy (Recidiviz/recidiviz-data#29355) ## Description of the change Add an Admin Panel API endpoint for deleting an agency. To reduce redundant logic, we extract out the existing delete_agency script and import it into a util file. Note: I first tried importing it into the admin API straight from recidiviz/tools/justice_counts/delete_agency.py but this caused a circular dependency: https://github.com/Recidiviz/recidiviz-data/actions/runs/8838706773/job/24270463398 ## Super/Child agencies It looks like our existing delete agency script actually does not handle superagencies/child agencies properly. My fix for this is: # If the agency is a superagency, nullify the super_agency_id field from all of its # children. Nullifying a child agency's super_agency_id field causes the child # agency to no longer be considered a child agency. I tested locally that this behavior works properly and that the child agencies are correctly "uncoupled" from their superagencies. But would love someone else to verify that nullifying Agency.super_agency_id for child agencies is the right approach! ## Testing ### Unit testing Add a comprehensive unit test to the admin panel test suite. ### Testing the Admin Panel Endpoint Locally I ran the admin panel endpoint via the request_api for a local agency and manually verified that the endpoint works. ``` python -m recidiviz.tools.justice_counts.control_panel.request_api admin/agency/XXX '{}' delete ``` I also verified this on a superagency and it correctly: * Deleted the superagency. * Turned the superagency's child agencies into regular agencies. I ran it on a child agency and it correctly: * Deleted the child agency * The child agency no longer showed up as a child for the superagency in the admin panel. ### Testing the Util Command Successfully ran the existing delete agency tool against a staging agency to confirm that the modification of the delete agency tool file does not break it. ``` python -m recidiviz.tools.justice_counts.delete_agency \ --project-id=justice-counts-staging \ --agency-id=361 \ --dry-run=false ``` <img width="585" alt="Screenshot 2024-04-25 at 11 54 34 AM" src="https://github.com/Recidiviz/recidiviz-data/assets/130382407/51e3492a-7b3e-430a-a3b9-6036fe80d2c6"> ## Related issues Closes Recidiviz/recidiviz-data#28832 GitOrigin-RevId: e68e4e78cd94c3ede4d1d3a826c5807b7c0675de
- Loading branch information