Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/country_workspace/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ class Group(Enum):
"MAILJET_SECRET_KEY": (str, "", "", False, "Mailjet API secret key"),
"DEDUP_API_URL": (str, "", "", False, "Dedup Engine API base URL"),
"DEDUP_API_TOKEN": (str, "", "", False, "Dedup Engine API token"),
"APP_BASE_URL": (str, "", "", False, "Base URL of this application (used to build absolute callback URLs)"),
"EMAIL_BACKEND": (
str,
"anymail.backends.mailjet.EmailBackend",
Expand Down
4 changes: 3 additions & 1 deletion src/country_workspace/config/fragments/constance.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .app import AURORA_API_TOKEN, AURORA_API_URL, HOPE_API_TOKEN, HOPE_API_URL, NEW_USER_DEFAULT_GROUP
from .dedup import DEDUP_API_URL, DEDUP_API_TOKEN
from .dedup import DEDUP_API_URL, DEDUP_API_TOKEN, APP_BASE_URL
from .kobo import KOBO_API_TOKEN, KOBO_KF_URL, KOBO_MASTER_API_TOKEN, KOBO_PROJECT_VIEW_ID
from .mail import MAILJET_API_KEY, MAILJET_SECRET_KEY

Expand Down Expand Up @@ -68,6 +68,7 @@
"MAILJET_SECRET_KEY": (MAILJET_SECRET_KEY, "Mailjet secret key", "write_only_text_input"),
"DEDUP_API_URL": (DEDUP_API_URL, "Dedup Engine server address", str),
"DEDUP_API_TOKEN": (DEDUP_API_TOKEN, "Dedup Engine API access token", "write_only_text_input"),
"APP_BASE_URL": (APP_BASE_URL, "Current server address", str),
"CHUNK_SIZE_FOR_VALIDATION_TASK": (500, "Number of records to process per chunk in validation tasks", int),
"PICTURE_IMPORT_MAX_ZIP_UPLOAD_MB": (
20,
Expand Down Expand Up @@ -173,6 +174,7 @@
"NEW_USER_IS_STAFF",
"NEW_USER_DEFAULT_GROUP",
"CONCURRENCY_GUARD",
"APP_BASE_URL",
),
}

Expand Down
1 change: 1 addition & 0 deletions src/country_workspace/config/fragments/dedup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

DEDUP_API_URL = env("DEDUP_API_URL")
DEDUP_API_TOKEN = env("DEDUP_API_TOKEN")
APP_BASE_URL = env("APP_BASE_URL")
6 changes: 6 additions & 0 deletions src/country_workspace/config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.contrib import admin
from django.urls import path

from country_workspace.contrib.hope.views import DeduplicationCallbackView
from country_workspace.workspaces.sites import workspace

urlpatterns = [
Expand All @@ -16,6 +17,11 @@
path(r"sentry_debug/", lambda _: 1 / 0),
path("select2/", include(django_select2.urls)),
path(r"__debug__/", include(debug_toolbar.urls)),
path(
"api/dedup/callback/<str:signed_token>/",
DeduplicationCallbackView.as_view(),
name="dedup_callback",
),
]

if "django_browser_reload" in settings.INSTALLED_APPS: # pragma: no cover
Expand Down
5 changes: 4 additions & 1 deletion src/country_workspace/contrib/dedup_engine/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,17 @@ def _request[T](self, operation: str, fn: Callable[[], T]) -> T:
except RequestException as exc:
raise self._err(operation, exc, getattr(exc, "response", None), error_cls=RemoteUnavailableError) from exc

def create_deduplication_set(self) -> response.CreatedDeduplicationSet:
def create_deduplication_set(self, notification_url: str | None = None) -> response.CreatedDeduplicationSet:
collection = resource.DeduplicationSetCollection(
self.session,
self.api_root.deduplication_sets,
)
payload: request.CreateDeduplicationSet = {"reference_pk": self.group_reference_id}
if self.deduplication_set_id:
payload["id"] = self.deduplication_set_id
if notification_url:
payload["notification_url"] = notification_url
payload["notify"] = True

result = self._request(
"create_deduplication_set",
Expand Down
29 changes: 29 additions & 0 deletions src/country_workspace/contrib/hope/forms.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Any

from django import forms

from country_workspace.workspaces.admin.cleaners.base import BaseActionForm
Expand All @@ -7,3 +9,30 @@ class CreateRDPForm(BaseActionForm):
batch_name = forms.CharField(
required=False, help_text="Label for this RDP creation. Defaults is the current date and time."
)
push_to_hope = forms.BooleanField(
required=False,
label="Push to HOPE after creation",
help_text="Automatically push beneficiaries to HOPE when RDP creation succeeds.",
)

def __init__(self, *args: Any, show_push_option: bool = False, **kwargs: Any) -> None:
super().__init__(*args, **kwargs)
if not show_push_option:
self.fields.pop("push_to_hope")


class CreateRDPushThresholdForm(BaseActionForm):
batch_name = forms.CharField(widget=forms.HiddenInput, required=False)
push_to_hope = forms.CharField(widget=forms.HiddenInput)
max_dedup_findings_percent = forms.IntegerField(
min_value=0,
max_value=100,
initial=0,
required=False,
label="Max duplicate findings (%)",
help_text=(
"Maximum share of individuals allowed to have duplicate matches before push is blocked. "
"Only applies when biometric deduplication is enabled. "
"0 means any duplicate finding will block the push."
),
)
6 changes: 6 additions & 0 deletions src/country_workspace/contrib/hope/push/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
cancel_existing_rdp_core,
claim_rdp_deduplication,
claim_rdp_push,
create_and_push_rdp_core,
create_rdp_and_start_dedup_core,
create_rdp_core,
dedup_callback_handle,
dedup_existing_rdp_core,
push_existing_rdp_core,
)
Expand All @@ -18,7 +21,10 @@
"cancel_existing_rdp_core",
"claim_rdp_deduplication",
"claim_rdp_push",
"create_and_push_rdp_core",
"create_rdp_and_start_dedup_core",
"create_rdp_core",
"dedup_callback_handle",
"dedup_existing_rdp_core",
"get_program_dedup_settings_policy",
"get_rdp_policy",
Expand Down
1 change: 1 addition & 0 deletions src/country_workspace/contrib/hope/push/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class CreateRdpConfig(SelectionConfig):
country_office_id: ReadOnly[int]
program_id: ReadOnly[int]
pushed_by_id: ReadOnly[int]
max_dedup_findings_percent: NotRequired[int]


class PushWorkflowConfig(SelectionConfig):
Expand Down
Loading