Skip to content

Commit 2cf7fdc

Browse files
committed
refactor the settings
Signed-off-by: tdruez <tdruez@aboutcode.org>
1 parent 5da71bb commit 2cf7fdc

4 files changed

Lines changed: 16 additions & 13 deletions

File tree

dejacode/settings.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -662,16 +662,10 @@ def get_fake_redis_connection(config, use_strict_redis):
662662
# django-altcha
663663
ALTCHA_HMAC_KEY = env.str("DEJACODE_ALTCHA_HMAC_KEY", default="")
664664

665-
WEBHOOK_EVENTS = [
666-
"request.added",
667-
"request.updated",
668-
"request_comment.added",
669-
"user.added_or_updated",
670-
"user.locked_out",
671-
"vulnerability.data_update",
672-
]
673665
# Provide context variables to WebhookSubscription extra_headers template values.
674-
HOOK_ENV = env.dict("HOOK_ENV", default={})
666+
# HOOK_ENV is the legacy name, kept for backward compatibility.
667+
_legacy_hook_env = env.dict("HOOK_ENV", default={})
668+
DEJACODE_WEBHOOK_ENV = env.dict("DEJACODE_WEBHOOK_ENV", default=_legacy_hook_env)
675669

676670
# Django-axes
677671
# Enable or disable Axes plugin functionality

notification/admin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@
77
#
88

99
from django import forms
10-
from django.conf import settings
1110
from django.contrib import admin
1211

1312
from dje.admin import DataspacedAdmin
1413
from dje.admin import ProhibitDataspaceLookupMixin
1514
from dje.admin import dejacode_site
1615
from dje.forms import DataspacedAdminForm
16+
from notification.models import WEBHOOK_EVENTS
1717
from notification.models import WebhookSubscription
1818

1919

2020
class WebhookSubscriptionForm(DataspacedAdminForm):
21-
EVENTS = [(event, event) for event in settings.WEBHOOK_EVENTS]
21+
EVENTS = [(event, event) for event in WEBHOOK_EVENTS]
2222

2323
class Meta:
2424
model = WebhookSubscription

notification/models.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@
2121

2222
logger = logging.getLogger("dje")
2323

24+
WEBHOOK_EVENTS = [
25+
"request.added",
26+
"request.updated",
27+
"request_comment.added",
28+
"user.added_or_updated",
29+
"user.locked_out",
30+
"vulnerability.data_update",
31+
]
32+
2433

2534
class WebhookSubscriptionQuerySet(WebhookSubscriptionQuerySetMixin, DataspacedQuerySet):
2635
pass
@@ -59,7 +68,7 @@ def dict(self):
5968

6069
def get_extra_headers(self):
6170
"""Inject `hook_env` context in headers template values."""
62-
if hook_env := settings.HOOK_ENV:
71+
if hook_env := settings.DEJACODE_WEBHOOK_ENV:
6372
hook_env_context = template.Context(hook_env)
6473
return {
6574
key: self.render_template(value, hook_env_context)

notification/tests/test_models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,5 @@ def test_webhook_subscription_get_extra_headers(self):
4444
self.assertEqual(expected, self.webhook.get_extra_headers())
4545

4646
expected = {"Header": "some_value"}
47-
with override_settings(HOOK_ENV={"ENV_VALUE": "some_value"}):
47+
with override_settings(DEJACODE_WEBHOOK_ENV={"ENV_VALUE": "some_value"}):
4848
self.assertEqual(expected, self.webhook.get_extra_headers())

0 commit comments

Comments
 (0)