mirror of
https://github.com/ansible/awx.git
synced 2026-01-15 03:40:42 -03:30
Automatically rebuild our role hierarchy when our m2m map is updated
This commit is contained in:
parent
fae9ef3d65
commit
014b970030
@ -7,17 +7,21 @@ import logging
|
||||
# Django
|
||||
from django.db import models
|
||||
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
|
||||
from awx.main.models.base 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')
|
||||
|
||||
|
||||
|
||||
def rebuild_role_hierarchy_cache(sender, **kwargs):
|
||||
kwargs['instance'].rebuild_role_hierarchy_cache()
|
||||
|
||||
class Role(CommonModelNameNotUnique):
|
||||
'''
|
||||
Role model
|
||||
@ -56,6 +60,8 @@ class Role(CommonModelNameNotUnique):
|
||||
for child in self.children.all():
|
||||
child.rebuild_role_hierarchy_cache()
|
||||
|
||||
m2m_changed.connect(rebuild_role_hierarchy_cache, Role.parents.through)
|
||||
|
||||
|
||||
class RoleHierarchy(CreatedModifiedModel):
|
||||
'''
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user