mirror of
https://github.com/ansible/awx.git
synced 2024-10-31 23:51:09 +03:00
Fix required fields in notifier serializer
Handle the situation where the password field was left as-is when posting the existing encrypted field
This commit is contained in:
parent
b01fe663af
commit
469bff1d0b
@ -2139,6 +2139,10 @@ class NotifierSerializer(BaseSerializer):
|
||||
incorrect_type_fields = []
|
||||
if 'notification_configuration' not in attrs:
|
||||
return attrs
|
||||
if self.context['view'].kwargs:
|
||||
object_actual = self.context['view'].get_object()
|
||||
else:
|
||||
object_actual = None
|
||||
for field in notification_class.init_parameters:
|
||||
if field not in attrs['notification_configuration']:
|
||||
missing_fields.append(field)
|
||||
@ -2149,8 +2153,8 @@ class NotifierSerializer(BaseSerializer):
|
||||
if not type(field_val) in expected_types:
|
||||
incorrect_type_fields.append((field, field_type))
|
||||
continue
|
||||
if field_type == "password" and field_val.startswith('$encrypted$'):
|
||||
missing_fields.append(field)
|
||||
if field_type == "password" and field_val == "$encrypted$" and object_actual is not None:
|
||||
attrs['notification_configuration'][field] = object_actual.notification_configuration[field]
|
||||
error_list = []
|
||||
if missing_fields:
|
||||
error_list.append("Missing required fields for Notification Configuration: {}".format(missing_fields))
|
||||
|
@ -68,6 +68,8 @@ class Notifier(CommonModel):
|
||||
update_fields = kwargs.get('update_fields', [])
|
||||
for field in filter(lambda x: self.notification_class.init_parameters[x]['type'] == "password",
|
||||
self.notification_class.init_parameters):
|
||||
if self.notification_configuration[field].startswith("$encrypted$"):
|
||||
continue
|
||||
if new_instance:
|
||||
value = self.notification_configuration[field]
|
||||
setattr(self, '_saved_{}_{}'.format("config", field), value)
|
||||
@ -84,7 +86,6 @@ class Notifier(CommonModel):
|
||||
self.notification_class.init_parameters):
|
||||
saved_value = getattr(self, '_saved_{}_{}'.format("config", field), '')
|
||||
self.notification_configuration[field] = saved_value
|
||||
#setattr(self.notification_configuration, field, saved_value)
|
||||
if 'notification_configuration' not in update_fields:
|
||||
update_fields.append('notification_configuration')
|
||||
self.save(update_fields=update_fields)
|
||||
|
Loading…
Reference in New Issue
Block a user