mirror of
https://github.com/ansible/awx.git
synced 2026-02-15 18:20:00 -03:30
fix a bug that prevented JT admins from editing custom virtualenvs
see: https://github.com/ansible/tower/issues/1754
This commit is contained in:
@@ -404,9 +404,11 @@ class ApiV1ConfigView(APIView):
|
|||||||
data.update(dict(
|
data.update(dict(
|
||||||
project_base_dir = settings.PROJECTS_ROOT,
|
project_base_dir = settings.PROJECTS_ROOT,
|
||||||
project_local_paths = Project.get_local_path_choices(),
|
project_local_paths = Project.get_local_path_choices(),
|
||||||
custom_virtualenvs = get_custom_venv_choices(),
|
|
||||||
))
|
))
|
||||||
|
|
||||||
|
if JobTemplate.accessible_objects(request.user, 'admin_role').exists():
|
||||||
|
data['custom_virtualenvs'] = get_custom_venv_choices()
|
||||||
|
|
||||||
return Response(data)
|
return Response(data)
|
||||||
|
|
||||||
def post(self, request):
|
def post(self, request):
|
||||||
|
|||||||
@@ -1366,6 +1366,7 @@ class JobTemplateAccess(BaseAccess):
|
|||||||
'job_tags', 'force_handlers', 'skip_tags', 'ask_variables_on_launch',
|
'job_tags', 'force_handlers', 'skip_tags', 'ask_variables_on_launch',
|
||||||
'ask_tags_on_launch', 'ask_job_type_on_launch', 'ask_skip_tags_on_launch',
|
'ask_tags_on_launch', 'ask_job_type_on_launch', 'ask_skip_tags_on_launch',
|
||||||
'ask_inventory_on_launch', 'ask_credential_on_launch', 'survey_enabled',
|
'ask_inventory_on_launch', 'ask_credential_on_launch', 'survey_enabled',
|
||||||
|
'custom_virtualenv',
|
||||||
|
|
||||||
# These fields are ignored, but it is convenient for QA to allow clients to post them
|
# These fields are ignored, but it is convenient for QA to allow clients to post them
|
||||||
'last_job_run', 'created', 'modified',
|
'last_job_run', 'created', 'modified',
|
||||||
|
|||||||
@@ -625,17 +625,31 @@ def test_save_survey_passwords_on_migration(job_template_with_survey_passwords):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_job_template_custom_virtualenv(get, patch, organization_factory, job_template_factory):
|
@pytest.mark.parametrize('access', ["superuser", "admin", "peon"])
|
||||||
|
def test_job_template_custom_virtualenv(get, patch, organization_factory, job_template_factory, alice, access):
|
||||||
objs = organization_factory("org", superusers=['admin'])
|
objs = organization_factory("org", superusers=['admin'])
|
||||||
jt = job_template_factory("jt", organization=objs.organization,
|
jt = job_template_factory("jt", organization=objs.organization,
|
||||||
inventory='test_inv', project='test_proj').job_template
|
inventory='test_inv', project='test_proj').job_template
|
||||||
|
|
||||||
|
user = alice
|
||||||
|
if access == "superuser":
|
||||||
|
user = objs.superusers.admin
|
||||||
|
elif access == "admin":
|
||||||
|
jt.admin_role.members.add(alice)
|
||||||
|
else:
|
||||||
|
jt.read_role.members.add(alice)
|
||||||
|
|
||||||
with TemporaryDirectory(dir=settings.BASE_VENV_PATH) as temp_dir:
|
with TemporaryDirectory(dir=settings.BASE_VENV_PATH) as temp_dir:
|
||||||
admin = objs.superusers.admin
|
|
||||||
os.makedirs(os.path.join(temp_dir, 'bin', 'activate'))
|
os.makedirs(os.path.join(temp_dir, 'bin', 'activate'))
|
||||||
url = reverse('api:job_template_detail', kwargs={'pk': jt.id})
|
url = reverse('api:job_template_detail', kwargs={'pk': jt.id})
|
||||||
patch(url, {'custom_virtualenv': temp_dir}, user=admin, expect=200)
|
|
||||||
assert get(url, user=admin).data['custom_virtualenv'] == os.path.join(temp_dir, '')
|
if access == "peon":
|
||||||
|
patch(url, {'custom_virtualenv': temp_dir}, user=user, expect=403)
|
||||||
|
assert 'custom_virtualenv' not in get(url, user=user)
|
||||||
|
assert JobTemplate.objects.get(pk=jt.id).custom_virtualenv is None
|
||||||
|
else:
|
||||||
|
patch(url, {'custom_virtualenv': temp_dir}, user=user, expect=200)
|
||||||
|
assert get(url, user=user).data['custom_virtualenv'] == os.path.join(temp_dir, '')
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
|
|||||||
Reference in New Issue
Block a user