Merge pull request #7222 from rooftopcellist/inventory_update_not_manual

Inventory Update All no longer includes manual sources
This commit is contained in:
Christian Adams
2017-07-21 13:04:14 -04:00
committed by GitHub
2 changed files with 7 additions and 6 deletions

View File

@@ -2481,7 +2481,7 @@ class InventoryInventorySourcesUpdate(RetrieveAPIView):
def retrieve(self, request, *args, **kwargs): def retrieve(self, request, *args, **kwargs):
inventory = self.get_object() inventory = self.get_object()
update_data = [] update_data = []
for inventory_source in inventory.inventory_sources.all(): for inventory_source in inventory.inventory_sources.exclude(source=''):
details = {'inventory_source': inventory_source.pk, details = {'inventory_source': inventory_source.pk,
'can_update': inventory_source.can_update} 'can_update': inventory_source.can_update}
update_data.append(details) update_data.append(details)
@@ -2492,18 +2492,16 @@ class InventoryInventorySourcesUpdate(RetrieveAPIView):
update_data = [] update_data = []
successes = 0 successes = 0
failures = 0 failures = 0
for inventory_source in inventory.inventory_sources.all(): for inventory_source in inventory.inventory_sources.exclude(source=''):
details = {'inventory_source': inventory_source.pk, 'status': None} details = {'inventory_source': inventory_source.pk, 'status': None}
can_update = inventory_source.can_update can_update = inventory_source.can_update
project_update = False project_update = False
if inventory_source.source == 'scm' and inventory_source.update_on_project_update: if inventory_source.source == 'scm' and inventory_source.update_on_project_update:
if not request.user or not request.user.can_access(Project, 'start', inventory_source.source_project): if not request.user or not request.user.can_access(Project, 'start', inventory_source.source_project):
details['status'] = _('You do not have permission to update project `{}`').format(inventory_source.source_project.name) details['status'] = _('You do not have permission to update project `{}`').format(inventory_source.source_project.name)
can_update = False can_update = False
else: else:
project_update = True project_update = True
if can_update: if can_update:
if project_update: if project_update:
details['project_update'] = inventory_source.source_project.update().id details['project_update'] = inventory_source.source_project.update().id

View File

@@ -113,6 +113,9 @@ class TestInventoryInventorySourcesUpdate:
update_on_project_update=is_up_on_proj, update_on_project_update=is_up_on_proj,
can_update=can_update, update=lambda:InventoryUpdate)] can_update=can_update, update=lambda:InventoryUpdate)]
def exclude(self, **kwargs):
return self.all()
Inventory = namedtuple('Inventory', ['inventory_sources']) Inventory = namedtuple('Inventory', ['inventory_sources'])
obj = Inventory(inventory_sources=InventorySources()) obj = Inventory(inventory_sources=InventorySources())