mirror of
https://github.com/ansible/awx.git
synced 2026-04-27 04:35:22 -02:30
cleanup from accessible_objects refactor
This commit is contained in:
@@ -3,7 +3,6 @@ import json
|
||||
|
||||
# Django
|
||||
from django.db import models
|
||||
from django.db.models import Q
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.contrib.auth.models import User # noqa
|
||||
|
||||
@@ -38,7 +37,6 @@ class ResourceMixin(models.Model):
|
||||
'''
|
||||
return ResourceMixin._accessible_objects(cls, accessor, role_field)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def _accessible_pk_qs(cls, accessor, role_field, content_types=None):
|
||||
if type(accessor) == User:
|
||||
@@ -50,17 +48,15 @@ class ResourceMixin(models.Model):
|
||||
ancestor_roles = Role.objects.filter(content_type__pk=accessor_type.id,
|
||||
object_id=accessor.id)
|
||||
|
||||
if content_types is not None:
|
||||
return RoleAncestorEntry.objects.filter(
|
||||
ancestor__in = ancestor_roles,
|
||||
content_type_id__in = content_types,
|
||||
role_field = role_field
|
||||
).values_list('object_id').distinct()
|
||||
if content_types is None:
|
||||
ct_kwarg = dict(content_type_id = ContentType.objects.get_for_model(cls).id)
|
||||
else:
|
||||
ct_kwarg = dict(content_type_id__in = content_types)
|
||||
|
||||
return RoleAncestorEntry.objects.filter(
|
||||
ancestor__in = ancestor_roles,
|
||||
content_type_id = ContentType.objects.get_for_model(cls).id,
|
||||
role_field = role_field
|
||||
role_field = role_field,
|
||||
**ct_kwarg
|
||||
).values_list('object_id').distinct()
|
||||
|
||||
|
||||
|
||||
@@ -175,12 +175,10 @@ class UnifiedJobTemplate(PolymorphicModel, CommonModelNameNotUnique, Notificatio
|
||||
Does not return inventory sources or system JTs, these should
|
||||
be handled inside of get_queryset where it is utilized.
|
||||
'''
|
||||
# Algorithmic option, if we don't want hardcoded class names
|
||||
# ujt_name_list = [c.__name__.lower() for c in cls.__subclasses__()]
|
||||
# ujt_name_list.remove('inventorysource')
|
||||
ujt_names = [c.__name__.lower() for c in cls.__subclasses__()
|
||||
if c.__name__.lower() not in ['inventorysource', 'systemjobtemplate']]
|
||||
subclass_content_types = ContentType.objects.filter(
|
||||
model__in=['project', 'jobtemplate', 'systemjobtemplate', 'workflowjobtemplate']
|
||||
).values_list('id', flat=True)
|
||||
model__in=ujt_names).values_list('id', flat=True)
|
||||
|
||||
return ResourceMixin._accessible_pk_qs(cls, accessor, role_field, content_types=subclass_content_types)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user