测试gitnore
This commit is contained in:
@@ -12,7 +12,7 @@ def check_user_model(app_configs=None, **kwargs):
|
||||
if app_configs is None:
|
||||
cls = apps.get_model(settings.AUTH_USER_MODEL)
|
||||
else:
|
||||
app_label, model_name = settings.AUTH_USER_MODEL.split(".")
|
||||
app_label, model_name = settings.AUTH_USER_MODEL.split('.')
|
||||
for app_config in app_configs:
|
||||
if app_config.label == app_label:
|
||||
cls = app_config.get_model(model_name)
|
||||
@@ -31,7 +31,7 @@ def check_user_model(app_configs=None, **kwargs):
|
||||
checks.Error(
|
||||
"'REQUIRED_FIELDS' must be a list or tuple.",
|
||||
obj=cls,
|
||||
id="auth.E001",
|
||||
id='auth.E001',
|
||||
)
|
||||
)
|
||||
|
||||
@@ -47,7 +47,7 @@ def check_user_model(app_configs=None, **kwargs):
|
||||
% (cls.USERNAME_FIELD, cls.USERNAME_FIELD)
|
||||
),
|
||||
obj=cls,
|
||||
id="auth.E002",
|
||||
id='auth.E002',
|
||||
)
|
||||
)
|
||||
|
||||
@@ -56,49 +56,47 @@ def check_user_model(app_configs=None, **kwargs):
|
||||
constraint.fields == (cls.USERNAME_FIELD,)
|
||||
for constraint in cls._meta.total_unique_constraints
|
||||
):
|
||||
if settings.AUTHENTICATION_BACKENDS == [
|
||||
"django.contrib.auth.backends.ModelBackend"
|
||||
]:
|
||||
if (settings.AUTHENTICATION_BACKENDS ==
|
||||
['django.contrib.auth.backends.ModelBackend']):
|
||||
errors.append(
|
||||
checks.Error(
|
||||
"'%s.%s' must be unique because it is named as the "
|
||||
"'USERNAME_FIELD'." % (cls._meta.object_name, cls.USERNAME_FIELD),
|
||||
"'%s.%s' must be unique because it is named as the 'USERNAME_FIELD'." % (
|
||||
cls._meta.object_name, cls.USERNAME_FIELD
|
||||
),
|
||||
obj=cls,
|
||||
id="auth.E003",
|
||||
id='auth.E003',
|
||||
)
|
||||
)
|
||||
else:
|
||||
errors.append(
|
||||
checks.Warning(
|
||||
"'%s.%s' is named as the 'USERNAME_FIELD', but it is not unique."
|
||||
% (cls._meta.object_name, cls.USERNAME_FIELD),
|
||||
hint=(
|
||||
"Ensure that your authentication backend(s) can handle "
|
||||
"non-unique usernames."
|
||||
"'%s.%s' is named as the 'USERNAME_FIELD', but it is not unique." % (
|
||||
cls._meta.object_name, cls.USERNAME_FIELD
|
||||
),
|
||||
hint='Ensure that your authentication backend(s) can handle non-unique usernames.',
|
||||
obj=cls,
|
||||
id="auth.W004",
|
||||
id='auth.W004',
|
||||
)
|
||||
)
|
||||
|
||||
if isinstance(cls().is_anonymous, MethodType):
|
||||
errors.append(
|
||||
checks.Critical(
|
||||
"%s.is_anonymous must be an attribute or property rather than "
|
||||
"a method. Ignoring this is a security issue as anonymous "
|
||||
"users will be treated as authenticated!" % cls,
|
||||
'%s.is_anonymous must be an attribute or property rather than '
|
||||
'a method. Ignoring this is a security issue as anonymous '
|
||||
'users will be treated as authenticated!' % cls,
|
||||
obj=cls,
|
||||
id="auth.C009",
|
||||
id='auth.C009',
|
||||
)
|
||||
)
|
||||
if isinstance(cls().is_authenticated, MethodType):
|
||||
errors.append(
|
||||
checks.Critical(
|
||||
"%s.is_authenticated must be an attribute or property rather "
|
||||
"than a method. Ignoring this is a security issue as anonymous "
|
||||
"users will be treated as authenticated!" % cls,
|
||||
'%s.is_authenticated must be an attribute or property rather '
|
||||
'than a method. Ignoring this is a security issue as anonymous '
|
||||
'users will be treated as authenticated!' % cls,
|
||||
obj=cls,
|
||||
id="auth.C010",
|
||||
id='auth.C010',
|
||||
)
|
||||
)
|
||||
return errors
|
||||
@@ -108,13 +106,11 @@ def check_models_permissions(app_configs=None, **kwargs):
|
||||
if app_configs is None:
|
||||
models = apps.get_models()
|
||||
else:
|
||||
models = chain.from_iterable(
|
||||
app_config.get_models() for app_config in app_configs
|
||||
)
|
||||
models = chain.from_iterable(app_config.get_models() for app_config in app_configs)
|
||||
|
||||
Permission = apps.get_model("auth", "Permission")
|
||||
permission_name_max_length = Permission._meta.get_field("name").max_length
|
||||
permission_codename_max_length = Permission._meta.get_field("codename").max_length
|
||||
Permission = apps.get_model('auth', 'Permission')
|
||||
permission_name_max_length = Permission._meta.get_field('name').max_length
|
||||
permission_codename_max_length = Permission._meta.get_field('codename').max_length
|
||||
errors = []
|
||||
|
||||
for model in models:
|
||||
@@ -123,28 +119,27 @@ def check_models_permissions(app_configs=None, **kwargs):
|
||||
# Check builtin permission name length.
|
||||
max_builtin_permission_name_length = (
|
||||
max(len(name) for name in builtin_permissions.values())
|
||||
if builtin_permissions
|
||||
else 0
|
||||
if builtin_permissions else 0
|
||||
)
|
||||
if max_builtin_permission_name_length > permission_name_max_length:
|
||||
verbose_name_max_length = permission_name_max_length - (
|
||||
max_builtin_permission_name_length - len(opts.verbose_name_raw)
|
||||
verbose_name_max_length = (
|
||||
permission_name_max_length - (max_builtin_permission_name_length - len(opts.verbose_name_raw))
|
||||
)
|
||||
errors.append(
|
||||
checks.Error(
|
||||
"The verbose_name of model '%s' must be at most %d "
|
||||
"characters for its builtin permission names to be at "
|
||||
"most %d characters."
|
||||
% (opts.label, verbose_name_max_length, permission_name_max_length),
|
||||
"most %d characters." % (
|
||||
opts.label, verbose_name_max_length, permission_name_max_length
|
||||
),
|
||||
obj=model,
|
||||
id="auth.E007",
|
||||
id='auth.E007',
|
||||
)
|
||||
)
|
||||
# Check builtin permission codename length.
|
||||
max_builtin_permission_codename_length = (
|
||||
max(len(codename) for codename in builtin_permissions.keys())
|
||||
if builtin_permissions
|
||||
else 0
|
||||
if builtin_permissions else 0
|
||||
)
|
||||
if max_builtin_permission_codename_length > permission_codename_max_length:
|
||||
model_name_max_length = permission_codename_max_length - (
|
||||
@@ -154,14 +149,13 @@ def check_models_permissions(app_configs=None, **kwargs):
|
||||
checks.Error(
|
||||
"The name of model '%s' must be at most %d characters "
|
||||
"for its builtin permission codenames to be at most %d "
|
||||
"characters."
|
||||
% (
|
||||
"characters." % (
|
||||
opts.label,
|
||||
model_name_max_length,
|
||||
permission_codename_max_length,
|
||||
),
|
||||
obj=model,
|
||||
id="auth.E011",
|
||||
id='auth.E011',
|
||||
)
|
||||
)
|
||||
codenames = set()
|
||||
@@ -171,14 +165,11 @@ def check_models_permissions(app_configs=None, **kwargs):
|
||||
errors.append(
|
||||
checks.Error(
|
||||
"The permission named '%s' of model '%s' is longer "
|
||||
"than %d characters."
|
||||
% (
|
||||
name,
|
||||
opts.label,
|
||||
permission_name_max_length,
|
||||
"than %d characters." % (
|
||||
name, opts.label, permission_name_max_length,
|
||||
),
|
||||
obj=model,
|
||||
id="auth.E008",
|
||||
id='auth.E008',
|
||||
)
|
||||
)
|
||||
# Check custom permission codename length.
|
||||
@@ -186,24 +177,23 @@ def check_models_permissions(app_configs=None, **kwargs):
|
||||
errors.append(
|
||||
checks.Error(
|
||||
"The permission codenamed '%s' of model '%s' is "
|
||||
"longer than %d characters."
|
||||
% (
|
||||
"longer than %d characters." % (
|
||||
codename,
|
||||
opts.label,
|
||||
permission_codename_max_length,
|
||||
),
|
||||
obj=model,
|
||||
id="auth.E012",
|
||||
id='auth.E012',
|
||||
)
|
||||
)
|
||||
# Check custom permissions codename clashing.
|
||||
if codename in builtin_permissions:
|
||||
errors.append(
|
||||
checks.Error(
|
||||
"The permission codenamed '%s' clashes with a builtin "
|
||||
"permission for model '%s'." % (codename, opts.label),
|
||||
"The permission codenamed '%s' clashes with a builtin permission "
|
||||
"for model '%s'." % (codename, opts.label),
|
||||
obj=model,
|
||||
id="auth.E005",
|
||||
id='auth.E005',
|
||||
)
|
||||
)
|
||||
elif codename in codenames:
|
||||
@@ -212,7 +202,7 @@ def check_models_permissions(app_configs=None, **kwargs):
|
||||
"The permission codenamed '%s' is duplicated for "
|
||||
"model '%s'." % (codename, opts.label),
|
||||
obj=model,
|
||||
id="auth.E006",
|
||||
id='auth.E006',
|
||||
)
|
||||
)
|
||||
codenames.add(codename)
|
||||
|
||||
Reference in New Issue
Block a user