Skip to content

Commit

Permalink
:sparles: add configuration step for Applicatie model
Browse files Browse the repository at this point in the history
  • Loading branch information
annashamray committed Dec 23, 2024
1 parent 684b6b9 commit cd71993
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
12 changes: 12 additions & 0 deletions vng_api_common/contrib/setup_configuration/models.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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)
25 changes: 24 additions & 1 deletion vng_api_common/contrib/setup_configuration/steps.py
Original file line number Diff line number Diff line change
@@ -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]):
Expand All @@ -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,
},
)

0 comments on commit cd71993

Please sign in to comment.