Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#1079] Added 'x-origin-oin' and 'x-doelbinding' fields to HaalCentraalConfig for BRP API 1.3 #456

Merged
merged 2 commits into from
Feb 7, 2023
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 3.2.15 on 2023-02-06 14:11

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("haalcentraal", "0001_initial"),
]

operations = [
migrations.AddField(
model_name="haalcentraalconfig",
name="api_doelbinding",
field=models.CharField(
blank=True,
help_text="Value of the 'x-doelbinding' header for Haalcentraal BRP v1.3 API requests.",
max_length=64,
verbose_name="API 'doelbinding' header",
),
),
migrations.AddField(
model_name="haalcentraalconfig",
name="api_origin_oin",
field=models.CharField(
blank=True,
help_text="Value of the 'x-origin-oin' header for Haalcentraal BRP v1.3 API requests.",
max_length=64,
verbose_name="API 'OIN' header",
),
),
]
17 changes: 17 additions & 0 deletions src/open_inwoner/haalcentraal/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,23 @@ class HaalCentraalConfig(SingletonModel):
null=True,
)

api_origin_oin = models.CharField(
verbose_name=_("API 'OIN' header"),
max_length=64,
blank=True,
help_text=_(
"Value of the 'x-origin-oin' header for Haalcentraal BRP v1.3 API requests."
),
)
api_doelbinding = models.CharField(
verbose_name=_("API 'doelbinding' header"),
max_length=64,
blank=True,
help_text=_(
"Value of the 'x-doelbinding' header for Haalcentraal BRP v1.3 API requests."
),
)

objects = HaalCentraalConfigManager()

class Meta:
Expand Down
23 changes: 22 additions & 1 deletion src/open_inwoner/haalcentraal/tests/test_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
from open_inwoner.accounts.tests.factories import UserFactory
from open_inwoner.utils.logentry import LOG_ACTIONS

from ...utils.test import ClearCachesMixin
from ..models import HaalCentraalConfig
from .factories import ServiceFactory
from .mixins import HaalCentraalMixin


@requests_mock.Mocker()
class TestPreSaveSignal(HaalCentraalMixin, TestCase):
class TestPreSaveSignal(ClearCachesMixin, HaalCentraalMixin, TestCase):
def test_signal_updates_users_data_when_logged_in_via_digid_v_2(self, m):
self._setUpMocks_v_2(m)
self._setUpService()
Expand Down Expand Up @@ -61,6 +62,26 @@ def test_signal_updates_users_data_when_logged_in_via_digid_v_1_3(self, m):
self.assertEqual(updated_user[0].city, "'s-Gravenhage")
self.assertTrue(updated_user[0].is_prepopulated)

@override_settings(BRP_VERSION="1.3")
def test_request_adds_configured_headers_when_calling_via_digid_v_1_3(self, m):
config = HaalCentraalConfig.get_solo()
config.api_origin_oin = "00000001234567890000"
config.api_doelbinding = "Huisvesting"
config.save()

self._setUpMocks_v_1_3(m)
self._setUpService()

user = UserFactory(
first_name="", last_name="", login_type=LoginTypeChoices.digid
)
user.bsn = "999993847"
user.save()

request = m.request_history[-1]
self.assertEqual(request.headers["x-origin-oin"], "00000001234567890000")
self.assertEqual(request.headers["x-doelbinding"], "Huisvesting")

def test_user_is_not_updated_without_defining_service(self, m):
self._setUpMocks_v_2(m)

Expand Down
14 changes: 9 additions & 5 deletions src/open_inwoner/haalcentraal/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,19 @@ def fetch_brp_data(instance, brp_version):
elif brp_version == "1.3":
url = urljoin(client.base_url, f"ingeschrevenpersonen/{instance.bsn}")
try:
headers = {
"Accept": "application/hal+json",
}
if config.api_origin_oin: # See Taiga #755
headers["x-origin-oin"] = config.api_origin_oin
if config.api_doelbinding: # See Taiga #755
headers["x-doelbinding"] = config.api_doelbinding

data = client.retrieve(
"ingeschrevenpersonen",
url=url,
request_kwargs=dict(
headers={
"Accept": "application/hal+json",
"x-doelbinding": "Huisvesting", # See Taiga #755
"x-origin-oin": "00000003273229750000",
}, # See Taiga #755
headers=headers,
params={
"fields": "geslachtsaanduiding,naam,geboorte,verblijfplaats"
},
Expand Down