-
-
Notifications
You must be signed in to change notification settings - Fork 225
refactor(settings): standardize Constance env overrides to CONSTANCE_ prefix DEV-1976 #7230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
3847781
3f18e14
078be15
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -190,6 +190,24 @@ | |||||||||||||||||
| # must use `constance.config.THE_SETTING` instead of | ||||||||||||||||||
| # `django.conf.settings.THE_SETTING` | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| def _constance_env(getter, new_key, deprecated_key, default): | ||||||||||||||||||
| """ | ||||||||||||||||||
| Read a Constance override from the `CONSTANCE_`-prefixed environment | ||||||||||||||||||
| variable, falling back to its deprecated (unprefixed / `KOBO_`) name. | ||||||||||||||||||
|
|
||||||||||||||||||
| Emit a `DeprecationWarning` when the deprecated name is still set so | ||||||||||||||||||
| deployments know to migrate to the `CONSTANCE_` prefix. | ||||||||||||||||||
| """ | ||||||||||||||||||
| if deprecated_key in os.environ: | ||||||||||||||||||
| warnings.warn( | ||||||||||||||||||
| f'{deprecated_key} is renamed {new_key}, ' | ||||||||||||||||||
| f'update the environment variable.', | ||||||||||||||||||
| DeprecationWarning, | ||||||||||||||||||
| ) | ||||||||||||||||||
| return getter(new_key, getter(deprecated_key, default)) | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| CONSTANCE_CONFIG = { | ||||||||||||||||||
| 'REGISTRATION_OPEN': ( | ||||||||||||||||||
| True, | ||||||||||||||||||
|
|
@@ -225,21 +243,39 @@ | |||||||||||||||||
| 'in the user interface', | ||||||||||||||||||
| ), | ||||||||||||||||||
| 'SUPPORT_EMAIL': ( | ||||||||||||||||||
| env.str('KOBO_SUPPORT_EMAIL', env.str('DEFAULT_FROM_EMAIL', 'help@kobotoolbox.org')), | ||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's not break the compatibility here. For any deprecated variable. Please log a Deprecation warning instance. Lines 2007 to 2014 in 39416ad
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that's way better! Done |
||||||||||||||||||
| _constance_env( | ||||||||||||||||||
| env.str, | ||||||||||||||||||
| 'CONSTANCE_SUPPORT_EMAIL', | ||||||||||||||||||
| 'KOBO_SUPPORT_EMAIL', | ||||||||||||||||||
| env.str('DEFAULT_FROM_EMAIL', 'help@kobotoolbox.org'), | ||||||||||||||||||
| ), | ||||||||||||||||||
| 'Email address for users to contact, e.g. when they encounter ' | ||||||||||||||||||
| 'unhandled errors in the application', | ||||||||||||||||||
| ), | ||||||||||||||||||
| 'SUPPORT_URL': ( | ||||||||||||||||||
| env.str('KOBO_SUPPORT_URL', 'https://support.kobotoolbox.org/'), | ||||||||||||||||||
| _constance_env( | ||||||||||||||||||
| env.str, | ||||||||||||||||||
| 'CONSTANCE_SUPPORT_URL', | ||||||||||||||||||
| 'KOBO_SUPPORT_URL', | ||||||||||||||||||
| 'https://support.kobotoolbox.org/', | ||||||||||||||||||
| ), | ||||||||||||||||||
| 'URL for "KoboToolbox Help Center"', | ||||||||||||||||||
| ), | ||||||||||||||||||
| 'ACADEMY_URL': ( | ||||||||||||||||||
| env.str('KOBO_ACADEMY_URL', 'https://academy.kobotoolbox.org/'), | ||||||||||||||||||
| _constance_env( | ||||||||||||||||||
| env.str, | ||||||||||||||||||
| 'CONSTANCE_ACADEMY_URL', | ||||||||||||||||||
| 'KOBO_ACADEMY_URL', | ||||||||||||||||||
| 'https://academy.kobotoolbox.org/', | ||||||||||||||||||
| ), | ||||||||||||||||||
| 'URL for "KoboToolbox Community Forum"', | ||||||||||||||||||
| ), | ||||||||||||||||||
| 'COMMUNITY_URL': ( | ||||||||||||||||||
| env.str( | ||||||||||||||||||
| 'KOBO_COMMUNITY_URL', 'https://community.kobotoolbox.org/' | ||||||||||||||||||
| _constance_env( | ||||||||||||||||||
| env.str, | ||||||||||||||||||
| 'CONSTANCE_COMMUNITY_URL', | ||||||||||||||||||
| 'KOBO_COMMUNITY_URL', | ||||||||||||||||||
| 'https://community.kobotoolbox.org/', | ||||||||||||||||||
| ), | ||||||||||||||||||
| 'URL for "KoboToolbox Community Forum"', | ||||||||||||||||||
| ), | ||||||||||||||||||
|
|
@@ -328,7 +364,12 @@ | |||||||||||||||||
| 'Require MFA for superusers with a usable password', | ||||||||||||||||||
| ), | ||||||||||||||||||
| 'USAGE_LIMIT_ENFORCEMENT': ( | ||||||||||||||||||
| env.bool('USAGE_LIMIT_ENFORCEMENT', False), | ||||||||||||||||||
| _constance_env( | ||||||||||||||||||
| env.bool, | ||||||||||||||||||
| 'CONSTANCE_USAGE_LIMIT_ENFORCEMENT', | ||||||||||||||||||
| 'USAGE_LIMIT_ENFORCEMENT', | ||||||||||||||||||
| False, | ||||||||||||||||||
| ), | ||||||||||||||||||
| 'For Stripe-enabled instances, determines whether usage limits will be enforced' | ||||||||||||||||||
| 'by blocking submissions/NLP actions or deleting stored files.', | ||||||||||||||||||
| ), | ||||||||||||||||||
|
|
@@ -345,10 +386,6 @@ | |||||||||||||||||
| ' the operations API. ' | ||||||||||||||||||
| ) | ||||||||||||||||||
| ), | ||||||||||||||||||
| # We are adopting the `CONSTANCE_` prefix as the new standard for all env | ||||||||||||||||||
| # variables that override Constance defaults. Legacy variables (e.g., KOBO_*) | ||||||||||||||||||
| # will be deprecated and migrated to this new pattern after the upcoming | ||||||||||||||||||
| # migration to Constance 4.x | ||||||||||||||||||
| 'ASR_MT_GOOGLE_PROJECT_ID': ( | ||||||||||||||||||
| env.str('CONSTANCE_ASR_MT_GOOGLE_PROJECT_ID', 'kobo-asr-mt'), | ||||||||||||||||||
| 'ID of the Google Cloud project used to access ASR/MT APIs', | ||||||||||||||||||
|
|
||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you mind to create an utility file where this could be moved out the settings files.
You can also move other helpers present in that file (e.g.:
dj_stripe_request_callback_method)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 078be15 β moved
constance_env(renamed from_constance_env) anddj_stripe_request_callback_methodintokobo/settings/utils.py. Also updated the PR description to match the current backward-compatible approach.