-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3ee2ba6
commit 33a2c58
Showing
12 changed files
with
9,871 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from django.apps import AppConfig | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
|
||
class SuwinetApp(AppConfig): | ||
name = "openforms.prefill.contrib.suwinet" | ||
label = "prefill_suwinet" | ||
verbose_name = _("Suwinet prefill plugin") | ||
|
||
def ready(self): | ||
# register the plugin | ||
from . import plugin # noqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import logging | ||
|
||
from django.urls import reverse | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
from glom import glom | ||
|
||
from openforms.authentication.constants import AuthAttribute | ||
from openforms.plugins.exceptions import InvalidPluginConfiguration | ||
from openforms.submissions.models import Submission | ||
from openforms.typing import JSONSerializable | ||
from suwinet.client import NoServiceConfigured, SuwinetClient, get_client | ||
from suwinet.constants import SERVICES | ||
from suwinet.models import SuwinetConfig | ||
|
||
from ...base import BasePlugin | ||
from ...constants import IdentifierRoles | ||
from ...registry import register | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def _get_client() -> SuwinetClient | None: | ||
try: | ||
return get_client() | ||
except NoServiceConfigured: | ||
logger.warning("No service defined for Suwinet.") | ||
return None | ||
|
||
|
||
@register("suwinet") | ||
class SuwinetPrefill(BasePlugin): | ||
requires_auth = AuthAttribute.bsn | ||
verbose_name = _("Suwinet") | ||
|
||
@staticmethod | ||
def get_available_attributes(): | ||
if not (client := _get_client()): | ||
return [] | ||
with client: | ||
return [ | ||
(f"{service_name}.{operation}", f"{service_name} > {operation}") | ||
for service_name in client | ||
for operation in SERVICES[service_name].operations | ||
] | ||
|
||
def get_prefill_values( | ||
self, | ||
submission: Submission, | ||
attributes: list[str], | ||
identifier_role: str = IdentifierRoles.main, | ||
) -> dict[str, JSONSerializable]: | ||
if not ( | ||
(client := _get_client()) | ||
and (bsn := self.get_identifier_value(submission, identifier_role)) | ||
): | ||
return {} | ||
|
||
def get_value(attr) -> dict | None: | ||
try: | ||
return glom(client, attr)(bsn) | ||
except Exception: | ||
logger.exception("Suwinet raised exception") | ||
return None | ||
|
||
with client: | ||
return {attr: value for attr in attributes if (value := get_value(attr))} | ||
|
||
def get_co_sign_values( | ||
self, identifier: str, submission: Submission | None = None | ||
) -> tuple[dict[str, dict], str]: | ||
""" | ||
Given an identifier, fetch the co-sign specific values. | ||
The return value is a dict keyed by field name as specified in | ||
``self.co_sign_fields``. | ||
:param identifier: the unique co-signer identifier used to look up the details | ||
in the pre-fill backend. | ||
:return: a key-value dictionary, where the key is the requested attribute and | ||
the value is the prefill value to use for that attribute. | ||
""" | ||
raise NotImplementedError( | ||
"You must implement the 'get_co_sign_values' method." | ||
) # pragma: nocover | ||
|
||
def check_config(self): | ||
try: | ||
client = get_client() | ||
# TODO: Try all endpoints test bsn | ||
except NoServiceConfigured as e: | ||
raise InvalidPluginConfiguration( | ||
_("Configuration error: {exception}").format(exception=e) | ||
) | ||
if not len(client): | ||
raise InvalidPluginConfiguration( | ||
_("No services found. Check the binding addresses or provide a wsdl.") | ||
) | ||
|
||
def get_config_actions(self): | ||
return [ | ||
( | ||
_("Configuration"), | ||
reverse( | ||
"admin:suwinet_suwinetconfig_change", | ||
args=(SuwinetConfig.singleton_instance_id,), | ||
), | ||
) | ||
] |
Empty file.
243 changes: 243 additions & 0 deletions
243
.../data/vcr_cassettes/SuwinetPrefillTests/SuwinetPrefillTests.test_binding_to_variable.yaml
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.