Skip to content

Commit

Permalink
🚧 [#4788] ConfigurationStep for Objects API registration config
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenbal committed Nov 12, 2024
1 parent c52c208 commit 02a25a2
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 2 deletions.
4 changes: 3 additions & 1 deletion bin/setup_configuration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ set -e
${SCRIPTPATH}/wait_for_db.sh

src/manage.py migrate
src/manage.py setup_configuration --no-selftest --yaml-file data/services.yaml
src/manage.py setup_configuration --no-selftest \
--yaml-file data/services.yaml \
--yaml-file data/objects_api.yaml \
14 changes: 14 additions & 0 deletions docker/data/objects_api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
OBJECTS_API_CONFIG_ENABLE: True
OBJECTS_API:
groups:
- name: Config 1
objects_service_slug: objecten-test
objecttypes_service_slug: objecttypen-test
drc_service_slug: documenten-test
catalogi_service_slug: catalogi-test
catalogue_domain: "AAAAA"
catalogue_rsin: "000000000"
organisatie_rsin: "000000000"
# iot_submission_report:
# iot_submission_csv:
# iot_attachment:
14 changes: 14 additions & 0 deletions docker/data/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,17 @@ ZGW_CONSUMERS:
auth_type: api_key
header_key: Authorization
header_value: Token bar
- slug: documenten-test
label: Documenten API test
api_root: https://httpstat.us/200
api_type: orc
auth_type: api_key
header_key: Authorization
header_value: Token bar
- slug: catalogi-test
label: Catalogi API test
api_root: https://httpstat.us/201
api_type: orc
auth_type: api_key
header_key: Authorization
header_value: Token bar
3 changes: 2 additions & 1 deletion src/openforms/conf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1225,5 +1225,6 @@


SETUP_CONFIGURATION_STEPS = [
"zgw_consumers.contrib.setup_configuration.steps.ServiceConfigurationStep"
"zgw_consumers.contrib.setup_configuration.steps.ServiceConfigurationStep",
"openforms.config.setup_configuration.steps.ObjectsAPIConfigurationStep",
]
Empty file.
44 changes: 44 additions & 0 deletions src/openforms/config/setup_configuration/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from django_setup_configuration.models import ConfigurationModel, DjangoModelRef
from pydantic import Field

Check warning on line 2 in src/openforms/config/setup_configuration/models.py

View check run for this annotation

Codecov / codecov/patch

src/openforms/config/setup_configuration/models.py#L1-L2

Added lines #L1 - L2 were not covered by tests

from openforms.contrib.objects_api.models import ObjectsAPIGroupConfig

Check warning on line 4 in src/openforms/config/setup_configuration/models.py

View check run for this annotation

Codecov / codecov/patch

src/openforms/config/setup_configuration/models.py#L4

Added line #L4 was not covered by tests


class SingleObjectsAPIGroupConfigModel(ConfigurationModel):
objects_service_slug: str = DjangoModelRef(ObjectsAPIGroupConfig, "objects_service")
objecttypes_service_slug: str = DjangoModelRef(

Check warning on line 9 in src/openforms/config/setup_configuration/models.py

View check run for this annotation

Codecov / codecov/patch

src/openforms/config/setup_configuration/models.py#L7-L9

Added lines #L7 - L9 were not covered by tests
ObjectsAPIGroupConfig, "objecttypes_service"
)
drc_service_slug: str = DjangoModelRef(ObjectsAPIGroupConfig, "drc_service")
catalogi_service_slug: str = DjangoModelRef(

Check warning on line 13 in src/openforms/config/setup_configuration/models.py

View check run for this annotation

Codecov / codecov/patch

src/openforms/config/setup_configuration/models.py#L12-L13

Added lines #L12 - L13 were not covered by tests
ObjectsAPIGroupConfig, "catalogi_service"
)
catalogue_domain: str = DjangoModelRef(

Check warning on line 16 in src/openforms/config/setup_configuration/models.py

View check run for this annotation

Codecov / codecov/patch

src/openforms/config/setup_configuration/models.py#L16

Added line #L16 was not covered by tests
ObjectsAPIGroupConfig, "catalogue_domain", default=""
)
catalogue_rsin: str = DjangoModelRef(

Check warning on line 19 in src/openforms/config/setup_configuration/models.py

View check run for this annotation

Codecov / codecov/patch

src/openforms/config/setup_configuration/models.py#L19

Added line #L19 was not covered by tests
ObjectsAPIGroupConfig, "catalogue_rsin", default=""
)
organisatie_rsin: str = DjangoModelRef(

Check warning on line 22 in src/openforms/config/setup_configuration/models.py

View check run for this annotation

Codecov / codecov/patch

src/openforms/config/setup_configuration/models.py#L22

Added line #L22 was not covered by tests
ObjectsAPIGroupConfig, "organisatie_rsin", default=""
)
iot_submission_report: str = DjangoModelRef(

Check warning on line 25 in src/openforms/config/setup_configuration/models.py

View check run for this annotation

Codecov / codecov/patch

src/openforms/config/setup_configuration/models.py#L25

Added line #L25 was not covered by tests
ObjectsAPIGroupConfig, "iot_submission_report", default=""
)
iot_submission_csv: str = DjangoModelRef(

Check warning on line 28 in src/openforms/config/setup_configuration/models.py

View check run for this annotation

Codecov / codecov/patch

src/openforms/config/setup_configuration/models.py#L28

Added line #L28 was not covered by tests
ObjectsAPIGroupConfig, "iot_submission_csv", default=""
)
iot_attachment: str = DjangoModelRef(

Check warning on line 31 in src/openforms/config/setup_configuration/models.py

View check run for this annotation

Codecov / codecov/patch

src/openforms/config/setup_configuration/models.py#L31

Added line #L31 was not covered by tests
ObjectsAPIGroupConfig, "iot_attachment", default=""
)

class Meta:
django_model_refs = {

Check warning on line 36 in src/openforms/config/setup_configuration/models.py

View check run for this annotation

Codecov / codecov/patch

src/openforms/config/setup_configuration/models.py#L35-L36

Added lines #L35 - L36 were not covered by tests
ObjectsAPIGroupConfig: [
"name",
]
}


class ObjectsAPIGroupConfigModel(ConfigurationModel):
groups: list[SingleObjectsAPIGroupConfigModel] = Field(default_factory=list)

Check warning on line 44 in src/openforms/config/setup_configuration/models.py

View check run for this annotation

Codecov / codecov/patch

src/openforms/config/setup_configuration/models.py#L43-L44

Added lines #L43 - L44 were not covered by tests
50 changes: 50 additions & 0 deletions src/openforms/config/setup_configuration/steps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from django_setup_configuration.configuration import BaseConfigurationStep
from zgw_consumers.models import Service

Check warning on line 2 in src/openforms/config/setup_configuration/steps.py

View check run for this annotation

Codecov / codecov/patch

src/openforms/config/setup_configuration/steps.py#L1-L2

Added lines #L1 - L2 were not covered by tests

from openforms.contrib.objects_api.models import ObjectsAPIGroupConfig

Check warning on line 4 in src/openforms/config/setup_configuration/steps.py

View check run for this annotation

Codecov / codecov/patch

src/openforms/config/setup_configuration/steps.py#L4

Added line #L4 was not covered by tests

from .models import ObjectsAPIGroupConfigModel

Check warning on line 6 in src/openforms/config/setup_configuration/steps.py

View check run for this annotation

Codecov / codecov/patch

src/openforms/config/setup_configuration/steps.py#L6

Added line #L6 was not covered by tests


class ObjectsAPIConfigurationStep(BaseConfigurationStep[ObjectsAPIGroupConfigModel]):

Check warning on line 9 in src/openforms/config/setup_configuration/steps.py

View check run for this annotation

Codecov / codecov/patch

src/openforms/config/setup_configuration/steps.py#L9

Added line #L9 was not covered by tests
"""
Configure admin login via OpenID Connect
"""

verbose_name = "Configuration to set up Objects API registration backend services"
config_model = ObjectsAPIGroupConfigModel
namespace = "OBJECTS_API"
enable_setting = "OBJECTS_API_CONFIG_ENABLE"

Check warning on line 17 in src/openforms/config/setup_configuration/steps.py

View check run for this annotation

Codecov / codecov/patch

src/openforms/config/setup_configuration/steps.py#L14-L17

Added lines #L14 - L17 were not covered by tests

def is_configured(self, model) -> bool:
names = [config.name for config in model.groups]
return ObjectsAPIGroupConfig.objects.filter(name__in=names).count() == len(

Check warning on line 21 in src/openforms/config/setup_configuration/steps.py

View check run for this annotation

Codecov / codecov/patch

src/openforms/config/setup_configuration/steps.py#L19-L21

Added lines #L19 - L21 were not covered by tests
names
)

def execute(self, model):

Check warning on line 25 in src/openforms/config/setup_configuration/steps.py

View check run for this annotation

Codecov / codecov/patch

src/openforms/config/setup_configuration/steps.py#L25

Added line #L25 was not covered by tests
for config in model.groups:
# TODO add proper error handling for service.get and optimize queries?
ObjectsAPIGroupConfig.objects.update_or_create(

Check warning on line 28 in src/openforms/config/setup_configuration/steps.py

View check run for this annotation

Codecov / codecov/patch

src/openforms/config/setup_configuration/steps.py#L28

Added line #L28 was not covered by tests
name=config.name,
defaults={
"objects_service": Service.objects.get(
slug=config.objects_service_slug
),
"objecttypes_service": Service.objects.get(
slug=config.objecttypes_service_slug
),
"drc_service": Service.objects.get(slug=config.drc_service_slug),
"catalogi_service": Service.objects.get(
slug=config.catalogi_service_slug
),
"catalogue_domain": config.catalogue_domain,
"catalogue_rsin": config.catalogue_rsin,
"organisatie_rsin": config.organisatie_rsin,
"iot_submission_report": config.iot_submission_report,
"iot_submission_csv": config.iot_submission_csv,
"iot_attachment": config.iot_attachment,
},
)

def validate_result(self, model) -> None: ...

0 comments on commit 02a25a2

Please sign in to comment.