diff --git a/aleksis/core/checks.py b/aleksis/core/checks.py index db3199b6081d77e9bd8e2c559db07f7924484599..e7f61dbdca502f2261614e2e1e5249b65b0a98ff 100644 --- a/aleksis/core/checks.py +++ b/aleksis/core/checks.py @@ -3,7 +3,7 @@ from typing import Optional import django.apps from django.core.checks import Tags, Warning, register -from .mixins import ExtensibleModel, PureDjangoModel +from .mixins import ExtensibleModel, GlobalPermissionModel, PureDjangoModel from .util.apps import AppConfig @@ -39,7 +39,10 @@ def check_app_configs_base_class( def check_app_models_base_class( app_configs: Optional[django.apps.registry.Apps] = None, **kwargs ) -> list: - """Check whether all app models derive from AlekSIS's base ExtensibleModel.""" + """Check whether all app models derive from AlekSIS's allowed base models. + + Does only allow ExtensibleModel, GlobalPermissionModel and PureDjangoModel. + """ results = [] if app_configs is None: @@ -47,14 +50,21 @@ def check_app_models_base_class( for app_config in filter(lambda c: c.name.startswith("aleksis."), app_configs): for model in app_config.get_models(): - if ExtensibleModel not in model.__mro__ and PureDjangoModel not in model.__mro__: + if ( + ExtensibleModel not in model.__mro__ + and PureDjangoModel not in model.__mro__ + and GlobalPermissionModel not in model.__mro__ + ): results.append( Warning( - f"Model {model._meta.object_name} in app config {app_config.name} does" - "not derive from aleksis.core.mixins.ExtensibleModel.", + f"Model {model._meta.object_name} in app config {app_config.name} does " + "not derive from aleksis.core.mixins.ExtensibleModel " + "or aleksis.core.mixins.GlobalPermissionModel.", hint=( - "Ensure all models in AlekSIS use ExtensibleModel as base." - "If your deviation is intentional, you can add the PureDjangoModel" + "Ensure all models in AlekSIS use ExtensibleModel (or " + "GlobalPermissionModel, if you want to define global permissions) " + "as base. " + "If your deviation is intentional, you can add the PureDjangoModel " "mixin instead to silence this warning." ), obj=model,