From 1d7a75e4d99f9908da86bc2f640fad9957d51a42 Mon Sep 17 00:00:00 2001 From: Alex Vandiver Date: Mon, 12 Apr 2021 00:52:46 -0700 Subject: [PATCH] submitReport: Capture if the report was originally flagged for review. Because the Journeyman role is randomly chosen for review 15% of the time, and we have no way to log changes to the "pending review" flag, it is not possible to report on if a particular report was _originally_ flagged for review, as that is not predictable from the original `api_log`, nor accurate from the current `report`. Add an immutable-in-the-UI column for if the report was originally chosen for review. We may have better solutions in the future (e.g. using revision objects) but this is a quick and dirty stopgap. A stopgap fix for #274. --- vaccinate/api/views.py | 7 +++++++ vaccinate/core/admin.py | 1 + .../0076_report_originally_pending_review.py | 21 +++++++++++++++++++ vaccinate/core/models.py | 4 ++++ vaccinate/core/test_admin.py | 5 +++-- 5 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 vaccinate/core/migrations/0076_report_originally_pending_review.py diff --git a/vaccinate/api/views.py b/vaccinate/api/views.py index 8b39aef..315b47c 100644 --- a/vaccinate/api/views.py +++ b/vaccinate/api/views.py @@ -187,6 +187,13 @@ def submit_report(request, on_request_logged): # is_pending_review if report_data["is_pending_review"] or user_should_have_reports_reviewed(reporter): kwargs["is_pending_review"] = True + kwargs["originally_pending_review"] = True + else: + # Explicitly set as False, since the originally_pending_review + # field is nullable, so we know which reports were before we + # started logging. + kwargs["originally_pending_review"] = False + if bool(request.GET.get("test")) and request.GET.get("fake_timestamp"): fake_timestamp = parser.parse(request.GET["fake_timestamp"]) if fake_timestamp.tzinfo is None: diff --git a/vaccinate/core/admin.py b/vaccinate/core/admin.py index 06f9a0a..2ccb6e0 100644 --- a/vaccinate/core/admin.py +++ b/vaccinate/core/admin.py @@ -418,6 +418,7 @@ class ReportAdmin(DynamicListDisplayMixin, admin.ModelAdmin): readonly_fields = ( "created_at", "created_at_utc", + "originally_pending_review", "public_id", "airtable_id", "airtable_json", diff --git a/vaccinate/core/migrations/0076_report_originally_pending_review.py b/vaccinate/core/migrations/0076_report_originally_pending_review.py new file mode 100644 index 0000000..fcaaca4 --- /dev/null +++ b/vaccinate/core/migrations/0076_report_originally_pending_review.py @@ -0,0 +1,21 @@ +# Generated by Django 3.1.8 on 2021-04-12 08:11 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("core", "0075_various_model_field_options"), + ] + + operations = [ + migrations.AddField( + model_name="report", + name="originally_pending_review", + field=models.BooleanField( + help_text="Reports that were originally flagged as pending review", + null=True, + ), + ), + ] diff --git a/vaccinate/core/models.py b/vaccinate/core/models.py index 7591441..23e69d6 100644 --- a/vaccinate/core/models.py +++ b/vaccinate/core/models.py @@ -469,6 +469,10 @@ class ReportSource(models.TextChoices): is_pending_review = models.BooleanField( default=False, help_text="Reports that are pending review by our QA team" ) + originally_pending_review = models.BooleanField( + null=True, + help_text="Reports that were originally flagged as pending review", + ) soft_deleted = models.BooleanField( default=False, help_text="we never delete rows from this table; all deletes are soft", diff --git a/vaccinate/core/test_admin.py b/vaccinate/core/test_admin.py index 9f18172..79adac2 100644 --- a/vaccinate/core/test_admin.py +++ b/vaccinate/core/test_admin.py @@ -320,6 +320,7 @@ def test_custom_csv_export_for_reports( report_source="ca", appointment_tag=web, is_pending_review=True, + originally_pending_review=True, ) plus_65 = AvailabilityTag.objects.get(slug="vaccinating_65_plus") plus_50 = AvailabilityTag.objects.get(slug="vaccinating_50_plus") @@ -337,8 +338,8 @@ def test_custom_csv_export_for_reports( csv_bytes = b"".join(chunk for chunk in response.streaming_content) csv_string = csv_bytes.decode("utf-8") assert csv_string == ( - "id,location_id,location,is_pending_review,soft_deleted,soft_deleted_because,report_source,appointment_tag_id,appointment_tag,appointment_details,public_notes,internal_notes,reported_by_id,reported_by,created_at,call_request_id,call_request,airtable_id,airtable_json,public_id,availability_tags\r\n" - '{},{},Location 1,True,False,,ca,3,web,,,,{},auth0:reporter,{},,,,,{},"Vaccinating 65+, Vaccinating 50+"\r\n'.format( + "id,location_id,location,is_pending_review,originally_pending_review,soft_deleted,soft_deleted_because,report_source,appointment_tag_id,appointment_tag,appointment_details,public_notes,internal_notes,reported_by_id,reported_by,created_at,call_request_id,call_request,airtable_id,airtable_json,public_id,availability_tags\r\n" + '{},{},Location 1,True,True,False,,ca,3,web,,,,{},auth0:reporter,{},,,,,{},"Vaccinating 65+, Vaccinating 50+"\r\n'.format( report.id, report.location_id, reporter.id,