From cd71993cd708ef0a785ffe93c4821b8d3c8daba3 Mon Sep 17 00:00:00 2001 From: Anna Shamray Date: Mon, 23 Dec 2024 11:37:09 +0100 Subject: [PATCH] :sparles: add configuration step for Applicatie model --- .../contrib/setup_configuration/models.py | 12 +++++++++ .../contrib/setup_configuration/steps.py | 25 ++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/vng_api_common/contrib/setup_configuration/models.py b/vng_api_common/contrib/setup_configuration/models.py index ad96049e..978ebd0f 100644 --- a/vng_api_common/contrib/setup_configuration/models.py +++ b/vng_api_common/contrib/setup_configuration/models.py @@ -1,6 +1,7 @@ from django_setup_configuration.models import ConfigurationModel from pydantic import Field +from vng_api_common.authorizations.models import Applicatie from vng_api_common.models import JWTSecret @@ -16,3 +17,14 @@ class Meta: class JWTSecretsConfigurationModel(ConfigurationModel): items: list[SingleJWTSecretConfigurationModel] = Field(default_factory=list) + + +class SingleApplicatieConfigurationModel(ConfigurationModel): + class Meta: + django_model_refs = { + Applicatie: ["uuid", "client_ids", "label", "heeft_alle_autorisaties"] + } + + +class ApplicatieConfigurationModel(ConfigurationModel): + items: list[SingleApplicatieConfigurationModel] = Field(default_factory=list) diff --git a/vng_api_common/contrib/setup_configuration/steps.py b/vng_api_common/contrib/setup_configuration/steps.py index a6bf2a7b..6a702ce7 100644 --- a/vng_api_common/contrib/setup_configuration/steps.py +++ b/vng_api_common/contrib/setup_configuration/steps.py @@ -1,8 +1,9 @@ from django_setup_configuration.configuration import BaseConfigurationStep +from vng_api_common.authorizations.models import Applicatie from vng_api_common.models import JWTSecret -from .models import JWTSecretsConfigurationModel +from .models import ApplicatieConfigurationModel, JWTSecretsConfigurationModel class JWTSecretsConfigurationStep(BaseConfigurationStep[JWTSecretsConfigurationModel]): @@ -21,3 +22,25 @@ def execute(self, model: JWTSecretsConfigurationModel): identifier=config.identifier, defaults={"secret": config.secret}, ) + + +class ApplicatieConfigurationStep(BaseConfigurationStep[ApplicatieConfigurationModel]): + """ + Configure Applicatie used for authorization + """ + + verbose_name = "Configuration to create applicaties" + config_model = ApplicatieConfigurationModel + namespace = "vng_api_common_applicaties" + enable_setting = "vng_api_common_applicaties_config_enable" + + def execute(self, model: ApplicatieConfigurationModel): + for config in model.items: + Applicatie.objects.update_or_create( + uuid=config.uuid, + defaults={ + "client_ids": config.client_ids, + "label": config.label, + "heeft_alle_autorisaties": config.heeft_alle_autorisaties, + }, + )