mirror of
https://github.com/ansible/awx.git
synced 2026-05-13 12:27:37 -02:30
Merge pull request #6909 from AlanCoding/no_manual_source_proj
Disallow manual projects for SCM inventory
This commit is contained in:
@@ -1637,6 +1637,11 @@ class InventorySourceSerializer(UnifiedJobTemplateSerializer, InventorySourceOpt
|
|||||||
ret['inventory'] = None
|
ret['inventory'] = None
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
def validate_source_project(self, value):
|
||||||
|
if value.scm_type == '':
|
||||||
|
raise serializers.ValidationError(_("Can not use manual project for SCM-based inventory."))
|
||||||
|
return value
|
||||||
|
|
||||||
def validate(self, attrs):
|
def validate(self, attrs):
|
||||||
def get_field_from_model_or_attrs(fd):
|
def get_field_from_model_or_attrs(fd):
|
||||||
return attrs.get(fd, self.instance and getattr(self.instance, fd) or None)
|
return attrs.get(fd, self.instance and getattr(self.instance, fd) or None)
|
||||||
|
|||||||
@@ -333,8 +333,8 @@ def test_prefetch_jt_copy_capability(job_template, project, inventory,
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_manual_projects_no_update(project, get, admin_user):
|
def test_manual_projects_no_update(manual_project, get, admin_user):
|
||||||
response = get(reverse('api:project_detail', kwargs={'pk': project.pk}), admin_user, expect=200)
|
response = get(reverse('api:project_detail', kwargs={'pk': manual_project.pk}), admin_user, expect=200)
|
||||||
assert not response.data['summary_fields']['user_capabilities']['start']
|
assert not response.data['summary_fields']['user_capabilities']['start']
|
||||||
assert not response.data['summary_fields']['user_capabilities']['schedule']
|
assert not response.data['summary_fields']['user_capabilities']['schedule']
|
||||||
|
|
||||||
|
|||||||
@@ -133,7 +133,21 @@ def project(instance, organization):
|
|||||||
organization=organization,
|
organization=organization,
|
||||||
playbook_files=['helloworld.yml', 'alt-helloworld.yml'],
|
playbook_files=['helloworld.yml', 'alt-helloworld.yml'],
|
||||||
local_path='_92__test_proj',
|
local_path='_92__test_proj',
|
||||||
scm_revision='1234567890123456789012345678901234567890'
|
scm_revision='1234567890123456789012345678901234567890',
|
||||||
|
scm_url='localhost',
|
||||||
|
scm_type='git'
|
||||||
|
)
|
||||||
|
return prj
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
@mock.patch.object(Project, "update", lambda self, **kwargs: None)
|
||||||
|
def manual_project(instance, organization):
|
||||||
|
prj = Project.objects.create(name="test-manual-proj",
|
||||||
|
description="manual-proj-desc",
|
||||||
|
organization=organization,
|
||||||
|
playbook_files=['helloworld.yml', 'alt-helloworld.yml'],
|
||||||
|
local_path='_92__test_proj'
|
||||||
)
|
)
|
||||||
return prj
|
return prj
|
||||||
|
|
||||||
|
|||||||
@@ -230,9 +230,9 @@ def test_patch_project_null_organization_xfail(patch, project, org_admin):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_cannot_schedule_manual_project(project, admin_user, post):
|
def test_cannot_schedule_manual_project(manual_project, admin_user, post):
|
||||||
response = post(
|
response = post(
|
||||||
reverse('api:project_schedules_list', kwargs={'pk':project.pk,}),
|
reverse('api:project_schedules_list', kwargs={'pk':manual_project.pk,}),
|
||||||
{
|
{
|
||||||
"name": "foo", "description": "", "enabled": True,
|
"name": "foo", "description": "", "enabled": True,
|
||||||
"rrule": "DTSTART:20160926T040000Z RRULE:FREQ=HOURLY;INTERVAL=1",
|
"rrule": "DTSTART:20160926T040000Z RRULE:FREQ=HOURLY;INTERVAL=1",
|
||||||
|
|||||||
Reference in New Issue
Block a user