mirror of
https://github.com/ansible/awx.git
synced 2026-01-14 03:10:42 -03:30
Merge pull request #1569 from AlanCoding/relaunch_survey
Allow normal users to relaunch jobs with survey answers
This commit is contained in:
commit
30fb4076df
@ -963,7 +963,17 @@ class JobLaunchConfig(LaunchTimeConfig):
|
||||
launching with those prompts
|
||||
'''
|
||||
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):
|
||||
return True
|
||||
else:
|
||||
|
||||
@ -7,6 +7,7 @@ from awx.main.tasks import RunJob
|
||||
from awx.main.models import (
|
||||
Job,
|
||||
JobTemplate,
|
||||
JobLaunchConfig,
|
||||
WorkflowJobTemplate
|
||||
)
|
||||
|
||||
@ -137,6 +138,27 @@ def test_job_args_unredacted_passwords(job, tmpdir_factory):
|
||||
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
|
||||
def test_update_kwargs_survey_invalid_default(survey_spec_factory):
|
||||
spec = survey_spec_factory('var2')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user