mirror of
https://github.com/ansible/awx.git
synced 2026-02-28 08:18:43 -03:30
Merge pull request #8447 from thedoubl3j/local_path_mod
related #7665 added 400 if user attempts an edit to local_path in a SCM project Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
@@ -1333,6 +1333,8 @@ class ProjectOptionsSerializer(BaseSerializer):
|
|||||||
scm_type = attrs.get('scm_type', u'') or u''
|
scm_type = attrs.get('scm_type', u'') or u''
|
||||||
if self.instance and not scm_type:
|
if self.instance and not scm_type:
|
||||||
valid_local_paths.append(self.instance.local_path)
|
valid_local_paths.append(self.instance.local_path)
|
||||||
|
if scm_type and "local_path" in attrs and self.instance.local_path != attrs['local_path']:
|
||||||
|
errors['local_path'] = _(f'Cannot change local_path for {scm_type}-based projects')
|
||||||
if scm_type:
|
if scm_type:
|
||||||
attrs.pop('local_path', None)
|
attrs.pop('local_path', None)
|
||||||
if 'local_path' in attrs and attrs['local_path'] not in valid_local_paths:
|
if 'local_path' in attrs and attrs['local_path'] not in valid_local_paths:
|
||||||
|
|||||||
@@ -99,3 +99,12 @@ def test_changing_overwrite_behavior_okay_if_not_used(post, patch, organization,
|
|||||||
expect=200
|
expect=200
|
||||||
)
|
)
|
||||||
assert Project.objects.get(pk=r1.data['id']).allow_override is False
|
assert Project.objects.get(pk=r1.data['id']).allow_override is False
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_scm_project_local_path_invalid(get, patch, project, admin):
|
||||||
|
url = reverse('api:project_detail', kwargs={'pk': project.id})
|
||||||
|
resp = patch(url, {'local_path': '/foo/bar'}, user=admin, expect=400)
|
||||||
|
assert resp.data['local_path'] == [
|
||||||
|
'Cannot change local_path for git-based projects'
|
||||||
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user