mirror of
https://github.com/ansible/awx.git
synced 2026-03-09 05:29:26 -02:30
cleanup from accessible_objects refactor
This commit is contained in:
@@ -3,7 +3,6 @@ import json
|
|||||||
|
|
||||||
# Django
|
# Django
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.models import Q
|
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.contrib.auth.models import User # noqa
|
from django.contrib.auth.models import User # noqa
|
||||||
|
|
||||||
@@ -38,7 +37,6 @@ class ResourceMixin(models.Model):
|
|||||||
'''
|
'''
|
||||||
return ResourceMixin._accessible_objects(cls, accessor, role_field)
|
return ResourceMixin._accessible_objects(cls, accessor, role_field)
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _accessible_pk_qs(cls, accessor, role_field, content_types=None):
|
def _accessible_pk_qs(cls, accessor, role_field, content_types=None):
|
||||||
if type(accessor) == User:
|
if type(accessor) == User:
|
||||||
@@ -50,17 +48,15 @@ class ResourceMixin(models.Model):
|
|||||||
ancestor_roles = Role.objects.filter(content_type__pk=accessor_type.id,
|
ancestor_roles = Role.objects.filter(content_type__pk=accessor_type.id,
|
||||||
object_id=accessor.id)
|
object_id=accessor.id)
|
||||||
|
|
||||||
if content_types is not None:
|
if content_types is None:
|
||||||
return RoleAncestorEntry.objects.filter(
|
ct_kwarg = dict(content_type_id = ContentType.objects.get_for_model(cls).id)
|
||||||
ancestor__in = ancestor_roles,
|
else:
|
||||||
content_type_id__in = content_types,
|
ct_kwarg = dict(content_type_id__in = content_types)
|
||||||
role_field = role_field
|
|
||||||
).values_list('object_id').distinct()
|
|
||||||
|
|
||||||
return RoleAncestorEntry.objects.filter(
|
return RoleAncestorEntry.objects.filter(
|
||||||
ancestor__in = ancestor_roles,
|
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()
|
).values_list('object_id').distinct()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -175,12 +175,10 @@ class UnifiedJobTemplate(PolymorphicModel, CommonModelNameNotUnique, Notificatio
|
|||||||
Does not return inventory sources or system JTs, these should
|
Does not return inventory sources or system JTs, these should
|
||||||
be handled inside of get_queryset where it is utilized.
|
be handled inside of get_queryset where it is utilized.
|
||||||
'''
|
'''
|
||||||
# Algorithmic option, if we don't want hardcoded class names
|
ujt_names = [c.__name__.lower() for c in cls.__subclasses__()
|
||||||
# ujt_name_list = [c.__name__.lower() for c in cls.__subclasses__()]
|
if c.__name__.lower() not in ['inventorysource', 'systemjobtemplate']]
|
||||||
# ujt_name_list.remove('inventorysource')
|
|
||||||
subclass_content_types = ContentType.objects.filter(
|
subclass_content_types = ContentType.objects.filter(
|
||||||
model__in=['project', 'jobtemplate', 'systemjobtemplate', 'workflowjobtemplate']
|
model__in=ujt_names).values_list('id', flat=True)
|
||||||
).values_list('id', flat=True)
|
|
||||||
|
|
||||||
return ResourceMixin._accessible_pk_qs(cls, accessor, role_field, content_types=subclass_content_types)
|
return ResourceMixin._accessible_pk_qs(cls, accessor, role_field, content_types=subclass_content_types)
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
resource medium jan2017
|
resource medium Jan2017 jobs1k jobs10k
|
||||||
organizations 500 1
|
organizations 500 1 1 1
|
||||||
users 5000 3
|
users 5000 3 3 3
|
||||||
teams 500 2
|
teams 500 2 2 2
|
||||||
projects 1000 30
|
projects 1000 30 30 30
|
||||||
job-templates 2000 127
|
job_templates 2000 127 127 127
|
||||||
credentials 2000 50
|
credentials 2000 50 50 50
|
||||||
inventories 2000 6
|
inventories 2000 6 6 6
|
||||||
inventory-groups 500 15
|
inventory_groups 500 15 15 15
|
||||||
inventory-hosts 2500 15
|
inventory_hosts 2500 15 15 15
|
||||||
wfjts 100 0
|
wfjts 100 0 0 0
|
||||||
nodes 1000 0
|
nodes 1000 0 0 0
|
||||||
labels 1000 0
|
labels 1000 0 0 0
|
||||||
jobs 1000 157208
|
jobs 1000 157208 1000 10000
|
||||||
job-events 1000 3370942
|
job_events 1000 3370942 20000 200000
|
||||||
|
@@ -490,7 +490,8 @@ try:
|
|||||||
if project_idx == 0 and i == 0:
|
if project_idx == 0 and i == 0:
|
||||||
job_template.admin_role.members.add(jt_admin)
|
job_template.admin_role.members.add(jt_admin)
|
||||||
project_idx += 1
|
project_idx += 1
|
||||||
print('')
|
if n > 0:
|
||||||
|
print('')
|
||||||
|
|
||||||
print('# Creating %d Workflow Job Templates' % n_wfjts)
|
print('# Creating %d Workflow Job Templates' % n_wfjts)
|
||||||
org_idx = 0
|
org_idx = 0
|
||||||
@@ -511,7 +512,8 @@ try:
|
|||||||
wfjt._is_new = _
|
wfjt._is_new = _
|
||||||
wfjts.append(wfjt)
|
wfjts.append(wfjt)
|
||||||
org_idx += 1
|
org_idx += 1
|
||||||
print('')
|
if n:
|
||||||
|
print('')
|
||||||
|
|
||||||
print('# Creating %d Workflow Job Template nodes' % n_nodes)
|
print('# Creating %d Workflow Job Template nodes' % n_nodes)
|
||||||
wfjt_idx = 0
|
wfjt_idx = 0
|
||||||
@@ -561,7 +563,8 @@ try:
|
|||||||
parent_node.success_nodes.add(node)
|
parent_node.success_nodes.add(node)
|
||||||
parent_idx = (parent_idx + 7) % len(wfjt_nodes)
|
parent_idx = (parent_idx + 7) % len(wfjt_nodes)
|
||||||
wfjt_idx += 1
|
wfjt_idx += 1
|
||||||
print('')
|
if n:
|
||||||
|
print('')
|
||||||
|
|
||||||
print('# Creating %d Labels' % n_labels)
|
print('# Creating %d Labels' % n_labels)
|
||||||
org_idx = 0
|
org_idx = 0
|
||||||
@@ -580,7 +583,8 @@ try:
|
|||||||
)
|
)
|
||||||
labels.append(label)
|
labels.append(label)
|
||||||
org_idx += 1
|
org_idx += 1
|
||||||
print('')
|
if n:
|
||||||
|
print('')
|
||||||
label_gen = yield_choice(labels)
|
label_gen = yield_choice(labels)
|
||||||
|
|
||||||
print('# Adding labels to job templates')
|
print('# Adding labels to job templates')
|
||||||
@@ -636,10 +640,9 @@ try:
|
|||||||
jobs.append(job)
|
jobs.append(job)
|
||||||
job_i += 1
|
job_i += 1
|
||||||
if not job._is_new:
|
if not job._is_new:
|
||||||
job_template_idx += 1
|
|
||||||
group_idx += 1
|
group_idx += 1
|
||||||
continue
|
continue
|
||||||
if i+1 == n:
|
if i + 1 == n:
|
||||||
job_template.last_job = job
|
job_template.last_job = job
|
||||||
if job_template.pk % 5 == 0:
|
if job_template.pk % 5 == 0:
|
||||||
job_template.current_job = job
|
job_template.current_job = job
|
||||||
@@ -689,3 +692,5 @@ try:
|
|||||||
except Rollback:
|
except Rollback:
|
||||||
print('Rolled back changes')
|
print('Rolled back changes')
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
print('')
|
||||||
|
|||||||
Reference in New Issue
Block a user