/usr/lib/python3/dist-packages/hijack/checks.py is in python3-django-hijack 2.0.7-2ubuntu3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | # -*- coding: utf-8 -*-
from django.core.checks import Error, Warning, register
from django.conf.global_settings import AUTH_USER_MODEL as default_auth_user_model
from django.conf import settings
from django.contrib.admin.views.decorators import staff_member_required
from compat import import_string
from hijack import settings as hijack_settings
def check_display_admin_button_with_custom_user_model(app_configs, **kwargs):
warnings = []
if hijack_settings.HIJACK_DISPLAY_ADMIN_BUTTON \
and settings.AUTH_USER_MODEL != default_auth_user_model:
warnings.append(
Warning(
'Setting HIJACK_DISPLAY_ADMIN_BUTTON, which is True by default, '
'does not work with a custom user model. '
'Mix HijackUserAdminMixin into your custom UserAdmin or set HIJACK_DISPLAY_ADMIN_BUTTON to False.',
hint=None,
obj=settings.AUTH_USER_MODEL,
id='hijack.W001',
)
)
return warnings
def check_legacy_settings(app_configs, **kwargs):
warnings = []
for setting in hijack_settings.SETTINGS:
legacy_name = setting['legacy_name']
if legacy_name and hasattr(settings, legacy_name):
warnings.append(
Warning(
'Deprecation warning: Setting "%s" has been renamed to "%s"'
% (legacy_name, setting['name']),
hint=None,
obj=None,
id='hijack.W002',
)
)
return warnings
def check_url_allowed_attributes(app_configs, **kwargs):
errors = []
required_attributes = [
'user_id',
'email',
'username',
]
set_attributes = hijack_settings.HIJACK_URL_ALLOWED_ATTRIBUTES
if not any(attribute in set_attributes for attribute in required_attributes):
errors.append(
Error(
'Setting HIJACK_URL_ALLOWED_ATTRIBUTES needs to be subset of (%s)'
% ', '.join(required_attributes),
hint=None,
obj=set_attributes,
id='hijack.E001',
)
)
return errors
def check_custom_authorization_check_importable(app_configs, **kwargs):
errors = []
authorization_check = hijack_settings.HIJACK_AUTHORIZATION_CHECK
try:
if authorization_check != staff_member_required:
import_string(authorization_check)
except ImportError:
errors.append(
Error(
'Setting HIJACK_AUTHORIZATION_CHECK cannot be imported',
hint=None,
obj=authorization_check,
id='hijack.E002',
)
)
return errors
def check_hijack_decorator_importable(app_configs, **kwargs):
errors = []
decorator = hijack_settings.HIJACK_DECORATOR
try:
if decorator != 'django.contrib.admin.views.decorators.staff_member_required':
import_string(decorator)
except ImportError:
errors.append(
Error(
'Setting HIJACK_DECORATOR cannot be imported',
hint=None,
obj=decorator,
id='hijack.E003',
)
)
return errors
def check_staff_authorization_settings(app_configs, **kwargs):
errors = []
if hijack_settings.HIJACK_AUTHORIZE_STAFF_TO_HIJACK_STAFF and not hijack_settings.HIJACK_AUTHORIZE_STAFF:
errors.append(
Error(
'Setting HIJACK_AUTHORIZE_STAFF_TO_HIJACK_STAFF may not be True if HIJACK_AUTHORIZE_STAFF is False.',
hint=None,
obj=None,
id='hijack.E004',
)
)
return errors
def register_checks():
for check in [
check_display_admin_button_with_custom_user_model,
check_legacy_settings,
check_url_allowed_attributes,
check_custom_authorization_check_importable,
check_hijack_decorator_importable,
check_staff_authorization_settings,
]:
register(check)
|