ansible / awx

AWX provides a web-based user interface, REST API, and task engine built on top of Ansible. It is one of the upstream projects for Red Hat Ansible Automation Platform.
Other
13.99k stars 3.42k forks source link

In Survey Spec if the choices is an array of strings the UI fails #11326

Open mkanoor opened 2 years ago

mkanoor commented 2 years ago

Please confirm the following

Summary

In the AAP UI when choices are added for a multi select field they are stored as a string with \n as the delimiter. e.g choices: "NJ\nPA\OK" The REST API allows for the choices to be stored as an array of strings e.g.

"choices": [
        "NJ",
        "PA",
        "OK"
      ]

So if someone uses a REST API to add a Survey spec and specifies an array/list of strings the REST API call succeeds and stores the value but when the UI tries to display it fails.

AWX version

AWX 4.0.0

Installation method

openshift

Modifications

no

Ansible version

No response

Operating system

Linux

Web browser

Chrome

Steps to reproduce

Create a Job Template Add a Survey Spec for the Job Template using a REST API with the following payload

POST https://{{TowerIP}}/api/v2/job_templates/{{job_template_id}}/survey_spec/
BODY

  "name": "",
  "description": "",
  "spec": [
    {
      "question_name": "State",
      "question_description": "The state where you live",
      "required": true,
      "type": "multiplechoice",
      "variable": "state",
      "min": 0,
      "max": 1024,
      "new_question": false,
      "default": "",
      "choices": [
        "NJ",
        "PA",
        "OK"
      ]
    }
  ]
}

After the Survey Spec has been created click on the Survey Spec "state" field and the UI gets an error

Screen Shot 2021-11-09 at 4 15 49 PM

Survey Spec

Screen Shot 2021-11-09 at 4 16 19 PM

Expected results

The UI should be able to display the survey spec item or reject the REST API call when arrays are used for choices.

Actual results

The REST API call succeeds for both GET and POST but the UI fails.

Additional information

No response

jbradberry commented 2 years ago

I believe the culprit is here: https://github.com/ansible/awx/blob/6a17e5b65bf9421c2e650d23817c79ce81248c6f/awx/api/views/__init__.py#L2568

If what is passed in is a list instead of a string, as you can do in the API, this block of code that standardizes the input for this entry will be bypassed.