From d5fda4874938f0ecd7a3d658292ad311522808d7 Mon Sep 17 00:00:00 2001
From: Paulina Kujawa
Date: Wed, 13 Nov 2024 10:23:23 +0100
Subject: [PATCH 1/4] fix type
---
src/hct_mis_api/config/env.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/hct_mis_api/config/env.py b/src/hct_mis_api/config/env.py
index 7a2374ad95..e23d2865d2 100644
--- a/src/hct_mis_api/config/env.py
+++ b/src/hct_mis_api/config/env.py
@@ -31,7 +31,7 @@
"MAILJET_API_KEY": (str, ""),
"MAILJET_SECRET_KEY": (str, ""),
"CATCH_ALL_EMAIL": (list, []),
- "DEFAULT_EMAIL_DISPLAY": (list, []),
+ "DEFAULT_EMAIL_DISPLAY": (str, ""),
"KOBO_KF_URL": (str, "https://kf-hope.unitst.org"),
"KOBO_KC_URL": (str, "https://kc-hope.unitst.org"),
"KOBO_MASTER_API_TOKEN": (str, "KOBO_TOKEN"),
From b16c53767b2f1743649423e88d797d9e037b66a7 Mon Sep 17 00:00:00 2001
From: Pavlo Mokiichuk
Date: Wed, 13 Nov 2024 12:21:26 +0100
Subject: [PATCH 2/4] [STG] Fix download file for stg/dev env (#4423)
* fix download file
* mypy
* upd download
* upd
---
src/hct_mis_api/apps/payment/api/views.py | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/src/hct_mis_api/apps/payment/api/views.py b/src/hct_mis_api/apps/payment/api/views.py
index 2f610c8b82..bc23941961 100644
--- a/src/hct_mis_api/apps/payment/api/views.py
+++ b/src/hct_mis_api/apps/payment/api/views.py
@@ -210,7 +210,10 @@ def destroy(self, request: Request, *args: Any, **kwargs: Any) -> Response:
@action(detail=True, methods=["get"])
def download(self, request: Request, *args: Any, **kwargs: Any) -> FileResponse:
document = self.get_object()
- file_mimetype, _ = mimetypes.guess_type(document.file.path)
- response = FileResponse(document.file.open(), content_type=file_mimetype or "application/octet-stream")
- response["Content-Disposition"] = f"attachment; filename={document.file.name.split('/')[-1]}"
+ file = document.file
+ file_mimetype, _ = mimetypes.guess_type(file.url)
+ response = FileResponse(
+ file.open(), as_attachment=True, content_type=file_mimetype or "application/octet-stream"
+ )
+ response["Content-Disposition"] = f"attachment; filename={file.name.split('/')[-1]}"
return response
From 18e07115614843b6e43a9afae1663862817313f2 Mon Sep 17 00:00:00 2001
From: Marek Biczysko <34810846+MarekBiczysko@users.noreply.github.com>
Date: Wed, 13 Nov 2024 15:03:21 +0100
Subject: [PATCH 3/4] =?UTF-8?q?221518=5FGrievances=5FDelivery=5Fmechanism?=
=?UTF-8?q?=5Ffields=5Fare=5Falways=5Fwrongly=5Fadded=E2=80=A6=20(#4427)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../RequestedIndividualDataChangeTable.tsx | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/frontend/src/components/grievances/RequestedIndividualDataChangeTable/RequestedIndividualDataChangeTable.tsx b/src/frontend/src/components/grievances/RequestedIndividualDataChangeTable/RequestedIndividualDataChangeTable.tsx
index f718268226..3b4a198f86 100644
--- a/src/frontend/src/components/grievances/RequestedIndividualDataChangeTable/RequestedIndividualDataChangeTable.tsx
+++ b/src/frontend/src/components/grievances/RequestedIndividualDataChangeTable/RequestedIndividualDataChangeTable.tsx
@@ -48,7 +48,11 @@ export function RequestedIndividualDataChangeTable({
payment_channels_to_edit: paymentChannelsToEdit,
previous_payment_channels: previousPaymentChannels,
flex_fields: flexFields,
+ // eslint-disable-next-line
+ delivery_mechanism_data: _deliveryMechanismData,
delivery_mechanism_data_to_edit: deliveryMechanismDataToEdit,
+ // eslint-disable-next-line
+ delivery_mechanism_data_to_remove: _deliveryMechanismDataToRemove,
...restIndividualData
} = individualData;
const entries = restIndividualData && Object.entries(restIndividualData);
From b4d851d7658f1e70603132278d2039589787f79f Mon Sep 17 00:00:00 2001
From: Pavlo Mokiichuk
Date: Thu, 14 Nov 2024 13:39:46 +0100
Subject: [PATCH 4/4] STG Add django command to run script (#4422)
* add command
* add test :star2:
---
.../commands/remove-pre-gpf-data.py | 29 +++++++++++
.../apps/core/test_remove_pre_gpf_data.py | 48 +++++++++++++++++++
2 files changed, 77 insertions(+)
create mode 100644 src/hct_mis_api/apps/core/management/commands/remove-pre-gpf-data.py
create mode 100644 tests/unit/apps/core/test_remove_pre_gpf_data.py
diff --git a/src/hct_mis_api/apps/core/management/commands/remove-pre-gpf-data.py b/src/hct_mis_api/apps/core/management/commands/remove-pre-gpf-data.py
new file mode 100644
index 0000000000..8d2c05881f
--- /dev/null
+++ b/src/hct_mis_api/apps/core/management/commands/remove-pre-gpf-data.py
@@ -0,0 +1,29 @@
+import logging
+from typing import Any
+
+from django.core.management import BaseCommand
+from django.utils import timezone
+
+from hct_mis_api.one_time_scripts.remove_migrated_data_is_original import (
+ get_statistic_is_original,
+ remove_migrated_data_is_original,
+)
+
+logger = logging.getLogger(__name__)
+
+
+class Command(BaseCommand):
+ help = "Remove pre-GPF data, with is_original=True"
+
+ def handle(self, *args: Any, **options: Any) -> None:
+ start_time = timezone.now()
+ self.stdout.write("Starting to remove pre-GPF data.")
+
+ # get statistics
+ get_statistic_is_original()
+ # run script
+ remove_migrated_data_is_original()
+ # get statistics after
+ get_statistic_is_original()
+
+ self.stdout.write(self.style.SUCCESS(f"Done in {timezone.now() - start_time}"))
diff --git a/tests/unit/apps/core/test_remove_pre_gpf_data.py b/tests/unit/apps/core/test_remove_pre_gpf_data.py
new file mode 100644
index 0000000000..622c022809
--- /dev/null
+++ b/tests/unit/apps/core/test_remove_pre_gpf_data.py
@@ -0,0 +1,48 @@
+from io import StringIO
+from unittest import mock
+
+from django.core.management import call_command
+from django.test import TestCase
+
+from hct_mis_api.apps.account.fixtures import BusinessAreaFactory
+from hct_mis_api.apps.household.fixtures import (
+ HouseholdFactory,
+ IndividualFactory,
+ PendingHouseholdFactory,
+ PendingIndividualFactory,
+)
+from hct_mis_api.apps.household.models import (
+ Household,
+ Individual,
+ PendingHousehold,
+ PendingIndividual,
+)
+
+
+class TestRemovePreGpfDataCommands(TestCase):
+ def setUp(self) -> None:
+ BusinessAreaFactory(name="Afghanistan")
+ IndividualFactory(household=None)
+ IndividualFactory(is_original=True, household=None)
+ PendingIndividualFactory(household=None)
+ PendingIndividualFactory(is_original=True, household=None)
+ HouseholdFactory()
+ HouseholdFactory(is_original=True)
+ PendingHouseholdFactory()
+ PendingHouseholdFactory(is_original=True)
+
+ def test_remove_pre_gpf_data(self) -> None:
+ # check count before
+ self.assertEqual(Individual.all_objects.count(), 4)
+ self.assertEqual(PendingIndividual.all_objects.count(), 4)
+ self.assertEqual(Household.all_objects.count(), 4)
+ self.assertEqual(PendingHousehold.all_objects.count(), 4)
+
+ with mock.patch("sys.stdout", new=StringIO()):
+ call_command("remove-pre-gpf-data")
+
+ # check count after
+ self.assertEqual(Individual.all_objects.count(), 2)
+ self.assertEqual(PendingIndividual.all_objects.count(), 2)
+ self.assertEqual(Household.all_objects.count(), 2)
+ self.assertEqual(PendingHousehold.all_objects.count(), 2)