mirror of
https://github.com/ansible/awx.git
synced 2026-01-14 11:20:39 -03:30
Allow manual updates in spite of update_on_project_update
This makes inventory sources with the that flag set behave like any other inventory source with manual use. They will still update when triggered by a project SCM hash change.
This commit is contained in:
parent
1c5b0f023e
commit
f2d51f99dc
@ -2634,24 +2634,9 @@ class InventorySourceUpdateView(RetrieveAPIView):
|
||||
is_job_start = True
|
||||
new_in_14 = True
|
||||
|
||||
def _update_dependent_project(self, obj, request):
|
||||
if not self.request.user or not self.request.user.can_access(Project, 'start', obj.source_project):
|
||||
raise PermissionDenied(detail=_(
|
||||
'You do not have permission to update project `{}`.'.format(obj.source_project.name)))
|
||||
project_update = obj.source_project.update()
|
||||
if not project_update:
|
||||
return Response({}, status=status.HTTP_400_BAD_REQUEST)
|
||||
else:
|
||||
headers = {'Location': project_update.get_absolute_url(request=request)}
|
||||
return Response(dict(
|
||||
detail=_('Request to update dependent project has been accepted.'), inventory_update=None),
|
||||
status=status.HTTP_202_ACCEPTED, headers=headers)
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
obj = self.get_object()
|
||||
if obj.can_update:
|
||||
if obj.source == 'scm' and obj.update_on_project_update:
|
||||
return self._update_dependent_project(obj, request)
|
||||
update = obj.update()
|
||||
if not update:
|
||||
return Response({}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
@ -1874,8 +1874,7 @@ class RunInventoryUpdate(BaseTask):
|
||||
source_project = None
|
||||
if inventory_update.inventory_source:
|
||||
source_project = inventory_update.inventory_source.source_project
|
||||
if (inventory_update.source=='scm' and source_project and
|
||||
not inventory_update.inventory_source.update_on_project_update):
|
||||
if (inventory_update.source=='scm' and inventory_update.launch_type=='manual' and source_project):
|
||||
request_id = '' if self.request.id is None else self.request.id
|
||||
local_project_sync = source_project.create_project_update(
|
||||
launch_type="sync",
|
||||
|
||||
@ -5,7 +5,7 @@ from django.core.exceptions import ValidationError
|
||||
|
||||
from awx.api.versioning import reverse
|
||||
|
||||
from awx.main.models import InventorySource, Project, ProjectUpdate
|
||||
from awx.main.models import InventorySource
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@ -248,31 +248,6 @@ def test_inventory_update_access_called(post, inventory_source, alice, mock_acce
|
||||
mock_instance.can_start.assert_called_once_with(inventory_source)
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
class TestUpdateOnProjUpdate:
|
||||
|
||||
def test_no_access_update_denied(self, admin_user, scm_inventory, mock_access, post):
|
||||
inv_src = scm_inventory.inventory_sources.first()
|
||||
with mock_access(Project) as mock_access:
|
||||
mock_access.can_start = mock.MagicMock(return_value=False)
|
||||
r = post(reverse('api:inventory_source_update_view', kwargs={'pk': inv_src.id}),
|
||||
{}, admin_user, expect=403)
|
||||
assert 'You do not have permission to update project' in r.data['detail']
|
||||
|
||||
def test_no_access_update_allowed(self, admin_user, scm_inventory, mock_access, post):
|
||||
inv_src = scm_inventory.inventory_sources.first()
|
||||
inv_src.source_project.scm_type = 'git'
|
||||
inv_src.source_project.save()
|
||||
with mock.patch('awx.api.views.InventorySourceUpdateView.get_object') as get_object:
|
||||
get_object.return_value = inv_src
|
||||
with mock.patch.object(inv_src.source_project, 'update') as mock_update:
|
||||
mock_update.return_value = ProjectUpdate(pk=48, id=48)
|
||||
r = post(reverse('api:inventory_source_update_view', kwargs={'pk': inv_src.id}),
|
||||
{}, admin_user, expect=202)
|
||||
assert 'dependent project' in r.data['detail']
|
||||
assert not r.data['inventory_update']
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_inventory_source_vars_prohibition(post, inventory, admin_user):
|
||||
with mock.patch('awx.api.serializers.settings') as mock_settings:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user