Skip to content

Commit 4e7637c

Browse files
authored
Merge pull request #365 from maykinmedia/feature/349-selectielijst-api
[#349] Specify which Selectielijst service to use
2 parents 7b6bcf1 + 2b8877f commit 4e7637c

File tree

11 files changed

+217
-11
lines changed

11 files changed

+217
-11
lines changed

Diff for: backend/bin/docker_start.sh

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ done
2626
>&2 echo "Apply database migrations"
2727
python src/manage.py migrate
2828

29+
# Load fixtures
30+
>&2 echo "Loading fixtures"
31+
python src/manage.py loaddata default_admin_index
32+
2933
# Populate the environment variables for the frontend
3034
>&2 echo "Replace frontend env vars"
3135
/replace-envvars.sh

Diff for: backend/docs/configure/index.rst

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.. _configuration_index:
2+
3+
=================================================
4+
Configuring Open Archiefbeheer for administrators
5+
=================================================
6+
7+
.. toctree::
8+
:maxdepth: 2
9+
10+
services

Diff for: backend/docs/configure/services.rst

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
.. _configuration_services:
2+
3+
===========================
4+
External APIs configuration
5+
===========================
6+
7+
Checklist
8+
=========
9+
10+
#. Services need to be configured for:
11+
12+
* Zaken API
13+
* Catalogi API
14+
* Documenten API
15+
* Besluiten API
16+
* Selectielijst API
17+
18+
#. In the **API configuration**, specify which service should be used for the Selectielijst API.
19+
20+
Services
21+
========
22+
23+
The services can be configured under **External APIs** > **Services**.
24+
25+
API configuration
26+
=================
27+
28+
Under **External APIs** > **API configuration** you can select which service should be used to query the Selectielijst API.

Diff for: backend/docs/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Documentation
1313
.. toctree::
1414
:maxdepth: 3
1515

16+
configure/index
1617
general/index
1718
install/index
1819
developers/index

Diff for: backend/src/openarchiefbeheer/config/admin.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22

33
from solo.admin import SingletonModelAdmin
44

5-
from .models import ArchiveConfig
5+
from .models import APIConfig, ArchiveConfig
66

77

88
@admin.register(ArchiveConfig)
99
class ArchiveConfigAdmin(SingletonModelAdmin):
1010
pass
11+
12+
13+
@admin.register(APIConfig)
14+
class APIConfigAdmin(SingletonModelAdmin):
15+
pass
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Generated by Django 4.2.15 on 2024-09-19 10:23
2+
3+
from django.db import migrations, models
4+
import django.db.models.deletion
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
("zgw_consumers", "0020_service_timeout"),
11+
("config", "0002_alter_archiveconfig_zaaktypes_short_process"),
12+
]
13+
14+
operations = [
15+
migrations.CreateModel(
16+
name="APIConfig",
17+
fields=[
18+
(
19+
"id",
20+
models.AutoField(
21+
auto_created=True,
22+
primary_key=True,
23+
serialize=False,
24+
verbose_name="ID",
25+
),
26+
),
27+
(
28+
"selectielijst_api_service",
29+
models.ForeignKey(
30+
blank=True,
31+
help_text="Which service to use to query the Selectielijst API.",
32+
null=True,
33+
on_delete=django.db.models.deletion.SET_NULL,
34+
to="zgw_consumers.service",
35+
verbose_name="selectielijst API service",
36+
),
37+
),
38+
],
39+
options={
40+
"verbose_name": "API configuration",
41+
"verbose_name_plural": "API configurations",
42+
},
43+
),
44+
]

Diff for: backend/src/openarchiefbeheer/config/models.py

+18
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,21 @@ class Meta:
2424

