-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ [#200] Refactor ConfigurationSteps for new setup-config version
several steps have been moved to their respective libraries
- Loading branch information
Showing
5 changed files
with
50 additions
and
233 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
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,20 @@ | ||
from django.contrib.sites.models import Site | ||
|
||
from django_setup_configuration.fields import DjangoModelRef | ||
from django_setup_configuration.models import ConfigurationModel | ||
from pydantic import Field | ||
from vng_api_common.authorizations.models import AuthorizationsConfig | ||
|
||
|
||
class AuthorizationsConfigModel(ConfigurationModel): | ||
authorizations_api_service_identifier: str = DjangoModelRef( | ||
AuthorizationsConfig, "authorizations_api_service" | ||
) | ||
|
||
|
||
class SiteConfigModel(ConfigurationModel): | ||
organization: str = Field() | ||
"""The name of the organization that owns this Open Notificaties instance""" | ||
|
||
class Meta: | ||
django_model_refs = {Site: ("domain",)} |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,41 +1,24 @@ | ||
from django.conf import settings | ||
from django.contrib.sites.models import Site | ||
from django.urls import reverse | ||
|
||
import requests | ||
from django_setup_configuration.configuration import BaseConfigurationStep | ||
from django_setup_configuration.exceptions import SelfTestFailed | ||
|
||
from nrc.utils import build_absolute_url | ||
from .models import SiteConfigModel | ||
|
||
|
||
class SiteConfigurationStep(BaseConfigurationStep): | ||
class SiteConfigurationStep(BaseConfigurationStep[SiteConfigModel]): | ||
""" | ||
Configure the application site/domain. | ||
**NOTE:** Site configuration will be depreciated | ||
""" | ||
|
||
verbose_name = "Site Configuration" | ||
required_settings = ["OPENNOTIFICATIES_DOMAIN", "OPENNOTIFICATIES_ORGANIZATION"] | ||
enable_setting = "SITES_CONFIG_ENABLE" | ||
config_model = SiteConfigModel | ||
namespace = "site_config" | ||
enable_setting = "site_config_enable" | ||
|
||
def is_configured(self) -> bool: | ||
def execute(self, model: SiteConfigModel) -> None: | ||
site = Site.objects.get_current() | ||
return site.domain == settings.OPENNOTIFICATIES_DOMAIN | ||
|
||
def configure(self): | ||
site = Site.objects.get_current() | ||
site.domain = settings.OPENNOTIFICATIES_DOMAIN | ||
site.name = ( | ||
f"Open Notificaties {settings.OPENNOTIFICATIES_ORGANIZATION}".strip() | ||
) | ||
site.domain = model.domain | ||
site.name = f"Open Notificaties {model.organization}".strip() | ||
site.save() | ||
|
||
def test_configuration(self): | ||
full_url = build_absolute_url(reverse("home")) | ||
try: | ||
response = requests.get(full_url) | ||
response.raise_for_status() | ||
except requests.RequestException as exc: | ||
raise SelfTestFailed(f"Could not access home page at '{full_url}'") from exc |