Skip to content
Snippets Groups Projects
Commit b9affcaa authored by Hangzhi Yu's avatar Hangzhi Yu
Browse files

Let GlobalPermissionModel pass through checks

parent 7893c465
No related branches found
No related tags found
1 merge request!453Resolve "Reinvestigate how to do global permissions"
Pipeline #5768 passed
......@@ -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,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment