Skip to content
Snippets Groups Projects

Resolve "Reinvestigate how to do global permissions"

Merged Hangzhi Yu requested to merge 344-reinvestigate-how-to-do-global-permissions into master
1 file
+ 17
7
Compare changes
  • Side-by-side
  • Inline
+ 17
7
@@ -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,
Loading