mirror of
https://github.com/ansible/awx.git
synced 2026-03-04 02:01:01 -03:30
Change serializer to take in init paramdefault value
This commit is contained in:
@@ -4618,12 +4618,15 @@ class NotificationTemplateSerializer(BaseSerializer):
|
|||||||
object_actual = self.context['view'].get_object()
|
object_actual = self.context['view'].get_object()
|
||||||
else:
|
else:
|
||||||
object_actual = None
|
object_actual = None
|
||||||
for field in notification_class.init_parameters:
|
for field, params in notification_class.init_parameters.items():
|
||||||
if field not in attrs['notification_configuration']:
|
if field not in attrs['notification_configuration']:
|
||||||
missing_fields.append(field)
|
if 'default' in params:
|
||||||
|
attrs['notification_configuration'][field] = params['default']
|
||||||
|
else:
|
||||||
|
missing_fields.append(field)
|
||||||
continue
|
continue
|
||||||
field_val = attrs['notification_configuration'][field]
|
field_val = attrs['notification_configuration'][field]
|
||||||
field_type = notification_class.init_parameters[field]['type']
|
field_type = params['type']
|
||||||
expected_types = self.type_map[field_type]
|
expected_types = self.type_map[field_type]
|
||||||
if not type(field_val) in expected_types:
|
if not type(field_val) in expected_types:
|
||||||
incorrect_type_fields.append((field, field_type))
|
incorrect_type_fields.append((field, field_type))
|
||||||
|
|||||||
@@ -18,17 +18,10 @@ class CustomEmailBackend(EmailBackend):
|
|||||||
"use_ssl": {"label": "Use SSL", "type": "bool"},
|
"use_ssl": {"label": "Use SSL", "type": "bool"},
|
||||||
"sender": {"label": "Sender Email", "type": "string"},
|
"sender": {"label": "Sender Email", "type": "string"},
|
||||||
"recipients": {"label": "Recipient List", "type": "list"},
|
"recipients": {"label": "Recipient List", "type": "list"},
|
||||||
"timeout": {"label": "Timeout", "type": "int"}}
|
"timeout": {"label": "Timeout", "type": "int", "default": 30}}
|
||||||
recipient_parameter = "recipients"
|
recipient_parameter = "recipients"
|
||||||
sender_parameter = "sender"
|
sender_parameter = "sender"
|
||||||
|
|
||||||
def __init__(self, timeout=None, **kwargs):
|
|
||||||
self.timeout = timeout
|
|
||||||
if timeout is None:
|
|
||||||
self.timeout == 30
|
|
||||||
if not (1 <= timeout <= 120):
|
|
||||||
raise ValueError("Email timeout range needs to be between 1 and 120 seconds")
|
|
||||||
return super(CustomEmailBackend, self).__init__(timeout, **kwargs)
|
|
||||||
|
|
||||||
def format_body(self, body):
|
def format_body(self, body):
|
||||||
if "body" in body:
|
if "body" in body:
|
||||||
|
|||||||
Reference in New Issue
Block a user