mirror of
https://github.com/ansible/awx.git
synced 2026-01-11 10:00:01 -03:30
Removed unnecessary ResourceHierarchy model
This commit is contained in:
parent
fe29486d7b
commit
70229076d2
@ -11,7 +11,7 @@ from django.utils.translation import ugettext_lazy as _
|
||||
# AWX
|
||||
from awx.main.models.base import * # noqa
|
||||
|
||||
__all__ = ['Role', 'RolePermission', 'Resource', 'RoleHierarchy', 'ResourceHierarchy']
|
||||
__all__ = ['Role', 'RolePermission', 'Resource', 'RoleHierarchy']
|
||||
|
||||
logger = logging.getLogger('awx.main.models.rbac')
|
||||
|
||||
@ -115,47 +115,6 @@ class Resource(CommonModelNameNotUnique):
|
||||
|
||||
parent = models.ForeignKey('Resource', related_name='children', null=True, default=None)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
super(Resource, self).save(*args, **kwargs)
|
||||
self.rebuild_resource_hierarchy_cache()
|
||||
|
||||
def rebuild_resource_hierarchy_cache(self):
|
||||
'Rebuilds the associated entries in the ResourceHierarchy model'
|
||||
|
||||
# Compute what our hierarchy should be. (Note: this depends on our
|
||||
# parent's cached hierarchy being correct)
|
||||
actual_ancestors = set()
|
||||
if self.parent:
|
||||
actual_ancestors = set([r.ancestor.id for r in ResourceHierarchy.objects.filter(resource__id=self.parent.id)])
|
||||
actual_ancestors.add(self.id)
|
||||
|
||||
# Compute what we have stored
|
||||
stored_ancestors = set([r.ancestor.id for r in ResourceHierarchy.objects.filter(resource__id=self.id)])
|
||||
|
||||
# If it differs, update, and then update all of our children
|
||||
if actual_ancestors != stored_ancestors:
|
||||
ResourceHierarchy.objects.filter(resource__id=self.id).delete()
|
||||
for id in actual_ancestors:
|
||||
rh = ResourceHierarchy(resource=self, ancestor=Resource.objects.get(id=id))
|
||||
rh.save()
|
||||
for child in self.children.all():
|
||||
child.rebuild_resource_hierarchy_cache()
|
||||
|
||||
|
||||
|
||||
class ResourceHierarchy(CreatedModifiedModel):
|
||||
'''
|
||||
Stores a flattened relation map of all resources in the system for easy joining
|
||||
'''
|
||||
|
||||
class Meta:
|
||||
app_label = 'main'
|
||||
verbose_name_plural = _('resource_ancestors')
|
||||
db_table = 'main_rbac_resource_hierarchy'
|
||||
|
||||
resource = models.ForeignKey('Resource', related_name='+', on_delete=models.CASCADE)
|
||||
ancestor = models.ForeignKey('Resource', related_name='+', on_delete=models.CASCADE)
|
||||
|
||||
|
||||
class RolePermission(CreatedModifiedModel):
|
||||
'''
|
||||
@ -187,4 +146,3 @@ class RolePermission(CreatedModifiedModel):
|
||||
execute = models.IntegerField(default = 0)
|
||||
scm_update = models.IntegerField(default = 0)
|
||||
use = models.IntegerField(default = 0)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user