improve sanitation of empty credential values to match API v1 behavior

This is mostly backwards compatability to avoid surprises: in 3.1.x
if you submit a field value with `null` or an empty string to
a CharField, it's treated as an empty string (and SSH key validation
is skipped).  For boolean field values (`net.authorize`), `null` and
empty string are coerced to `False`.

see: #7216
see: #7218
This commit is contained in:
Ryan Petrello
2017-07-21 11:21:40 -04:00
parent 825dfc9df9
commit a640d6afec
3 changed files with 72 additions and 3 deletions

View File

@@ -457,6 +457,13 @@ class CredentialType(CommonModelNameNotUnique):
if field.get('ask_at_runtime', False) is True
]
def default_for_field(self, field_id):
for field in self.inputs.get('fields', []):
if field['id'] == field_id:
if 'choices' in field:
return field['choices'][0]
return {'string': '', 'boolean': False}[field['type']]
@classmethod
def default(cls, f):
func = functools.partial(f, cls)