mirror of
https://github.com/ansible/awx.git
synced 2026-01-13 02:50:02 -03:30
Fix extra_vars/survey handling since request.data is now an OrderedDict.
This commit is contained in:
parent
99150b5a05
commit
d8ae1115f0
@ -8,7 +8,6 @@ import re
|
||||
import logging
|
||||
from collections import OrderedDict
|
||||
from dateutil import rrule
|
||||
from ast import literal_eval
|
||||
|
||||
from rest_framework_mongoengine.serializers import DocumentSerializer
|
||||
|
||||
@ -1955,6 +1954,7 @@ class JobLaunchSerializer(BaseSerializer):
|
||||
variables_needed_to_start = serializers.ReadOnlyField()
|
||||
credential_needed_to_start = serializers.SerializerMethodField()
|
||||
survey_enabled = serializers.SerializerMethodField()
|
||||
extra_vars = VerbatimField(required=False)
|
||||
|
||||
class Meta:
|
||||
model = JobTemplate
|
||||
@ -2001,20 +2001,16 @@ class JobLaunchSerializer(BaseSerializer):
|
||||
except KeyError:
|
||||
errors['passwords_needed_to_start'] = credential.passwords_needed
|
||||
|
||||
extra_vars = force_text(attrs.get('extra_vars', {}))
|
||||
try:
|
||||
extra_vars = literal_eval(extra_vars)
|
||||
extra_vars = json.dumps(extra_vars)
|
||||
except Exception:
|
||||
pass
|
||||
extra_vars = attrs.get('extra_vars', {})
|
||||
|
||||
try:
|
||||
extra_vars = json.loads(extra_vars)
|
||||
except (ValueError, TypeError):
|
||||
if isinstance(extra_vars, basestring):
|
||||
try:
|
||||
extra_vars = yaml.safe_load(extra_vars)
|
||||
except (yaml.YAMLError, TypeError, AttributeError):
|
||||
errors['extra_vars'] = 'Must be valid JSON or YAML'
|
||||
extra_vars = json.loads(extra_vars)
|
||||
except (ValueError, TypeError):
|
||||
try:
|
||||
extra_vars = yaml.safe_load(extra_vars)
|
||||
except (yaml.YAMLError, TypeError, AttributeError):
|
||||
errors['extra_vars'] = 'Must be valid JSON or YAML'
|
||||
|
||||
if not isinstance(extra_vars, dict):
|
||||
extra_vars = {}
|
||||
|
||||
@ -226,7 +226,7 @@ class ApiV1ConfigView(APIView):
|
||||
def post(self, request):
|
||||
if not request.user.is_superuser:
|
||||
return Response(None, status=status.HTTP_404_NOT_FOUND)
|
||||
if not type(request.data) == dict:
|
||||
if not isinstance(request.data, dict):
|
||||
return Response({"error": "Invalid license data"}, status=status.HTTP_400_BAD_REQUEST)
|
||||
if "eula_accepted" not in request.data:
|
||||
return Response({"error": "Missing 'eula_accepted' property"}, status=status.HTTP_400_BAD_REQUEST)
|
||||
@ -1941,13 +1941,13 @@ class JobTemplateSurveySpec(GenericAPIView):
|
||||
return Response(dict(error="'description' missing from survey spec"), status=status.HTTP_400_BAD_REQUEST)
|
||||
if "spec" not in obj.survey_spec:
|
||||
return Response(dict(error="'spec' missing from survey spec"), status=status.HTTP_400_BAD_REQUEST)
|
||||
if type(obj.survey_spec["spec"]) != list:
|
||||
if not isinstance(obj.survey_spec["spec"], list):
|
||||
return Response(dict(error="'spec' must be a list of items"), status=status.HTTP_400_BAD_REQUEST)
|
||||
if len(obj.survey_spec["spec"]) < 1:
|
||||
return Response(dict(error="'spec' doesn't contain any items"), status=status.HTTP_400_BAD_REQUEST)
|
||||
idx = 0
|
||||
for survey_item in obj.survey_spec["spec"]:
|
||||
if type(survey_item) != dict:
|
||||
if not isinstance(survey_item, dict):
|
||||
return Response(dict(error="survey element %s is not a json object" % str(idx)), status=status.HTTP_400_BAD_REQUEST)
|
||||
if "type" not in survey_item:
|
||||
return Response(dict(error="'type' missing from survey element %s" % str(idx)), status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
@ -307,7 +307,7 @@ class JobTemplate(UnifiedJobTemplate, JobOptions):
|
||||
except Exception:
|
||||
try:
|
||||
kwargs_extra_vars = yaml.safe_load(kwargs_extra_vars)
|
||||
assert type(kwargs_extra_vars) is dict
|
||||
assert isinstance(kwargs_extra_vars, dict)
|
||||
except:
|
||||
kwargs_extra_vars = {}
|
||||
else:
|
||||
@ -487,7 +487,7 @@ class Job(UnifiedJob, JobOptions):
|
||||
|
||||
def handle_extra_data(self, extra_data):
|
||||
extra_vars = {}
|
||||
if type(extra_data) == dict:
|
||||
if isinstance(extra_data, dict):
|
||||
extra_vars = extra_data
|
||||
elif extra_data is None:
|
||||
return
|
||||
@ -1070,7 +1070,7 @@ class SystemJob(UnifiedJob, SystemJobOptions):
|
||||
|
||||
def handle_extra_data(self, extra_data):
|
||||
extra_vars = {}
|
||||
if type(extra_data) == dict:
|
||||
if isinstance(extra_data, dict):
|
||||
extra_vars = extra_data
|
||||
elif extra_data is None:
|
||||
return
|
||||
|
||||
@ -321,7 +321,7 @@ class UnifiedJobTemplate(PolymorphicModel, CommonModelNameNotUnique):
|
||||
value = value.id
|
||||
create_kwargs[id_field_name] = value
|
||||
elif field_name in kwargs:
|
||||
if field_name == 'extra_vars' and type(kwargs[field_name]) == dict:
|
||||
if field_name == 'extra_vars' and isinstance(kwargs[field_name], dict):
|
||||
create_kwargs[field_name] = json.dumps(kwargs['extra_vars'])
|
||||
else:
|
||||
create_kwargs[field_name] = kwargs[field_name]
|
||||
|
||||
@ -758,6 +758,7 @@ class ProjectsTest(BaseTransactionTest):
|
||||
team_permission['name'] += '2'
|
||||
team_permission['user'] = user.pk
|
||||
self.post(url, team_permission, expect=400, auth=self.get_super_credentials())
|
||||
del team_permission['user']
|
||||
|
||||
# can list permissions on a user
|
||||
url = reverse('api:user_permissions_list', args=(user.pk,))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user