mirror of
https://github.com/ansible/awx.git
synced 2026-05-07 09:27:36 -02:30
Merge pull request #1569 from AlanCoding/relaunch_survey
Allow normal users to relaunch jobs with survey answers
This commit is contained in:
@@ -963,7 +963,17 @@ class JobLaunchConfig(LaunchTimeConfig):
|
|||||||
launching with those prompts
|
launching with those prompts
|
||||||
'''
|
'''
|
||||||
prompts = self.prompts_dict()
|
prompts = self.prompts_dict()
|
||||||
for field_name, ask_field_name in template.get_ask_mapping().items():
|
ask_mapping = template.get_ask_mapping()
|
||||||
|
if template.survey_enabled and (not template.ask_variables_on_launch):
|
||||||
|
ask_mapping.pop('extra_vars')
|
||||||
|
provided_vars = set(prompts['extra_vars'].keys())
|
||||||
|
survey_vars = set(
|
||||||
|
element.get('variable') for element in
|
||||||
|
template.survey_spec.get('spec', {}) if 'variable' in element
|
||||||
|
)
|
||||||
|
if provided_vars - survey_vars:
|
||||||
|
return True
|
||||||
|
for field_name, ask_field_name in ask_mapping.items():
|
||||||
if field_name in prompts and not getattr(template, ask_field_name):
|
if field_name in prompts and not getattr(template, ask_field_name):
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ from awx.main.tasks import RunJob
|
|||||||
from awx.main.models import (
|
from awx.main.models import (
|
||||||
Job,
|
Job,
|
||||||
JobTemplate,
|
JobTemplate,
|
||||||
|
JobLaunchConfig,
|
||||||
WorkflowJobTemplate
|
WorkflowJobTemplate
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -137,6 +138,27 @@ def test_job_args_unredacted_passwords(job, tmpdir_factory):
|
|||||||
assert extra_vars['secret_key'] == 'my_password'
|
assert extra_vars['secret_key'] == 'my_password'
|
||||||
|
|
||||||
|
|
||||||
|
def test_launch_config_has_unprompted_vars(survey_spec_factory):
|
||||||
|
jt = JobTemplate(
|
||||||
|
survey_enabled = True,
|
||||||
|
survey_spec = survey_spec_factory(['question1', 'question2'])
|
||||||
|
)
|
||||||
|
unprompted_config = JobLaunchConfig(
|
||||||
|
extra_data = {
|
||||||
|
'question1': 'foobar',
|
||||||
|
'question4': 'foobar'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
assert unprompted_config.has_unprompted(jt)
|
||||||
|
allowed_config = JobLaunchConfig(
|
||||||
|
extra_data = {
|
||||||
|
'question1': 'foobar',
|
||||||
|
'question2': 'foobar'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
assert not allowed_config.has_unprompted(jt)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.survey
|
@pytest.mark.survey
|
||||||
def test_update_kwargs_survey_invalid_default(survey_spec_factory):
|
def test_update_kwargs_survey_invalid_default(survey_spec_factory):
|
||||||
spec = survey_spec_factory('var2')
|
spec = survey_spec_factory('var2')
|
||||||
|
|||||||
Reference in New Issue
Block a user