mirror of
https://github.com/ansible/awx.git
synced 2026-04-06 18:49:21 -02:30
adapt the capabilities_prefetch to work with unified models
This commit is contained in:
@@ -3783,6 +3783,12 @@ class UnifiedJobTemplateList(ListAPIView):
|
|||||||
model = UnifiedJobTemplate
|
model = UnifiedJobTemplate
|
||||||
serializer_class = UnifiedJobTemplateSerializer
|
serializer_class = UnifiedJobTemplateSerializer
|
||||||
new_in_148 = True
|
new_in_148 = True
|
||||||
|
capabilities_prefetch = [
|
||||||
|
'admin', 'execute',
|
||||||
|
{'copy': ['jobtemplate.project.use', 'jobtemplate.inventory.use', 'jobtemplate.credential.use',
|
||||||
|
'jobtemplate.cloud_credential.use', 'jobtemplate.network_credential.use',
|
||||||
|
'workflowjobtemplate.organization.admin']}
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class UnifiedJobList(ListAPIView):
|
class UnifiedJobList(ListAPIView):
|
||||||
|
|||||||
@@ -532,19 +532,20 @@ def cache_list_capabilities(page, prefetch_list, model, user):
|
|||||||
paths = [paths]
|
paths = [paths]
|
||||||
|
|
||||||
# Build the query for accessible_objects according the user & role(s)
|
# Build the query for accessible_objects according the user & role(s)
|
||||||
qs_obj = None
|
filter_args = []
|
||||||
for role_path in paths:
|
for role_path in paths:
|
||||||
if '.' in role_path:
|
if '.' in role_path:
|
||||||
res_path = '__'.join(role_path.split('.')[:-1])
|
res_path = '__'.join(role_path.split('.')[:-1])
|
||||||
role_type = role_path.split('.')[-1]
|
role_type = role_path.split('.')[-1]
|
||||||
if qs_obj is None:
|
parent_model = model
|
||||||
qs_obj = model.objects
|
for subpath in role_path.split('.')[:-1]:
|
||||||
parent_model = model._meta.get_field(res_path).related_model
|
parent_model = parent_model._meta.get_field(subpath).related_model
|
||||||
kwargs = {'%s__in' % res_path: parent_model.accessible_objects(user, '%s_role' % role_type)}
|
filter_args.append(Q(
|
||||||
qs_obj = qs_obj.filter(Q(**kwargs) | Q(**{'%s__isnull' % res_path: True}))
|
Q(**{'%s__pk__in' % res_path: parent_model.accessible_pk_qs(user, '%s_role' % role_type)}) |
|
||||||
|
Q(**{'%s__isnull' % res_path: True})))
|
||||||
else:
|
else:
|
||||||
role_type = role_path
|
role_type = role_path
|
||||||
qs_obj = model.accessible_objects(user, '%s_role' % role_type)
|
filter_args.append(Q(**{'pk__in': model.accessible_pk_qs(user, '%s_role' % role_type)}))
|
||||||
|
|
||||||
if display_method is None:
|
if display_method is None:
|
||||||
# Role name translation to UI names for methods
|
# Role name translation to UI names for methods
|
||||||
@@ -555,7 +556,8 @@ def cache_list_capabilities(page, prefetch_list, model, user):
|
|||||||
display_method = 'start'
|
display_method = 'start'
|
||||||
|
|
||||||
# Union that query with the list of items on page
|
# Union that query with the list of items on page
|
||||||
ids_with_role = set(qs_obj.filter(pk__in=page_ids).values_list('pk', flat=True))
|
filter_args.append(Q(pk__in=page_ids))
|
||||||
|
ids_with_role = set(model.objects.filter(*filter_args).values_list('pk', flat=True))
|
||||||
|
|
||||||
# Save data item-by-item
|
# Save data item-by-item
|
||||||
for obj in page:
|
for obj in page:
|
||||||
|
|||||||
Reference in New Issue
Block a user