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

Workarounds for eSuite integration #305

Merged
merged 12 commits into from
Sep 19, 2022
Merged
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
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
12 changes: 8 additions & 4 deletions src/open_inwoner/haalcentraal/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def fetch_data(instance, brp_version):

client = config.service.build_client()
logger.warning(brp_version)
data = {}
if brp_version == "2.0":
url = urljoin(client.base_url, "personen")
try:
Expand All @@ -39,8 +40,7 @@ def fetch_data(instance, brp_version):
"burgerservicenummer": [instance.bsn],
},
request_kwargs=dict(
headers={"Accept": "application/hal+json"},
verify=False
headers={"Accept": "application/hal+json"}, verify=False
),
)
except RequestException as e:
Expand All @@ -57,9 +57,13 @@ def fetch_data(instance, brp_version):
"ingeschrevenpersonen",
url=url,
request_kwargs=dict(
headers={"Accept": "application/hal+json"},
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
verify=False,
),
)
except RequestException as e:
Expand Down
68 changes: 67 additions & 1 deletion src/open_inwoner/openzaak/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,80 @@
from requests import RequestException
from zds_client import ClientError
from zgw_consumers.api_models.base import factory
from zgw_consumers.api_models.catalogi import ZaakType
from zgw_consumers.api_models.catalogi import ZGWModel
from zgw_consumers.api_models.zaken import Zaak
from zgw_consumers.service import get_paginated_results

from .clients import build_client

logger = logging.getLogger(__name__)

### Workaround for Groningen e-Suite #773 ###

from dataclasses import dataclass
from datetime import date, datetime
from decimal import Decimal
from typing import List, Optional, Union

from dateutil.parser import parse
from dateutil.relativedelta import relativedelta


@dataclass
class ZaakType(ZGWModel):
url: str
# catalogus: str
identificatie: str
omschrijving: str
vertrouwelijkheidaanduiding: str
doel: str
aanleiding: str
indicatie_intern_of_extern: str
handeling_initiator: str
onderwerp: str
handeling_behandelaar: str
# doorlooptijd: relativedelta
# servicenorm: Optional[relativedelta]
# opschorting_en_aanhouding_mogelijk: bool
# verlenging_mogelijk: bool
# verlengingstermijn: Optional[relativedelta]
# publicatie_indicatie: bool
# producten_of_diensten: list
statustypen: list
# resultaattypen: list
# informatieobjecttypen: list
# roltypen: list
# besluittypen: list

# begin_geldigheid: date
# versiedatum: date


@dataclass
class Zaak(ZGWModel):
url: str
identificatie: str
bronorganisatie: str
omschrijving: str
# toelichting: str
zaaktype: str
registratiedatum: date
startdatum: date
einddatum_gepland: Optional[date]
uiterlijke_einddatum_afdoening: Optional[date]
# publicatiedatum: Optional[date]
vertrouwelijkheidaanduiding: str
status: str
einddatum: Optional[date] = None


# resultaat: str
# relevante_andere_zaken: list
# zaakgeometrie: dict


### ###


def fetch_cases(user_bsn: str) -> List[Zaak]:
client = build_client("zaak")
Expand Down
29 changes: 23 additions & 6 deletions src/open_inwoner/openzaak/statuses.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,33 @@
from zds_client import ClientError
from zgw_consumers.api_models.base import factory
from zgw_consumers.api_models.catalogi import StatusType
from zgw_consumers.api_models.zaken import Status, ZaakInformatieObject
from zgw_consumers.api_models.zaken import Status, ZGWModel
from zgw_consumers.concurrent import parallel
from zgw_consumers.service import get_paginated_results

from .clients import build_client

logger = logging.getLogger(__name__)

### Workaround for Groningen e-Suite #773 ###

from dataclasses import dataclass
from datetime import date, datetime


@dataclass
class ZaakInformatieObject(ZGWModel):
url: str
informatieobject: str
zaak: str
# aard_relatie_weergave: str
titel: str
# beschrijving: str
registratiedatum: datetime


### ###


def fetch_status_history(case_url: str) -> List[Status]:
client = build_client("zaak")
Expand Down Expand Up @@ -40,11 +59,9 @@ def fetch_specific_statuses(status_urls: List[str]) -> List[Status]:
if client is None:
return []

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sergei: client.schema voor de with parallel zal het schema resolven en cachen, dan moet dat niet in de threadpool zelf gebeuren. might fix your issue

with parallel() as executor:
_statuses = executor.map(
lambda url: client.retrieve("status", url=url),
status_urls,
)
_statuses = []
for url in status_urls:
_statuses += [client.retrieve("status", url=url)]

statuses = factory(Status, list(_statuses))

