mirror of
https://github.com/ansible/awx.git
synced 2026-05-07 09:27:36 -02:30
Merge pull request #5445 from AlanCoding/sub_ct_from_cache
Allow UJT content type list to come from manager cache
This commit is contained in:
@@ -174,6 +174,13 @@ class UnifiedJobTemplate(PolymorphicModel, CommonModelNameNotUnique, Notificatio
|
|||||||
return []
|
return []
|
||||||
return ['project', 'inventorysource', 'systemjobtemplate']
|
return ['project', 'inventorysource', 'systemjobtemplate']
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _submodels_with_roles(cls):
|
||||||
|
ujt_classes = [c for c in cls.__subclasses__()
|
||||||
|
if c._meta.model_name not in ['inventorysource', 'systemjobtemplate']]
|
||||||
|
ct_dict = ContentType.objects.get_for_models(*ujt_classes)
|
||||||
|
return [ct.id for ct in ct_dict.values()]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def accessible_pk_qs(cls, accessor, role_field):
|
def accessible_pk_qs(cls, accessor, role_field):
|
||||||
'''
|
'''
|
||||||
@@ -184,12 +191,8 @@ class UnifiedJobTemplate(PolymorphicModel, CommonModelNameNotUnique, Notificatio
|
|||||||
# do not use this if in a subclass
|
# do not use this if in a subclass
|
||||||
if cls != UnifiedJobTemplate:
|
if cls != UnifiedJobTemplate:
|
||||||
return super(UnifiedJobTemplate, cls).accessible_pk_qs(accessor, role_field)
|
return super(UnifiedJobTemplate, cls).accessible_pk_qs(accessor, role_field)
|
||||||
ujt_names = [c.__name__.lower() for c in cls.__subclasses__()
|
return ResourceMixin._accessible_pk_qs(
|
||||||
if c.__name__.lower() not in ['inventorysource', 'systemjobtemplate']]
|
cls, accessor, role_field, content_types=cls._submodels_with_roles())
|
||||||
subclass_content_types = list(ContentType.objects.filter(
|
|
||||||
model__in=ujt_names).values_list('id', flat=True))
|
|
||||||
|
|
||||||
return ResourceMixin._accessible_pk_qs(cls, accessor, role_field, content_types=subclass_content_types)
|
|
||||||
|
|
||||||
def _perform_unique_checks(self, unique_checks):
|
def _perform_unique_checks(self, unique_checks):
|
||||||
# Handle the list of unique fields returned above. Replace with an
|
# Handle the list of unique fields returned above. Replace with an
|
||||||
|
|||||||
@@ -1,5 +1,20 @@
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
# Django
|
||||||
|
from django.contrib.contenttypes.models import ContentType
|
||||||
|
|
||||||
|
# AWX
|
||||||
|
from awx.main.models import UnifiedJobTemplate, JobTemplate, WorkflowJobTemplate, Project
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_subclass_types(rando):
|
||||||
|
assert set(UnifiedJobTemplate._submodels_with_roles()) == set([
|
||||||
|
ContentType.objects.get_for_model(JobTemplate).id,
|
||||||
|
ContentType.objects.get_for_model(Project).id,
|
||||||
|
ContentType.objects.get_for_model(WorkflowJobTemplate).id
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
class TestCreateUnifiedJob:
|
class TestCreateUnifiedJob:
|
||||||
'''
|
'''
|
||||||
|
|||||||
Reference in New Issue
Block a user