mirror of
https://github.com/ansible/awx.git
synced 2026-05-13 04:17:36 -02:30
workflow JT survey and launch serializer in functional state
This commit is contained in:
@@ -2609,20 +2609,21 @@ class JobLaunchSerializer(BaseSerializer):
|
|||||||
|
|
||||||
class WorkflowJobLaunchSerializer(BaseSerializer):
|
class WorkflowJobLaunchSerializer(BaseSerializer):
|
||||||
|
|
||||||
# can_start_without_user_input = serializers.BooleanField(read_only=True)
|
can_start_without_user_input = serializers.BooleanField(read_only=True)
|
||||||
# variables_needed_to_start = serializers.ReadOnlyField()
|
variables_needed_to_start = serializers.ReadOnlyField()
|
||||||
|
|
||||||
survey_enabled = serializers.SerializerMethodField()
|
survey_enabled = serializers.SerializerMethodField()
|
||||||
extra_vars = VerbatimField(required=False, write_only=True)
|
extra_vars = VerbatimField(required=False, write_only=True)
|
||||||
# workflow_job_template_data = serializers.SerializerMethodField()
|
warnings = serializers.SerializerMethodField()
|
||||||
# warnings =
|
workflow_job_template_data = serializers.SerializerMethodField()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = WorkflowJobTemplate
|
model = WorkflowJobTemplate
|
||||||
fields = ('*',#'can_start_without_user_input',
|
fields = ('can_start_without_user_input', 'extra_vars', 'warnings',
|
||||||
'extra_vars',
|
'survey_enabled', 'variables_needed_to_start',
|
||||||
'survey_enabled')#, 'variables_needed_to_start',
|
'workflow_job_template_data')
|
||||||
# 'workflow_job_template_data')
|
|
||||||
|
def get_warnings(self, obj):
|
||||||
|
return obj.get_warnings()
|
||||||
|
|
||||||
def get_survey_enabled(self, obj):
|
def get_survey_enabled(self, obj):
|
||||||
if obj:
|
if obj:
|
||||||
|
|||||||
@@ -2803,13 +2803,6 @@ class WorkflowJobTemplateLaunch(RetrieveAPIView):
|
|||||||
if extra_vars:
|
if extra_vars:
|
||||||
data['extra_vars'] = extra_vars
|
data['extra_vars'] = extra_vars
|
||||||
return data
|
return data
|
||||||
|
|
||||||
# def get(self, request, *args, **kwargs):
|
|
||||||
# data = {}
|
|
||||||
# obj = self.get_object()
|
|
||||||
# data['warnings'] = obj.get_warnings()
|
|
||||||
# data['variables_needed_to_start'] = obj.variables_needed_to_start
|
|
||||||
# return Response(data)
|
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
obj = self.get_object()
|
obj = self.get_object()
|
||||||
@@ -2824,8 +2817,11 @@ class WorkflowJobTemplateLaunch(RetrieveAPIView):
|
|||||||
|
|
||||||
new_job = obj.create_unified_job(**prompted_fields)
|
new_job = obj.create_unified_job(**prompted_fields)
|
||||||
new_job.signal_start(**prompted_fields)
|
new_job.signal_start(**prompted_fields)
|
||||||
data = dict(workflow_job=new_job.id)
|
|
||||||
|
data = OrderedDict()
|
||||||
data['ignored_fields'] = ignored_fields
|
data['ignored_fields'] = ignored_fields
|
||||||
|
data.update(WorkflowJobSerializer(new_job, context=self.get_serializer_context()).to_representation(new_job))
|
||||||
|
data['workflow_job'] = new_job.id
|
||||||
return Response(data, status=status.HTTP_201_CREATED)
|
return Response(data, status=status.HTTP_201_CREATED)
|
||||||
|
|
||||||
# TODO:
|
# TODO:
|
||||||
|
|||||||
@@ -1541,7 +1541,8 @@ class WorkflowJobTemplateAccess(BaseAccess):
|
|||||||
|
|
||||||
def can_change(self, obj, data):
|
def can_change(self, obj, data):
|
||||||
# Check survey license if surveys are added to WFJTs
|
# Check survey license if surveys are added to WFJTs
|
||||||
if 'survey_enabled' in data and obj.survey_enabled != data['survey_enabled'] and data['survey_enabled']:
|
if (data and 'survey_enabled' in data and
|
||||||
|
obj.survey_enabled != data['survey_enabled'] and data['survey_enabled']):
|
||||||
self.check_license(feature='surveys')
|
self.check_license(feature='surveys')
|
||||||
|
|
||||||
if self.user.is_superuser:
|
if self.user.is_superuser:
|
||||||
|
|||||||
@@ -332,9 +332,9 @@ class WorkflowJobTemplate(UnifiedJobTemplate, WorkflowJobOptions, SurveyJobTempl
|
|||||||
survey_vars = [question['variable'] for question in self.survey_spec.get('spec', [])]
|
survey_vars = [question['variable'] for question in self.survey_spec.get('spec', [])]
|
||||||
for key in extra_vars:
|
for key in extra_vars:
|
||||||
if key in survey_vars:
|
if key in survey_vars:
|
||||||
prompted_fields[field][key] = extra_vars[key]
|
prompted_fields['extra_vars'][key] = extra_vars[key]
|
||||||
else:
|
else:
|
||||||
ignored_fields[field][key] = extra_vars[key]
|
ignored_fields['extra_vars'][key] = extra_vars[key]
|
||||||
else:
|
else:
|
||||||
prompted_fields['extra_vars'] = extra_vars
|
prompted_fields['extra_vars'] = extra_vars
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user