mirror of
https://github.com/ansible/awx.git
synced 2026-05-07 01:17:37 -02:30
More updates for InventorySource changes
This commit is contained in:
@@ -1238,7 +1238,7 @@ class HostSerializer(BaseSerializerWithVariables):
|
||||
|
||||
|
||||
class GroupSerializer(BaseSerializerWithVariables):
|
||||
show_capabilities = ['start', 'copy', 'schedule', 'edit', 'delete']
|
||||
show_capabilities = ['copy', 'edit', 'delete']
|
||||
|
||||
class Meta:
|
||||
model = Group
|
||||
@@ -1427,13 +1427,12 @@ class InventorySourceSerializer(UnifiedJobTemplateSerializer, InventorySourceOpt
|
||||
status = serializers.ChoiceField(choices=InventorySource.INVENTORY_SOURCE_STATUS_CHOICES, read_only=True)
|
||||
last_update_failed = serializers.BooleanField(read_only=True)
|
||||
last_updated = serializers.DateTimeField(read_only=True)
|
||||
show_capabilities = ['start', 'schedule', 'edit', 'delete']
|
||||
|
||||
class Meta:
|
||||
model = InventorySource
|
||||
fields = ('*', 'inventory', 'update_on_launch',
|
||||
'update_cache_timeout') + \
|
||||
fields = ('*', 'name', 'inventory', 'update_on_launch', 'update_cache_timeout') + \
|
||||
('last_update_failed', 'last_updated') # Backwards compatibility.
|
||||
read_only_fields = ('*', 'name', 'inventory')
|
||||
|
||||
def get_related(self, obj):
|
||||
res = super(InventorySourceSerializer, self).get_related(obj)
|
||||
@@ -1450,8 +1449,6 @@ class InventorySourceSerializer(UnifiedJobTemplateSerializer, InventorySourceOpt
|
||||
))
|
||||
if obj.inventory:
|
||||
res['inventory'] = self.reverse('api:inventory_detail', kwargs={'pk': obj.inventory.pk})
|
||||
if obj.group:
|
||||
res['group'] = self.reverse('api:group_detail', kwargs={'pk': obj.group.pk})
|
||||
# Backwards compatibility.
|
||||
if obj.current_update:
|
||||
res['current_update'] = self.reverse('api:inventory_update_detail',
|
||||
@@ -1467,8 +1464,6 @@ class InventorySourceSerializer(UnifiedJobTemplateSerializer, InventorySourceOpt
|
||||
return ret
|
||||
if 'inventory' in ret and not obj.inventory:
|
||||
ret['inventory'] = None
|
||||
if 'group' in ret and not obj.group:
|
||||
ret['group'] = None
|
||||
return ret
|
||||
|
||||
|
||||
|
||||
@@ -2154,7 +2154,7 @@ class InventoryTreeView(RetrieveAPIView):
|
||||
root_group_pks = inventory.root_groups.order_by('name').values_list('pk', flat=True)
|
||||
groups_qs = inventory.groups
|
||||
groups_qs = groups_qs.select_related('inventory')
|
||||
groups_qs = groups_qs.prefetch_related('inventory_source')
|
||||
groups_qs = groups_qs.prefetch_related('inventory_sources')
|
||||
all_group_data = GroupSerializer(groups_qs, many=True).data
|
||||
all_group_data_map = dict((x['id'], x) for x in all_group_data)
|
||||
tree_data = [all_group_data_map[x] for x in root_group_pks]
|
||||
@@ -2164,22 +2164,17 @@ class InventoryTreeView(RetrieveAPIView):
|
||||
return Response(tree_data)
|
||||
|
||||
|
||||
class InventoryInventorySourcesList(SubListAPIView):
|
||||
class InventoryInventorySourcesList(SubListCreateAPIView):
|
||||
|
||||
view_name = _('Inventory Source List')
|
||||
|
||||
model = InventorySource
|
||||
serializer_class = InventorySourceSerializer
|
||||
parent_model = Inventory
|
||||
relationship = None # Not defined since using get_queryset().
|
||||
view_name = _('Inventory Source List')
|
||||
relationship = 'inventory_sources'
|
||||
parent_key = 'inventory'
|
||||
new_in_14 = True
|
||||
|
||||
def get_queryset(self):
|
||||
parent = self.get_parent_object()
|
||||
self.check_parent_access(parent)
|
||||
qs = self.request.user.get_queryset(self.model)
|
||||
return qs.filter(Q(inventory__pk=parent.pk) |
|
||||
Q(group__inventory__pk=parent.pk))
|
||||
|
||||
|
||||
class InventorySourceList(ListAPIView):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user