Add a generic relation to any model that registers itself for ACLs.
This helps reference the ACLs of the model with using ContentType.
This commit is contained in:
@@ -3,6 +3,7 @@ from __future__ import unicode_literals, absolute_import
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
|
from django.contrib.contenttypes.fields import GenericRelation
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -18,6 +19,12 @@ class ModelPermission(object):
|
|||||||
for permission in permissions:
|
for permission in permissions:
|
||||||
cls._registry[model].append(permission)
|
cls._registry[model].append(permission)
|
||||||
|
|
||||||
|
AccessControlList = apps.get_model(
|
||||||
|
app_label='acls', model_name='AccessControlList'
|
||||||
|
)
|
||||||
|
|
||||||
|
model.add_to_class('acls', GenericRelation(AccessControlList))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_for_instance(cls, instance):
|
def get_for_instance(cls, instance):
|
||||||
StoredPermission = apps.get_model(
|
StoredPermission = apps.get_model(
|
||||||
|
|||||||
Reference in New Issue
Block a user