2525
def __str__(self):
2626
return "Archive configuration"
27+
28+
29+
class APIConfig(SingletonModel):
30+
selectielijst_api_service = models.ForeignKey(
31+
to="zgw_consumers.Service",
32+
verbose_name=_("selectielijst API service"),
33+
on_delete=models.SET_NULL,
34+
null=True,
35+
blank=True,
36+
help_text=_("Which service to use to query the Selectielijst API."),
37+
)
38+
39+
class Meta:
40+
verbose_name = _("API configuration")
41+
verbose_name_plural = _("API configurations")
42+
43+
def __str__(self):
44+
return "API configuration"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
[
2+
{
3+
"model": "admin_index.appgroup",
4+
"fields": {
5+
"order": 0,
6+
"name": "External APIs",
7+
"slug": "externalapis",
8+
"models": [
9+
["zgw_consumers", "service"],
10+
["config", "apiconfig"]
11+
]
12+
}
13+
},
14+
{
15+
"model": "admin_index.appgroup",
16+
"fields": {
17+
"order": 1,
18+
"name": "Users",
19+
"slug": "users",
20+
"models": [
21+
["accounts", "user"],
22+
["accounts", "role"]
23+
]
24+
}
25+
},
26+
{
27+
"model": "admin_index.appgroup",
28+
"fields": {
29+
"order": 2,
30+
"name": "Logs",
31+
"slug": "logs",
32+
"models": [
33+
["timeline_logger", "timelinelog"]
34+
]
35+
}
36+
},
37+
{
38+
"model": "admin_index.appgroup",
39+
"fields": {
40+
"order": 3,
41+
"name": "Destruction Lists",
42+
"slug": "destructionlists",
43+
"models": [
44+
["destruction", "destructionlist"],
45+
["destruction", "destructionlistitem"],
46+
["destruction", "destructionlistassignee"]
47+
]
48+
}
49+
},
50+
{
51+
"model": "admin_index.appgroup",
52+
"fields": {
53+
"order": 4,
54+
"name": "Reviews",
55+
"slug": "reviews",
56+
"models": [
57+
["destruction", "destructionlistreview"],
58+
["destruction", "destructionlistitemreview"],
59+
["destruction", "reviewresponse"],
60+
["destruction", "reviewitemresponse"]
61+
]
62+
}
63+
},
64+
{
65+
"model": "admin_index.appgroup",
66+
"fields": {
67+
"order": 5,
68+
"name": "Cases",
69+
"slug": "cases",
70+
"models": [
71+
["zaken", "zaak"]
72+
]
73+
}
74+
}
75+
]

Diff for: backend/src/openarchiefbeheer/zaken/tests/test_tasks.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from datetime import date
2+
from unittest.mock import patch
23

34
from django.test import TestCase, TransactionTestCase, tag
45
from django.utils.translation import gettext_lazy as _
@@ -10,6 +11,7 @@
1011
from zgw_consumers.constants import APITypes
1112
from zgw_consumers.test.factories import ServiceFactory
1213

14+
from openarchiefbeheer.config.models import APIConfig
1315
from openarchiefbeheer.destruction.tests.factories import DestructionListItemFactory
1416

1517
from ..models import Zaak
@@ -355,7 +357,7 @@ def test_expanded_correctly(self, m):
355357
api_type=APITypes.zrc,
356358
api_root="http://zaken-api.nl/zaken/api/v1",
357359
)
358-
ServiceFactory.create(
360+
selectielist_service = ServiceFactory.create(
359361
api_type=APITypes.orc,
360362
api_root="https://selectielijst.openzaak.nl/api/v1/",
361363
)
@@ -369,7 +371,11 @@ def test_expanded_correctly(self, m):
369371
},
370372
)
371373

372-
retrieve_and_cache_zaken_from_openzaak()
374+
with patch(
375+
"openarchiefbeheer.zaken.utils.APIConfig.get_solo",
376+
return_value=APIConfig(selectielijst_api_service=selectielist_service),
377+
):
378+
retrieve_and_cache_zaken_from_openzaak()
373379

374380
zaak_with_resultaat = Zaak.objects.get(identificatie="ZAAK-01")
375381

Diff for: backend/src/openarchiefbeheer/zaken/tests/test_views.py

+20-7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from zgw_consumers.test.factories import ServiceFactory
1414

