3
3
import logging
4
4
from collections import defaultdict
5
5
from datetime import datetime
6
+ from typing import Iterable , Protocol
6
7
7
8
from django .conf import settings
8
9
from django .contrib import messages
9
- from django .core .exceptions import ObjectDoesNotExist , PermissionDenied
10
+ from django .core .exceptions import (
11
+ ImproperlyConfigured ,
12
+ ObjectDoesNotExist ,
13
+ PermissionDenied ,
14
+ )
10
15
from django .http import (
11
16
Http404 ,
12
17
HttpRequest ,
20
25
from django .views .generic import FormView , TemplateView
21
26
22
27
from django_htmx .http import HttpResponseClientRedirect
23
- from glom import glom
24
28
from mail_editor .helpers import find_template
25
29
from view_breadcrumbs import BaseBreadcrumbMixin
26
30
from zgw_consumers .api_models .constants import RolOmschrijving
27
31
32
+ from open_inwoner .accounts .models import User
28
33
from open_inwoner .mail .service import send_contact_confirmation_mail
34
+ from open_inwoner .openklant .constants import KlantenServiceType
29
35
from open_inwoner .openklant .models import OpenKlantConfig
30
- from open_inwoner .openklant .services import eSuiteKlantenService , eSuiteVragenService
31
- from open_inwoner . openklant . wrap import (
32
- contactmoment_has_new_answer ,
33
- get_fetch_parameters ,
34
- get_kcm_answer_mapping ,
36
+ from open_inwoner .openklant .services import (
37
+ OpenKlant2Service ,
38
+ Question ,
39
+ eSuiteKlantenService ,
40
+ eSuiteVragenService ,
35
41
)
42
+ from open_inwoner .openklant .wrap import get_fetch_parameters
36
43
from open_inwoner .openzaak .api_models import Status , StatusType , Zaak
37
44
from open_inwoner .openzaak .clients import CatalogiClient , ZakenClient
38
45
from open_inwoner .openzaak .documents import (
@@ -67,6 +74,15 @@ class SimpleFile:
67
74
created : datetime | None = None
68
75
69
76
77
+ class VragenService (Protocol ):
78
+ def list_questions_for_zaak (
79
+ self ,
80
+ zaak : Zaak ,
81
+ user : User | None = None ,
82
+ ) -> Iterable [Question ]: # noqa: E704
83
+ ...
84
+
85
+
70
86
class OuterCaseDetailView (
71
87
OuterCaseAccessMixin , CommonPageMixin , BaseBreadcrumbMixin , TemplateView
72
88
):
@@ -110,6 +126,20 @@ class InnerCaseDetailView(
110
126
contact_form_class = CaseContactForm
111
127
case : Zaak | None = None
112
128
129
+ def get_service (self , service_type : KlantenServiceType ) -> VragenService | None :
130
+ if service_type == KlantenServiceType .OPENKLANT2 :
131
+ try :
132
+ return OpenKlant2Service ()
133
+ except ImproperlyConfigured :
134
+ logger .error ("OpenKlant2 configuration missing" )
135
+ if service_type == KlantenServiceType .ESUITE :
136
+ try :
137
+ return eSuiteVragenService ()
138
+ except ImproperlyConfigured :
139
+ logger .error ("eSuiteVragenService configuration missing" )
140
+ except RuntimeError :
141
+ logger .error ("Failed to build eSuiteVragenService" )
142
+
113
143
def store_statustype_mapping (self , zaaktype_identificatie ):
114
144
# Filter on ZaakType identificatie to avoid eSuite situation where one statustype
115
145
# is linked to multiple zaaktypes
@@ -151,7 +181,6 @@ def get_context_data(self, **kwargs):
151
181
self .log_access_case_detail (self .case )
152
182
153
183
openzaak_config = OpenZaakConfig .get_solo ()
154
- openklant_config = OpenKlantConfig .get_solo ()
155
184
156
185
api_group = ZGWApiGroupConfig .objects .get (pk = self .kwargs ["api_group_id" ])
157
186
zaken_client = api_group .zaken_client
@@ -162,38 +191,24 @@ def get_context_data(self, **kwargs):
162
191
self .store_statustype_mapping (self .case .zaaktype .identificatie )
163
192
self .store_resulttype_mapping (self .case .zaaktype .identificatie )
164
193
165
- # questions/E-suite contactmomenten
166
- try :
167
- service = eSuiteVragenService (config = openklant_config )
168
- except RuntimeError :
169
- logger .error ("Failed to build eSuiteVragenService" )
170
- objectcontactmomenten = []
171
- else :
172
- objectcontactmomenten = service .retrieve_objectcontactmomenten_for_zaak (
173
- self .case
174
- )
175
-
176
194
questions = []
177
- for ocm in objectcontactmomenten :
178
- question = getattr (ocm , "contactmoment" , None )
179
- if question :
180
- questions .append (question )
181
- questions .sort (key = lambda q : q .registratiedatum , reverse = True )
182
-
183
- kcm_answer_mapping = get_kcm_answer_mapping (questions , self .request .user )
184
- for question in questions :
185
- question .new_answer_available = contactmoment_has_new_answer (
186
- question , kcm_answer_mapping
195
+ if ok2_service := self .get_service (
196
+ service_type = KlantenServiceType .OPENKLANT2
197
+ ):
198
+ questions .extend (
199
+ ok2_service .list_questions_for_zaak (
200
+ self .case , user = self .request .user
201
+ )
187
202
)
188
-
189
- # filter questions
190
- openklant_config = OpenKlantConfig . get_solo ()
191
- if exclude_range := openklant_config . exclude_contactmoment_kanalen :
192
- questions = [
193
- item
194
- for item in questions
195
- if glom ( item , "kanaal" ) not in exclude_range
196
- ]
203
+ if esuite_service := self . get_service (
204
+ service_type = KlantenServiceType . ESUITE
205
+ ):
206
+ questions . extend (
207
+ esuite_service . list_questions_for_zaak (
208
+ self . case , user = self . request . user
209
+ )
210
+ )
211
+ questions . sort ( key = lambda q : q [ "registered_date" ], reverse = True )
197
212
198
213
statustypen = []
199
214
catalogi_client = api_group .catalogi_client
0 commit comments