mirror of
https://github.com/ansible/awx.git
synced 2026-05-07 09:27:36 -02:30
Automatically rebuild our role hierarchy when our m2m map is updated
This commit is contained in:
@@ -7,17 +7,21 @@ import logging
|
|||||||
# Django
|
# Django
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
from django.db.models.signals import pre_save, post_save, pre_delete, post_delete, m2m_changed
|
||||||
|
|
||||||
# AWX
|
# AWX
|
||||||
from awx.main.models.base import * # noqa
|
from awx.main.models.base import * # noqa
|
||||||
from awx.main.fields import * # noqa
|
from awx.main.fields import * # noqa
|
||||||
|
|
||||||
__all__ = ['Role', 'RolePermission', 'Resource']
|
__all__ = ['Role', 'RolePermission', 'Resource', 'RoleHierarchy', 'ResourceHierarchy']
|
||||||
|
|
||||||
logger = logging.getLogger('awx.main.models.rbac')
|
logger = logging.getLogger('awx.main.models.rbac')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def rebuild_role_hierarchy_cache(sender, **kwargs):
|
||||||
|
kwargs['instance'].rebuild_role_hierarchy_cache()
|
||||||
|
|
||||||
class Role(CommonModelNameNotUnique):
|
class Role(CommonModelNameNotUnique):
|
||||||
'''
|
'''
|
||||||
Role model
|
Role model
|
||||||
@@ -56,6 +60,8 @@ class Role(CommonModelNameNotUnique):
|
|||||||
for child in self.children.all():
|
for child in self.children.all():
|
||||||
child.rebuild_role_hierarchy_cache()
|
child.rebuild_role_hierarchy_cache()
|
||||||
|
|
||||||
|
m2m_changed.connect(rebuild_role_hierarchy_cache, Role.parents.through)
|
||||||
|
|
||||||
|
|
||||||
class RoleHierarchy(CreatedModifiedModel):
|
class RoleHierarchy(CreatedModifiedModel):
|
||||||
'''
|
'''
|
||||||
|
|||||||
Reference in New Issue
Block a user