def ready(self): def check_drf_permissions(*args, **kwargs): errors = [] try: root = resolve(reverse('page-list')) except (NoReverseMatch, Resolver404): return errors try: view = root._func_path perms = set(import_string(view).permission_classes) except (ImportError, AttributeError): return errors bad_combo = {AllowAny} if not perms or perms == bad_combo: msg = "Improperly configured permissions found: {}".format(perms) hint = ("Probably you don't want just anyone creating pages. " "Either subclass the views for 'page-detail' and " "'page-list'\n\t " "OR set REST_FRAMEWORK['DEFAULT_PERMISSION_CLASSES'] " "to something more restrictive\n\t " "OR silence this warning") errors.append( checks.Warning( msg=msg, hint=hint, obj=view, id='varlet.W001', ) ) return errors checks.register(check_drf_permissions)
def ready(self): post_migrate.connect( create_permissions, dispatch_uid="django.contrib.auth.management.create_permissions" ) checks.register(check_user_model, checks.Tags.models) checks.register(check_models_permissions, checks.Tags.models)
def ready(self): # Register auth signals import pootle.apps.accounts.signals # FIXME In Django 1.8 this needs to change to # register(settings.check_deprecated_settings, "settings") checks.register("settings")(deprecation.check_deprecated_settings)
def register_startup_checks_extra(): """ Register extra checks provided by user. Here we will have to raise error for Exceptions, as that can not be done via check: all checks, including check_relate_settings, will only be executed after AppConfig.ready() is done. """ startup_checks_extra = getattr(settings, RELATE_STARTUP_CHECKS_EXTRA, None) if startup_checks_extra is not None: if not isinstance(startup_checks_extra, (list, tuple)): raise ImproperlyConfigured( INSTANCE_ERROR_PATTERN % {"location": RELATE_STARTUP_CHECKS_EXTRA, "types": "list or tuple" } ) for c in startup_checks_extra: try: check_item = import_string(c) except Exception as e: raise ImproperlyConfigured( GENERIC_ERROR_PATTERN % { "location": RELATE_STARTUP_CHECKS_EXTRA, "error_type": type(e).__name__, "error_str": str(e) }) else: register(check_item, RELATE_STARTUP_CHECKS_EXTRA_TAG)
def ready(self): register()(check_template_settings) if DJANGO_VERSION < (1, 9): # add_to_builtins was removed in 1.9 and replaced with a # documented public API configured by the TEMPLATES setting. from django.template.base import add_to_builtins add_to_builtins("mezzanine.template.loader_tags")
def register_checks(): for check in [ check_legacy_settings, check_url_allowed_attributes, check_custom_authorization_check_importable, check_hijack_decorator_importable, check_staff_authorization_settings, ]: register(check)
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)
def ready(self): post_migrate.connect( create_permissions, dispatch_uid="django.contrib.auth.management.create_permissions" ) if hasattr(get_user_model(), 'last_login'): from .models import update_last_login user_logged_in.connect(update_last_login, dispatch_uid='update_last_login') checks.register(check_user_model, checks.Tags.models) checks.register(check_models_permissions, checks.Tags.models)
def ready(self): post_migrate.connect( create_permissions, dispatch_uid="django.contrib.auth.management.create_permissions" ) last_login_field = getattr(get_user_model(), 'last_login', None) # Register the handler only if UserModel.last_login is a field. if isinstance(last_login_field, DeferredAttribute): from .models import update_last_login user_logged_in.connect(update_last_login, dispatch_uid='update_last_login') checks.register(check_user_model, checks.Tags.models) checks.register(check_models_permissions, checks.Tags.models)
def ready(self): checks.register(check_root_hostconf) checks.register(check_default_host) if getattr(settings, 'HOST_OVERRIDE_URL_TAG', False): if add_to_builtins: add_to_builtins('django_hosts.templatetags.hosts_override') else: raise ImproperlyConfigured( "On Django 1.9+, you must add " "'django_hosts.templatetags.hosts_override' to the " "TEMPLATES['OPTIONS']['builtins'] list instead of using " "the HOST_OVERRIDE_URL_TAG setting." )
def register_custom_checks(): from . import checks from django.core.checks import register, Tags register(checks.check_csp_sources_not_unsafe, Tags.security, deploy=True) register(checks.check_session_csrf_enabled, Tags.security) register(checks.check_csp_is_not_report_only, Tags.security) register(checks.check_cached_template_loader_used, Tags.caches, deploy=True)
def ready(self): """Perform initialization for back-end""" self.validate_configuration() self.check_superuser() # Make sure the existing version is what we expect signals.pre_migrate.connect(check_old_version, sender=self) # Validate CATMAID environment after all migrations have been run signals.post_migrate.connect(validate_environment, sender=self) # Register history checks register(check_history_setup) # Monkey patch django-rest-swagger so that it can handle our URLs custom_rest_swagger_apis.patch()
def register_system_checks(): for func in [ unique_room_names, unique_sessions_names, ]: check_function = make_check_function_run_once(func) register(check_function) for func in [ model_classes, files, constants, pages_function, templates_valid, template_encoding, orphan_methods, ]: check_function = make_check_function(func) register(check_function)
def ready(self): """Perform initialization for back-end""" self.validate_configuration() # If prepared statements are enabled, make sure they are created for # every new connection. Binding this signal handler has to happen before # the first database connection is created or connection pooling can not # be used with prepared statements safely. if settings.PREPARED_STATEMENTS: db_signals.connection_created.connect(prepare_db_statements) self.check_superuser() # Make sure the existing version is what we expect signals.pre_migrate.connect(check_old_version, sender=self) # Validate CATMAID environment after all migrations have been run signals.post_migrate.connect(validate_environment, sender=self) # Register history checks register(check_history_setup)
def ready(self): from .patches import json json.patch() from djangae.db.backends.appengine.caching import reset_context from django.core.signals import request_finished, request_started request_finished.connect(reset_context, dispatch_uid="request_finished_context_reset") request_started.connect(reset_context, dispatch_uid="request_started_context_reset") from django.conf import settings contenttype_configuration_error = ImproperlyConfigured( "If you're using django.contrib.contenttypes, then you need " "to add djangae.contrib.contenttypes to INSTALLED_APPS after " "django.contrib.contenttypes." ) if 'django.contrib.contenttypes' in settings.INSTALLED_APPS: from django.db import router, connections from django.contrib.contenttypes.models import ContentType conn = connections[router.db_for_read(ContentType)] if conn.settings_dict.get("ENGINE") != 'djangae.db.backends.appengine': # Don't enforce djangae.contrib.contenttypes if content types are being # saved to a different database backend return if not 'djangae.contrib.contenttypes' in settings.INSTALLED_APPS: # Raise error if User is using Django CT, but not Djangae raise contenttype_configuration_error else: if settings.INSTALLED_APPS.index('django.contrib.contenttypes') > \ settings.INSTALLED_APPS.index('djangae.contrib.contenttypes'): # Raise error if User is using both Django and Djangae CT, but # Django CT comes after Djangae CT raise contenttype_configuration_error checks.register(check_deferred_builtin)
def ready(self): pre_migrate.connect(inject_rename_contenttypes_operations, sender=self) post_migrate.connect(create_contenttypes) checks.register(check_generic_foreign_keys, checks.Tags.models)
def ready(self): from django.core.checks import register, Tags register(Tags.compatibility)(webpack_cfg_check)
def ready(self): post_migrate.connect(update_contenttypes) checks.register(check_generic_foreign_keys, checks.Tags.models)
def register_checks(): register(Tags.database)(check_variables)
def ready(self): _configure() checks.register(check_migrations, "migrations") setting_changed.connect(_watch_settings)
def ready(self): checks.register(check_finders, checks.Tags.staticfiles)
def ready(self): register(Tags.models)(check_max_migration_files)
def ready(self): super().ready() register(check_formats)
def ready(self): super().ready() register(check_avatars, deploy=True)
def ready(self): checks.register(deprecation.check_deprecated_settings, "settings") importlib.import_module("pootle_app.getters") importlib.import_module("pootle_app.providers")
def register_startup_checks(): register(check_relate_settings, RELATE_STARTUP_CHECKS_TAG)
def ready(self): register(check_admin_index_app, Tags.compatibility) register(check_admin_index_context_processor, Tags.compatibility)
from .checks import check_models_permissions, check_user_model from .management import create_permissions ======= from django.utils.translation import gettext_lazy as _ from . import get_user_model from .checks import check_models_permissions, check_user_model from .management import create_permissions from .signals import user_logged_in >>>>>>> 37c99181c9a6b95433d60f8c8ef9af5731096435 class AuthConfig(AppConfig): name = 'django.contrib.auth' verbose_name = _("Authentication and Authorization") def ready(self): post_migrate.connect( create_permissions, dispatch_uid="django.contrib.auth.management.create_permissions" ) <<<<<<< HEAD ======= if hasattr(get_user_model(), 'last_login'): from .models import update_last_login user_logged_in.connect(update_last_login, dispatch_uid='update_last_login') >>>>>>> 37c99181c9a6b95433d60f8c8ef9af5731096435 checks.register(check_user_model, checks.Tags.models) checks.register(check_models_permissions, checks.Tags.models)
def ready(self): register(markdown_view_check, Tags.security)
def ready(self): checks.register('models')(check_user_model)
def ready(self): # Import and register the system checks checks.register(check_production_settings) checks.register(check_sentry_config)
def ready(self): super().ready() register(check_data_writable) register(check_mail_connection, deploy=True) register(check_celery, deploy=True) register(check_cache, deploy=True) register(check_settings, deploy=True) register(check_templates, deploy=True) register(check_site) register(check_perms, deploy=True) register(check_errors, deploy=True) register(check_version, deploy=True) register(check_encoding) register(check_diskspace, deploy=True) init_error_collection() if using_postgresql(): CharField.register_lookup(PostgreSQLSearchLookup) TextField.register_lookup(PostgreSQLSearchLookup) CharField.register_lookup(PostgreSQLSubstringLookup) TextField.register_lookup(PostgreSQLSubstringLookup) else: CharField.register_lookup(MySQLSearchLookup) TextField.register_lookup(MySQLSearchLookup) CharField.register_lookup(MySQLSubstringLookup) TextField.register_lookup(MySQLSubstringLookup)
def ready(self): super().ready() register(check_backups, deploy=True)
# ACTION_CHECKBOX_NAME is unused, but should stay since its import from here # has been referenced in documentation. from django.contrib.admin.checks import check_admin_app from django.contrib.admin.decorators import register from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME from django.contrib.admin.options import ModelAdmin, HORIZONTAL, VERTICAL from django.contrib.admin.options import StackedInline, TabularInline from django.contrib.admin.filters import (ListFilter, SimpleListFilter, FieldListFilter, BooleanFieldListFilter, RelatedFieldListFilter, ChoicesFieldListFilter, DateFieldListFilter, AllValuesFieldListFilter) from django.contrib.admin.sites import AdminSite, site from django.core import checks from django.utils.module_loading import autodiscover_modules __all__ = [ "register", "ACTION_CHECKBOX_NAME", "ModelAdmin", "HORIZONTAL", "VERTICAL", "StackedInline", "TabularInline", "AdminSite", "site", "ListFilter", "SimpleListFilter", "FieldListFilter", "BooleanFieldListFilter", "RelatedFieldListFilter", "ChoicesFieldListFilter", "DateFieldListFilter", "AllValuesFieldListFilter", "autodiscover", ] def autodiscover(): autodiscover_modules('admin', register_to=site) checks.register('admin')(check_admin_app)
def register_checks(): register(Tags.models)(check_models)
def ready(self): from waldur_core.core.models import CoordinatesMixin from waldur_core.structure.executors import check_cleanup_executors from waldur_core.structure.models import ResourceMixin, Service, TagMixin, VirtualMachine from waldur_core.structure import handlers from waldur_core.structure import signals as structure_signals from django.core import checks checks.register(check_cleanup_executors) Customer = self.get_model('Customer') Project = self.get_model('Project') CustomerPermission = self.get_model('CustomerPermission') ProjectPermission = self.get_model('ProjectPermission') signals.post_save.connect( handlers.log_customer_save, sender=Customer, dispatch_uid='waldur_core.structure.handlers.log_customer_save', ) signals.post_delete.connect( handlers.log_customer_delete, sender=Customer, dispatch_uid='waldur_core.structure.handlers.log_customer_delete', ) signals.post_save.connect( handlers.log_project_save, sender=Project, dispatch_uid='waldur_core.structure.handlers.log_project_save', ) signals.post_delete.connect( handlers.log_project_delete, sender=Project, dispatch_uid='waldur_core.structure.handlers.log_project_delete', ) # increase nc_user_count quota usage on adding user to customer structure_models_with_roles = (Customer, Project) for model in structure_models_with_roles: name = 'increase_customer_nc_users_quota_on_adding_user_to_%s' % model.__name__ structure_signals.structure_role_granted.connect( handlers.change_customer_nc_users_quota, sender=model, dispatch_uid='waldur_core.structure.handlers.%s' % name, ) # decrease nc_user_count quota usage on removing user from customer for model in structure_models_with_roles: name = 'decrease_customer_nc_users_quota_on_removing_user_from_%s' % model.__name__ structure_signals.structure_role_revoked.connect( handlers.change_customer_nc_users_quota, sender=model, dispatch_uid='waldur_core.structure.handlers.%s' % name, ) structure_signals.structure_role_granted.connect( handlers.log_customer_role_granted, sender=Customer, dispatch_uid= 'waldur_core.structure.handlers.log_customer_role_granted', ) structure_signals.structure_role_revoked.connect( handlers.log_customer_role_revoked, sender=Customer, dispatch_uid= 'waldur_core.structure.handlers.log_customer_role_revoked', ) structure_signals.structure_role_updated.connect( handlers.log_customer_role_updated, sender=CustomerPermission, dispatch_uid= 'waldur_core.structure.handlers.log_customer_role_updated', ) structure_signals.structure_role_granted.connect( handlers.log_project_role_granted, sender=Project, dispatch_uid= 'waldur_core.structure.handlers.log_project_role_granted', ) structure_signals.structure_role_revoked.connect( handlers.log_project_role_revoked, sender=Project, dispatch_uid= 'waldur_core.structure.handlers.log_project_role_revoked', ) structure_signals.structure_role_updated.connect( handlers.log_project_role_updated, sender=ProjectPermission, dispatch_uid= 'waldur_core.structure.handlers.log_project_role_updated', ) signals.pre_delete.connect( handlers.revoke_roles_on_project_deletion, sender=Project, dispatch_uid= 'waldur_core.structure.handlers.revoke_roles_on_project_deletion', ) for index, model in enumerate(ResourceMixin.get_all_models()): signals.pre_delete.connect( handlers.log_resource_deleted, sender=model, dispatch_uid= 'waldur_core.structure.handlers.log_resource_deleted_{}_{}'. format(model.__name__, index), ) structure_signals.resource_imported.connect( handlers.log_resource_imported, sender=model, dispatch_uid= 'waldur_core.structure.handlers.log_resource_imported_{}_{}'. format(model.__name__, index), ) fsm_signals.post_transition.connect( handlers.log_resource_action, sender=model, dispatch_uid= 'waldur_core.structure.handlers.log_resource_action_{}_{}'. format(model.__name__, index), ) signals.post_save.connect( handlers.log_resource_creation_scheduled, sender=model, dispatch_uid= 'waldur_core.structure.handlers.log_resource_creation_scheduled_{}_{}' .format(model.__name__, index), ) signals.pre_delete.connect( handlers.delete_service_settings_on_scope_delete, sender=model, dispatch_uid= 'waldur_core.structure.handlers.delete_service_settings_on_scope_delete_{}_{}' .format(model.__name__, index), ) if issubclass(model, CoordinatesMixin): fsm_signals.post_transition.connect( handlers.detect_vm_coordinates, sender=model, dispatch_uid= 'waldur_core.structure.handlers.detect_vm_coordinates_{}_{}' .format(model.__name__, index), ) for index, model in enumerate(VirtualMachine.get_all_models()): signals.post_save.connect( handlers.update_resource_start_time, sender=model, dispatch_uid= 'waldur_core.structure.handlers.update_resource_start_time_{}_{}' .format(model.__name__, index), ) signals.post_save.connect( handlers.connect_customer_to_shared_service_settings, sender=Customer, dispatch_uid= 'waldur_core.structure.handlers.connect_customer_to_shared_service_settings', ) signals.post_save.connect( handlers.connect_project_to_all_available_services, sender=Project, dispatch_uid= 'waldur_core.structure.handlers.connect_project_to_all_available_services', ) for index, service_model in enumerate(Service.get_all_models()): signals.post_save.connect( handlers. connect_service_to_all_projects_if_it_is_available_for_all, sender=service_model, dispatch_uid='waldur_core.structure.handlers.' 'connect_service_{}_to_all_projects_if_it_is_available_for_all_{}' .format(service_model.__name__, index), ) signals.post_delete.connect( handlers.delete_service_settings_on_service_delete, sender=service_model, dispatch_uid= 'waldur_core.structure.handlers.delete_service_settings_on_service_delete_{}_{}' .format(service_model.__name__, index), ) signals.post_save.connect( handlers.clean_tags_cache_after_tagged_item_saved, sender=TagMixin.tags.through, dispatch_uid= 'waldur_core.structure.handlers.clean_tags_cache_after_tagged_item_created' ) signals.pre_delete.connect( handlers.clean_tags_cache_before_tagged_item_deleted, sender=TagMixin.tags.through, dispatch_uid= 'waldur_core.structure.handlers.clean_tags_cache_after_tagged_item_created' )
def ready(self): super(FontsConfig, self).ready() register(check_fonts)
def ready(self): register(check_requirements) register(check_data_writable) super(UtilsConfig, self).ready()
def ready(self): register(check_gemeente_code, Tags.compatibility) register(check_rolomschrijvingen, Tags.compatibility) register(check_zaakmagazijn_url, Tags.compatibility)
def register_checks(): for check in [ check_get_requests_allowed, check_custom_user_model, ]: register(check)
def ready(self): checks.register(checks.Tags.models)(check_generic_foreign_keys)
def ready(self): checks.register(check_dependencies, checks.Tags.admin) checks.register(check_admin_app, checks.Tags.admin)
from django.conf import settings from django.contrib.auth.checks import check_user_model from django.core import checks from django.core.exceptions import ImproperlyConfigured, PermissionDenied from django.utils.module_loading import import_by_path from django.middleware.csrf import rotate_token from .signals import user_logged_in, user_logged_out, user_login_failed SESSION_KEY = '_auth_user_id' BACKEND_SESSION_KEY = '_auth_user_backend' REDIRECT_FIELD_NAME = 'next' # Register the user model checks checks.register('models')(check_user_model) def load_backend(path): return import_by_path(path)() def get_backends(): backends = [] for backend_path in settings.AUTHENTICATION_BACKENDS: backends.append(load_backend(backend_path)) if not backends: raise ImproperlyConfigured('No authentication backends have been defined. Does AUTHENTICATION_BACKENDS contain anything?') return backends
def ready(self): checks.register(check_admin_app, checks.Tags.admin)
def ready(self): super().ready() register(check_data_writable) register(check_mail_connection, deploy=True) register(check_celery, deploy=True) register(check_cache, deploy=True) register(check_settings, deploy=True) register(check_templates, deploy=True) register(check_site, deploy=True) register(check_perms, deploy=True) register(check_errors, deploy=True) register(check_version, deploy=True) register(check_encoding) register(check_diskspace, deploy=True) init_error_collection() engine = settings.DATABASES["default"]["ENGINE"] if engine == "django.db.backends.postgresql": CharField.register_lookup(PostgreSQLSearchLookup) TextField.register_lookup(PostgreSQLSearchLookup) CharField.register_lookup(PostgreSQLSubstringLookup) TextField.register_lookup(PostgreSQLSubstringLookup) elif engine == "django.db.backends.mysql": CharField.register_lookup(MySQLSearchLookup) TextField.register_lookup(MySQLSearchLookup) CharField.register_lookup(MySQLSubstringLookup) TextField.register_lookup(MySQLSubstringLookup) else: raise Exception(f"Unsupported database: {engine}")
def ready(self): from django.core.checks import register, Tags register(Tags.compatibility)(webpack_cfg_check) # Invalidate stats file cache cache.delete(STATS_FILE_CACHE_KEY)
def ready(self): # FIXME In Django 1.8 this needs to change to # register(settings.check_deprecated_settings, "settings") checks.register("settings")(deprecation.check_deprecated_settings)
def ready(self): super(AccountsConfig, self).ready() register(check_avatars, deploy=True)
def ready(self): """Register select2_submodule_check.""" checks.register(select2_submodule_check)
def register_system_checks(): for func in [model_classes, files, constants, pages_function]: check_function = make_check_function(func) register(check_function)
def register_checks(): for check in [ # warn_1_3_changes, # Might be more annoying than useful ]: register(check)
def ready(self): super(GitExportConfig, self).ready() register(check_git_backend)
def ready(self): checks.register(check_user_model, checks.Tags.models)
def ready(self): post_migrate.connect( create_permissions, dispatch_uid="django.contrib.auth.management.create_permissions") checks.register(check_user_model, checks.Tags.models) checks.register(check_models_permissions, checks.Tags.models)
def ready(self): super(AuthenticationConfig, self).ready() from allianceauth.authentication import checks, signals register(Tags.security)(checks.check_login_scopes_setting)
def ready(self) -> None: register(Tags.security)(check_settings)