1515
from openarchiefbeheer.accounts.tests.factories import UserFactory
16+
from openarchiefbeheer.config.models import APIConfig
1617
from openarchiefbeheer.destruction.constants import ListItemStatus
1718
from openarchiefbeheer.destruction.tests.factories import (
1819
DestructionListFactory,
@@ -418,7 +419,7 @@ def test_not_authenticated(self):
418419

419420
@Mocker()
420421
def test_retrieve_choices(self, m):
421-
ServiceFactory.create(
422+
selectielist_service = ServiceFactory.create(
422423
api_type=APITypes.orc,
423424
api_root="http://selectielijst.nl/api/v1",
424425
)
@@ -461,7 +462,11 @@ def test_retrieve_choices(self, m):
461462
endpoint = furl(reverse("api:retrieve-selectielijstklasse-choices"))
462463
endpoint.args["zaak"] = zaak.url
463464

464-
response = self.client.get(endpoint.url)
465+
with patch(
466+
"openarchiefbeheer.zaken.utils.APIConfig.get_solo",
467+
return_value=APIConfig(selectielijst_api_service=selectielist_service),
468+
):
469+
response = self.client.get(endpoint.url)
465470

466471
self.assertEqual(response.status_code, status.HTTP_200_OK)
467472
self.assertEqual(
@@ -494,7 +499,7 @@ def test_retrieve_choices(self, m):
494499
@Mocker()
495500
def test_retrieve_choices_without_zaak(self, m):
496501
# Create a mock service
497-
ServiceFactory.create(
502+
selectielist_service = ServiceFactory.create(
498503
api_type=APITypes.orc,
499504
api_root="http://selectielijst.nl/api/v1",
500505
)
@@ -541,7 +546,11 @@ def test_retrieve_choices_without_zaak(self, m):
541546
endpoint = furl(reverse("api:retrieve-selectielijstklasse-choices"))
542547

543548
# Send the GET request
544-
response = self.client.get(endpoint.url)
549+
with patch(
550+
"openarchiefbeheer.zaken.utils.APIConfig.get_solo",
551+
return_value=APIConfig(selectielijst_api_service=selectielist_service),
552+
):
553+
response = self.client.get(endpoint.url)
545554

546555
# Validate the response
547556
self.assertEqual(response.status_code, status.HTTP_200_OK)
@@ -574,7 +583,7 @@ def test_retrieve_choices_without_zaak(self, m):
574583

575584
@Mocker()
576585
def test_response_cached(self, m):
577-
ServiceFactory.create(
586+
selectielist_service = ServiceFactory.create(
578587
api_type=APITypes.orc,
579588
api_root="http://selectielijst.nl/api/v1",
580589
)
@@ -617,7 +626,11 @@ def test_response_cached(self, m):
617626
endpoint = furl(reverse("api:retrieve-selectielijstklasse-choices"))
618627
endpoint.args["zaak"] = zaak.url
619628

620-
self.client.get(endpoint.url)
621-
self.client.get(endpoint.url)
629+
with patch(
630+
"openarchiefbeheer.zaken.utils.APIConfig.get_solo",
631+
return_value=APIConfig(selectielijst_api_service=selectielist_service),
632+
):
633+
self.client.get(endpoint.url)
634+
self.client.get(endpoint.url)
622635

623636
self.assertEqual(len(m.request_history), 1)

Diff for: backend/src/openarchiefbeheer/zaken/utils.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from zgw_consumers.models import Service
2121
from zgw_consumers.utils import PaginatedResponseData
2222

23+
from openarchiefbeheer.config.models import APIConfig
2324
from openarchiefbeheer.utils.datastructure import HashableDict
2425
from openarchiefbeheer.utils.results_store import ResultStore
2526

@@ -127,7 +128,8 @@ def format_selectielijstklasse_choice(resultaat: Resultaat) -> DropDownChoice:
127128

128129
@lru_cache
129130
def retrieve_selectielijstklasse_choices(query_params: HashableDict | None) -> list:
130-
selectielijst_service = Service.objects.filter(api_type=APITypes.orc).first()
131+
config = APIConfig.get_solo()
132+
selectielijst_service = config.selectielijst_api_service
131133
if not selectielijst_service:
132134
return []
133135

0 commit comments

Comments
 (0)