-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🚧 [#4788] ConfigurationStep for Objects API registration config
- Loading branch information
Showing
7 changed files
with
127 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
from openforms.contrib.objects_api.models import ObjectsAPIGroupConfig | ||
|
||
|
||
class SingleObjectsAPIGroupConfigModel(ConfigurationModel): | ||
objects_service_slug: str = DjangoModelRef(ObjectsAPIGroupConfig, "objects_service") | ||
objecttypes_service_slug: str = DjangoModelRef( | ||
ObjectsAPIGroupConfig, "objecttypes_service" | ||
) | ||
drc_service_slug: str = DjangoModelRef(ObjectsAPIGroupConfig, "drc_service") | ||
catalogi_service_slug: str = DjangoModelRef( | ||
ObjectsAPIGroupConfig, "catalogi_service" | ||
) | ||
catalogue_domain: str = DjangoModelRef( | ||
ObjectsAPIGroupConfig, "catalogue_domain", default="" | ||
) | ||
catalogue_rsin: str = DjangoModelRef( | ||
ObjectsAPIGroupConfig, "catalogue_rsin", default="" | ||
) | ||
organisatie_rsin: str = DjangoModelRef( | ||
ObjectsAPIGroupConfig, "organisatie_rsin", default="" | ||
) | ||
iot_submission_report: str = DjangoModelRef( | ||
ObjectsAPIGroupConfig, "iot_submission_report", default="" | ||
) | ||
iot_submission_csv: str = DjangoModelRef( | ||
ObjectsAPIGroupConfig, "iot_submission_csv", default="" | ||
) | ||
iot_attachment: str = DjangoModelRef( | ||
ObjectsAPIGroupConfig, "iot_attachment", default="" | ||
) | ||
|
||
class Meta: | ||
django_model_refs = { | ||
ObjectsAPIGroupConfig: [ | ||
"name", | ||
] | ||
} | ||
|
||
|
||
class ObjectsAPIGroupConfigModel(ConfigurationModel): | ||
groups: list[SingleObjectsAPIGroupConfigModel] = Field(default_factory=list) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
from openforms.contrib.objects_api.models import ObjectsAPIGroupConfig | ||
|
||
from .models import ObjectsAPIGroupConfigModel | ||
|
||
|
||
class ObjectsAPIConfigurationStep(BaseConfigurationStep[ObjectsAPIGroupConfigModel]): | ||
""" | ||
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" | ||
|
||
def is_configured(self, model) -> bool: | ||
names = [config.name for config in model.groups] | ||
return ObjectsAPIGroupConfig.objects.filter(name__in=names).count() == len( | ||
names | ||
) | ||
|
||
def execute(self, model): | ||
for config in model.groups: | ||
# TODO add proper error handling for service.get and optimize queries? | ||
ObjectsAPIGroupConfig.objects.update_or_create( | ||
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: ... |