Skip to content

Commit

Permalink
Merge pull request #308 from maykinmedia/develop
Browse files Browse the repository at this point in the history
Update main, release v1.0.1
  • Loading branch information
alextreme authored Sep 20, 2022
2 parents 097258e + 6e3b4b7 commit e577480
Show file tree
Hide file tree
Showing 20 changed files with 3,095 additions and 79 deletions.
2 changes: 2 additions & 0 deletions src/open_inwoner/accounts/tests/test_password_reset_view.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from django.core.cache import cache
from django.test import TestCase
from django.urls import reverse


class PasswordResetViewTests(TestCase):
def test_user_cant_access_the_password_reset_view_more_than_5_times(self):
url = reverse("admin_password_reset")
cache.clear()

for i in range(5):
response = self.client.get(url)
Expand Down
29 changes: 22 additions & 7 deletions src/open_inwoner/accounts/views/cases.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin
from django.core.cache import cache
from django.shortcuts import redirect
from django.urls import reverse
from django.utils.functional import cached_property
Expand Down Expand Up @@ -44,7 +45,10 @@ def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)

cases = fetch_cases(self.request.user.bsn)
case_types = {case_type.url: case_type for case_type in fetch_case_types()}
case_types = cache.get("case_types")
if not case_types:
case_types = {case_type.url: case_type for case_type in fetch_case_types()}
cache.set("case_types", case_types, 60 * 60)
status_types = {
status_type.url: status_type for status_type in fetch_status_types()
}
Expand All @@ -65,8 +69,9 @@ def get_context_data(self, **kwargs):
{
"uuid": str(case.uuid),
"start_date": case.startdatum,
"end_date": case.einddatum,
"description": case_types[case.zaaktype].omschrijving
"end_date": case.einddatum if hasattr(case, "einddatum") else None,
"description": case.omschrijving,
"zaaktype_description": case_types[case.zaaktype].omschrijving
if case_types
else _("No data available"),
"current_status": status_types[
Expand All @@ -82,9 +87,17 @@ def get_context_data(self, **kwargs):
("#completed_apps", _("Afgeronde aanvragen")),
]

context["open_cases"] = [case for case in updated_cases if not case["end_date"]]
context["open_cases"] = [
case
for case in updated_cases
if not case["end_date"] and not case["current_status"] == "Afgerond"
]
context["open_cases"].sort(key=lambda case: case["start_date"])
context["closed_cases"] = [case for case in updated_cases if case["end_date"]]
context["closed_cases"] = [
case
for case in updated_cases
if case["end_date"] or case["current_status"] == "Afgerond"
]
context["closed_cases"].sort(key=lambda case: case["end_date"])

return context
Expand Down Expand Up @@ -134,9 +147,11 @@ def get_context_data(self, **kwargs):
status.statustype = status_type

context["case"] = {
"identification": case.identificatie,
"start_date": case.startdatum,
"end_date": case.einddatum,
"description": case_type.omschrijving
"end_date": case.einddatum if hasattr(case, "einddatum") else None,
"description": case.omschrijving,
"type_description": case_type.omschrijving
if case_type
else _("No data available"),
"current_status": statuses[-1].statustype.omschrijving
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ <h2 class="h2">{{footer_texts.footer_visiting_title}}</h2>
<p class="p">
{{footer_texts.footer_visiting_intro|linebreaksbr}}
</p>
{% if footer_texts.footer_visiting_map %}
{% button icon="arrow_forward" icon_position='before' transparent=True text=_("Bekijk op Google Maps") href=footer_texts.footer_visiting_map %}
{% endif %}
</div>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<ul class="accessibility-header__list" role="complementary" aria-label="{% trans "Toegangkelijkheids help" %}">
<li class="accessibility-header__list-item">
{% trans "Lees voor" as link_text %}
{% link href="#" icon="hearing" text=link_text extra_classes="accessibility--read" %}
{% link href="#" icon="volume_up" text=link_text extra_classes="accessibility--read" %}
</li>

<li class="accessibility-header__list-item">
Expand Down
2 changes: 1 addition & 1 deletion src/open_inwoner/components/templatetags/dashboard_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def case_dashboard(case: dict, **kwargs) -> dict:
{
"icon": "inventory_2",
"label": _("Aanvraag"),
"value": case.get("description"),
"value": case.get("identification"),
},
{
"icon": "calendar_today",
Expand Down
2 changes: 1 addition & 1 deletion src/open_inwoner/components/templatetags/file_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def case_document_list(documents: list[ZaakInformatieObject], **kwargs) -> dict:

files = [
{
"file": document.titel or document.beschrijving or _("Geen titel"),
"file": document.titel or _("Geen titel"),
}
for document in documents
]
Expand Down
3 changes: 2 additions & 1 deletion src/open_inwoner/conf/app/csp.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
#
# NOTE: make sure values are a tuple or list, and to quote special values like 'self'
CSP_DEFAULT_SRC = (
"'none'",
"'self'",
) # ideally we'd use BASE_URI but it'd have to be lazy or cause issues
CSP_BASE_URI = ("'self'",)
CSP_FONT_SRC = ("'self'",)
CSP_FRAME_ANCESTORS = ["'self'"]
CSP_FRAME_SRC = ["'self'"]
CSP_OBJECT_SRC = "'none'"
CSP_SCRIPT_SRC = (
"'self'",
"https://service.pdok.nl/brt/achtergrondkaart/wmts/v2_0/standaard/EPSG:28992/",
Expand Down
5 changes: 4 additions & 1 deletion src/open_inwoner/conf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@
EMAIL_USE_TLS = config("EMAIL_USE_TLS", default=False)
EMAIL_TIMEOUT = 10

DEFAULT_FROM_EMAIL = "[email protected]"
DEFAULT_FROM_EMAIL = config("DEFAULT_FROM_EMAIL", default="[email protected]")

#
# LOGGING
Expand Down Expand Up @@ -877,6 +877,9 @@
MAX_UPLOAD_SIZE = 1024 ** 2 * 100 # 100MB
UPLOAD_FILE_TYPES = "application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/msword,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel,text/plain,application/vnd.oasis.opendocument.text,application/vnd.oasis.opendocument.formula,application/vnd.oasis.opendocument.spreadsheet,application/pdf,image/jpeg,image/png"

# HaalCentraal BRP versions
BRP_VERSION = config("BRP_VERSION", default="2.0")

#
# DIGID
#
Expand Down
100 changes: 65 additions & 35 deletions src/open_inwoner/haalcentraal/signals.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
from urllib.parse import urljoin

from django.conf import settings
from django.db.models.signals import pre_save
from django.dispatch import receiver
from django.utils.translation import gettext as _
Expand All @@ -17,58 +18,87 @@
logger = logging.getLogger(__name__)


def fetch_data(instance):
def fetch_data(instance, brp_version):
config = HaalCentraalConfig.get_solo()

if not config.service:
logger.warning("no service defined for Haal Centraal")
return {}

client = config.service.build_client()
url = urljoin(client.base_url, "personen")
logger.warning(brp_version)
data = {}
if brp_version == "2.0":
url = urljoin(client.base_url, "personen")
try:
data = client.operation(
operation_id="GetPersonen",
url=url,
data={
"fields": "naam,geboorte",
"type": "RaadpleegMetBurgerservicenummer",
"burgerservicenummer": [instance.bsn],
},
request_kwargs=dict(
headers={"Accept": "application/hal+json"}, verify=False
),
)
except RequestException as e:
logger.exception("exception while making request", exc_info=e)
return {}
except ClientError as e:
logger.exception("exception while making request", exc_info=e)
return {}

try:
data = client.operation(
operation_id="GetPersonen",
url=url,
data={
"fields": "naam,geboorte",
"type": "RaadpleegMetBurgerservicenummer",
"burgerservicenummer": [instance.bsn],
},
request_kwargs=dict(
headers={"Accept": "application/hal+json"},
),
)
except RequestException as e:
logger.exception("exception while making request", exc_info=e)
return {}
except ClientError as e:
logger.exception("exception while making request", exc_info=e)
return {}
elif brp_version == "1.3":
url = urljoin(client.base_url, f"ingeschrevenpersonen/{instance.bsn}")
try:
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
params={"fields": "naam,geboorte.datum"},
verify=False,
),
)
except RequestException as e:
logger.exception("exception while making request", exc_info=e)
return {}
except ClientError as e:
logger.exception("exception while making request", exc_info=e)
return {}

return data


@receiver(pre_save, sender=User)
def on_bsn_change(instance, **kwargs):
brp_version = settings.BRP_VERSION

if (
instance.bsn
and instance.is_prepopulated is False
and instance.login_type == LoginTypeChoices.digid
):
system_action("Retrieving data from haal centraal based on BSN")
data = fetch_data(instance)
if data.get("personen"):
person = glom(data, "personen")[0]
try:
instance.first_name = glom(person, "naam.voornamen")
instance.last_name = glom(person, "naam.geslachtsnaam")
instance.birthday = glom(person, "geboorte.datum.datum")
instance.is_prepopulated = True
except PathAccessError as e:
logger.exception(
"exception while trying to access fetched data", exc_info=e
)
else:
system_action(_("data was retrieved from haal centraal"), instance)
data = fetch_data(instance, brp_version)

if brp_version == "2.0" and data.get("personen"):
data = glom(data, "personen")[0]

try:
instance.first_name = glom(data, "naam.voornamen")
instance.last_name = glom(data, "naam.geslachtsnaam")
instance.birthday = glom(data, "geboorte.datum.datum")
instance.is_prepopulated = True
except PathAccessError as e:
logger.exception(
"exception while trying to access fetched data", exc_info=e
)
else:
system_action(_("data was retrieved from haal centraal"), instance)
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"_links": {
"self": {
"href": "https://www.haalcentraal.nl/haalcentraal/api/brp/ingeschrevenpersonen/999993847"
}
},
"naam": {
"aanhef": "Geachte mevrouw Kooyman",
"aanschrijfwijze": "M. Kooyman",
"gebruikInLopendeTekst": "mevrouw Kooyman",
"aanduidingNaamgebruik": "eigen",
"voornamen": "Merel",
"voorletters": "M.",
"geslachtsnaam": "Kooyman"
},
"geboorte": {
"datum": {
"datum": "1982-04-10",
"jaar": 1982,
"maand": 4,
"dag": 10
}
}
}
Loading

0 comments on commit e577480

Please sign in to comment.