Add a system check for WWW_AUTHENTICATE_BEHAVIOR setting

This commit is contained in:
Roni Choudhury 2024-01-29 13:21:33 -05:00
parent 8c23de27e8
commit 525979e343
2 changed files with 21 additions and 1 deletions

View File

@ -8,3 +8,4 @@ class RestFrameworkConfig(AppConfig):
def ready(self):
# Add System checks
from .checks import pagination_system_check # NOQA
from .checks import www_authenticate_behavior_setting_check # NOQA

View File

@ -1,4 +1,4 @@
from django.core.checks import Tags, Warning, register
from django.core.checks import Tags, Error, Warning, register
@register(Tags.compatibility)
@ -19,3 +19,22 @@ def pagination_system_check(app_configs, **kwargs):
)
)
return errors
@register(Tags.compatibility)
def www_authenticate_behavior_setting_check(app_configs, **kwargs):
errors = []
# WWW_AUTHENTICATE_BEHAVIOR setting must be 'first' or 'all'
from rest_framework.settings import api_settings
setting = api_settings.WWW_AUTHENTICATE_BEHAVIOR
if setting not in ['first', 'all']:
errors.append(
Error(
"The rest_framework setting WWW_AUTHENTICATE_BEHAVIOR must be either "
f"'first' or 'all' (it is currently set to '{setting}').",
hint="Set WWW_AUTHENTICATE_BEHAVIOR to either 'first' or 'all', "
"or leave it unset (the default value is 'first').",
id="rest_framework.E001",
)
)
return errors