-
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.
Merge pull request #3503 from open-formulieren/refactor/3489-api-clie…
…nt-implementations-tris Refactor Haal Centraal BRP clients
- Loading branch information
Showing
64 changed files
with
1,317 additions
and
3,117 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
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,4 @@ | ||
""" | ||
This Django app is obsolete. The code is left here so that migrations can run, | ||
but after Open Forms 2.4.0 this package will be removed completely. | ||
""" |
This file was deleted.
Oops, something went wrong.
65 changes: 65 additions & 0 deletions
65
src/openforms/contrib/brp/migrations/0003_copy_config_to_haalcentraal.py
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,65 @@ | ||
# Generated by Django 3.2.21 on 2023-09-23 21:02 | ||
|
||
from django.db import migrations | ||
|
||
from openforms.contrib.haal_centraal.constants import BRPVersions | ||
|
||
|
||
def copy_config_to_hc(apps, _): | ||
""" | ||
If there was no HC prefill used, but BRPConfig did have a configuration, we can | ||
use that configuration to set up HC. | ||
""" | ||
HaalCentraalConfig = apps.get_model("haalcentraal", "HaalCentraalConfig") | ||
BRPConfig = apps.get_model("brp", "BRPConfig") | ||
hc_config, _ = HaalCentraalConfig.objects.get_or_create(pk=1) | ||
|
||
# already configured, nothing to do | ||
if hc_config.brp_personen_service: | ||
return | ||
|
||
brp_config, _ = BRPConfig.objects.get_or_create(pk=1) | ||
if not brp_config.brp_service: | ||
return | ||
|
||
# only v1 was functional/supported, so we can make this explicit | ||
hc_config.brp_personen_service = brp_config.brp_service | ||
hc_config.brp_personen_version = BRPVersions.v13 | ||
hc_config.config() | ||
|
||
|
||
def copy_config_from_hc(apps, _): | ||
""" | ||
Copy the config back from HC but only if it's V1 - v2 was not supported at the | ||
time these migrations were added. | ||
""" | ||
HaalCentraalConfig = apps.get_model("haalcentraal", "HaalCentraalConfig") | ||
BRPConfig = apps.get_model("brp", "BRPConfig") | ||
hc_config = HaalCentraalConfig.objects.first() | ||
if not hc_config: | ||
return | ||
|
||
if ( | ||
not hc_config.brp_personen_service | ||
or hc_config.brp_personen_version != BRPVersions.v13 | ||
): | ||
return | ||
|
||
brp_config, _ = BRPConfig.objects.get_or_create(pk=1) | ||
if brp_config.brp_service: | ||
return | ||
|
||
brp_config.brp_service = hc_config.brp_personen_service | ||
brp_config.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("brp", "0002_nice_verbose_name"), | ||
("haalcentraal", "0002_copy_config_from_prefill"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(copy_config_to_hc, copy_config_from_hc), | ||
] |
16 changes: 16 additions & 0 deletions
16
src/openforms/contrib/brp/migrations/0004_delete_brpconfig.py
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,16 @@ | ||
# Generated by Django 3.2.21 on 2023-09-23 21:12 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("brp", "0003_copy_config_to_haalcentraal"), | ||
] | ||
|
||
operations = [ | ||
migrations.DeleteModel( | ||
name="BRPConfig", | ||
), | ||
] |
This file was deleted.
Oops, something went wrong.
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,18 @@ | ||
""" | ||
Provide Haal Centraal shared functionality. | ||
`Haal Centraal`_ is an initiative to expose Dutch-government data via a number of APIs, | ||
in a centralized way ("direct bij de bron"). It is often confused or merged with the | ||
"Haal Centraal BRP Persoon bevragen", but this is really just a single API under the | ||
Haal Centraal umbrella. | ||
This package provides API configuration and (base) client implementations for those | ||
Haal Centraal API's that we consume in Open Forms. | ||
.. note:: Technically the BAG API (see :module:`openforms.contrib.kadaster.clients.bag`) | ||
also falls under the umbrella of Haal Centraal, however all API root URLs still point | ||
to ``kadaster.nl`` domains and as such the code is organized in | ||
``openforms.contrib.kadaster``. | ||
.. _Haal Centraal: https://vng-realisatie.github.io/Haal-Centraal/ | ||
""" |
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,17 @@ | ||
from django.contrib import admin | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
from solo.admin import SingletonModelAdmin | ||
|
||
from .models import HaalCentraalConfig | ||
|
||
|
||
@admin.register(HaalCentraalConfig) | ||
class HaalCentraalConfigAdmin(SingletonModelAdmin): | ||
fieldsets = ( | ||
( | ||
_("BRP Personen Bevragen"), | ||
{"fields": ("brp_personen_service", "brp_personen_version")}, | ||
), | ||
) | ||
autocomplete_fields = ("brp_personen_service",) |
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,8 @@ | ||
from django.apps import AppConfig | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
|
||
class HaalCentraalConfig(AppConfig): | ||
name = "openforms.contrib.haal_centraal" | ||
label = "haalcentraal" | ||
verbose_name = _("Haal Centraal configuration") |
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,25 @@ | ||
from zgw_consumers_ext.api_client import ServiceClientFactory | ||
|
||
from ..models import HaalCentraalConfig | ||
from .brp import CLIENT_CLS_FOR_VERSION as BRP_CLIENT_CLS_FOR_VERSION, BRPClient | ||
|
||
|
||
class NoServiceConfigured(RuntimeError): | ||
pass | ||
|
||
|
||
def get_brp_client(**kwargs) -> BRPClient: | ||
config = HaalCentraalConfig.get_solo() | ||
assert isinstance(config, HaalCentraalConfig) | ||
if not (service := config.brp_personen_service): | ||
raise NoServiceConfigured("No BRP service configured!") | ||
|
||
version = config.brp_personen_version | ||
ClientCls = BRP_CLIENT_CLS_FOR_VERSION.get(version) | ||
if ClientCls is None: | ||
raise RuntimeError( | ||
f"No suitable client class configured for API version {version}" | ||
) | ||
|
||
service_client_factory = ServiceClientFactory(service) | ||
return ClientCls.configure_from(service_client_factory, **kwargs) |
Oops, something went wrong.