mirror of
https://github.com/ansible/awx.git
synced 2026-05-12 03:47:36 -02:30
manually update SCM inv src on bulk update
This commit is contained in:
@@ -2508,17 +2508,7 @@ class InventoryInventorySourcesUpdate(RetrieveAPIView):
|
|||||||
failures = 0
|
failures = 0
|
||||||
for inventory_source in inventory.inventory_sources.exclude(source=''):
|
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
|
if inventory_source.can_update:
|
||||||
project_update = False
|
|
||||||
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):
|
|
||||||
details['status'] = _('You do not have permission to update project `{}`').format(inventory_source.source_project.name)
|
|
||||||
can_update = False
|
|
||||||
else:
|
|
||||||
project_update = True
|
|
||||||
if can_update:
|
|
||||||
if project_update:
|
|
||||||
details['project_update'] = inventory_source.source_project.update().id
|
|
||||||
details['status'] = 'started'
|
details['status'] = 'started'
|
||||||
details['inventory_update'] = inventory_source.update().id
|
details['inventory_update'] = inventory_source.update().id
|
||||||
successes += 1
|
successes += 1
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ class TestInventoryInventorySourcesUpdate:
|
|||||||
@pytest.mark.parametrize("can_update, can_access, is_source, is_up_on_proj, expected", [
|
@pytest.mark.parametrize("can_update, can_access, is_source, is_up_on_proj, expected", [
|
||||||
(True, True, "ec2", False, [{'status': 'started', 'inventory_update': 1, 'inventory_source': 1}]),
|
(True, True, "ec2", False, [{'status': 'started', 'inventory_update': 1, 'inventory_source': 1}]),
|
||||||
(False, True, "gce", False, [{'status': 'Could not start because `can_update` returned False', 'inventory_source': 1}]),
|
(False, True, "gce", False, [{'status': 'Could not start because `can_update` returned False', 'inventory_source': 1}]),
|
||||||
(True, False, "scm", True, [{'status': 'You do not have permission to update project `project`', 'inventory_source': 1}]),
|
(True, False, "scm", True, [{'status': 'started', 'inventory_update': 1, 'inventory_source': 1}]),
|
||||||
])
|
])
|
||||||
def test_post(self, mocker, can_update, can_access, is_source, is_up_on_proj, expected):
|
def test_post(self, mocker, can_update, can_access, is_source, is_up_on_proj, expected):
|
||||||
class InventoryUpdate:
|
class InventoryUpdate:
|
||||||
|
|||||||
Reference in New Issue
Block a user