Expand Down
18 changes: 12 additions & 6 deletions src/open_inwoner/openzaak/tests/test_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,16 @@ def test_sorted_cases_are_retrieved_when_user_logged_in_via_digid(self, m):
"uuid": "6f8de38f-85ea-42d3-978c-845a033335a7",
"start_date": datetime.date(2021, 7, 26),
"end_date": None,
"description": "Coffee zaaktype",
"description": "Zaak naar aanleiding van ingezonden formulier",
"zaaktype_description": "Coffee zaaktype",
"current_status": "Finish",
},
{
"uuid": "e4d469b9-6666-4bdd-bf42-b53445298102",
"start_date": datetime.date(2022, 1, 12),
"end_date": None,
"description": "Coffee zaaktype",
"description": "Zaak naar aanleiding van ingezonden formulier",
"zaaktype_description": "Coffee zaaktype",
"current_status": "Finish",
},
],
Expand All @@ -197,7 +199,8 @@ def test_sorted_cases_are_retrieved_when_user_logged_in_via_digid(self, m):
"uuid": "d8bbdeb7-770f-4ca9-b1ea-77b4730bf67d",
"start_date": datetime.date(2022, 1, 2),
"end_date": datetime.date(2022, 1, 16),
"description": "Coffee zaaktype",
"description": "Zaak naar aanleiding van ingezonden formulier",
"zaaktype_description": "Coffee zaaktype",
"current_status": "Initial request",
}
],
Expand All @@ -218,14 +221,16 @@ def test_status_type_is_manually_retrieved_if_not_in_status_types(self, m):
"uuid": "6f8de38f-85ea-42d3-978c-845a033335a7",
"start_date": datetime.date(2021, 7, 26),
"end_date": None,
"description": "Coffee zaaktype",
"description": "Zaak naar aanleiding van ingezonden formulier",
"zaaktype_description": "Coffee zaaktype",
"current_status": "Finish",
},
{
"uuid": "e4d469b9-6666-4bdd-bf42-b53445298102",
"start_date": datetime.date(2022, 1, 12),
"end_date": None,
"description": "Coffee zaaktype",
"description": "Zaak naar aanleiding van ingezonden formulier",
"zaaktype_description": "Coffee zaaktype",
"current_status": "Finish",
},
],
Expand All @@ -237,7 +242,8 @@ def test_status_type_is_manually_retrieved_if_not_in_status_types(self, m):
"uuid": "d8bbdeb7-770f-4ca9-b1ea-77b4730bf67d",
"start_date": datetime.date(2022, 1, 2),
"end_date": datetime.date(2022, 1, 16),
"description": "Coffee zaaktype",
"description": "Zaak naar aanleiding van ingezonden formulier",
"zaaktype_description": "Coffee zaaktype",
"current_status": "Initial request",
}
],
Expand Down
8 changes: 6 additions & 2 deletions src/open_inwoner/openzaak/tests/test_statuses.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django_webtest import WebTest
from zgw_consumers.api_models.base import factory
from zgw_consumers.api_models.catalogi import StatusType
from zgw_consumers.api_models.zaken import Status, ZaakInformatieObject
from zgw_consumers.api_models.zaken import Status
from zgw_consumers.constants import APITypes
from zgw_consumers.test import generate_oas_component, mock_service_oas_get

Expand All @@ -17,6 +17,7 @@
from open_inwoner.utils.test import paginated_response

from ..models import OpenZaakConfig
from ..statuses import ZaakInformatieObject
from .factories import ServiceFactory

ZAKEN_ROOT = "https://zaken.nl/api/v1/"
Expand All @@ -27,6 +28,7 @@
@requests_mock.Mocker()
class TestListStatusView(WebTest):
def setUp(self):
self.maxDiff = None
self.user = UserFactory(
login_type=LoginTypeChoices.digid, bsn="900222086", email="johm@smith.nl"
)
Expand Down Expand Up @@ -159,9 +161,11 @@ def test_status_is_retrieved_when_user_logged_in_via_digid(self, m):
self.assertEqual(
response.context.get("case"),
{
"identification": "ZAAK-2022-0000000024",
"start_date": datetime.date(2022, 1, 2),
"end_date": None,
"description": "Coffee zaaktype",
"description": "Zaak naar aanleiding van ingezonden formulier",
"type_description": "Coffee zaaktype",
"current_status": "Finish",
"statuses": [status1_obj, status2_obj],
"documents": [
Expand Down
5 changes: 3 additions & 2 deletions src/open_inwoner/templates/pages/cases/status.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{% render_column span=9 %}

{# Title/dashboard. #}
<h1 class="h1" id="title">{{ case.obj.omschrijving }}</h1>
<h1 class="h1" id="title">{{ case.description }}</h1>
{% case_dashboard case %}

{# Status history. #}
Expand All @@ -26,7 +26,8 @@ <h2 class="h2" id="statuses">{% trans 'Status' %}</h2>
{% if case.documents %}
<h2 class="h2" id="documents">{% trans 'Documenten' %}</h2>
{% case_document_list case.documents %}
{% endif %}
{% endif %}
<p class="p">{{ case.type_description }}</p>
{% endrender_column %}
{% endrender_grid %}
{% else %}
Expand Down
6 changes: 5 additions & 1 deletion src/open_inwoner/templates/pages/product/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -123,21 +123,25 @@ <h3 class="h3" id="contact">{% trans 'Contact' %}</h3>
<h4 class="h4">{{ contact.first_name }} {{ contact.last_name }}</h4>
{% endrender_column %}

{% if contact.phonenumber %}
{% render_column span=6 %}
<span class="p">{{ contact.role|default:_('Telefoonnummer') }}</span>
{% endrender_column %}

{% render_column start=7 span=6 %}
{% link href='tel:'|add:contact.phonenumber text=contact.phonenumber primary=True %}
{% endrender_column %}
{% endif %}

{% if contact.email %}
{% render_column span=6 %}
<p class="p">{{ contact.organization|default:_('E-mail')}}</p>
{% endrender_column %}

{% render_column start=7 span=6 %}
{% link href='mailto:'|add:contact.email text=contact.email primary=True %}
{% endrender_column %}
{% endrender_column %}
{% endif %}
{% endrender_grid %}
{% endfor %}
{% endrender_notification %}
Expand Down