Add migration file to define http_method explicitly

This commit is contained in:
beeankha 2019-07-23 14:52:26 -04:00
parent 37e73acb62
commit 7580491f1a
2 changed files with 27 additions and 1 deletions

View File

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations
def add_webhook_notification_template_fields(apps, schema_editor):
# loop over all existing webhook notification templates
# and make sure they have the new "http_method", "username"
# and "password" fields
NotificationTemplate = apps.get_model('main', 'notificationtemplate')
webhooks = NotificationTemplate.objects.filter(notification_type='webhook')
for w in webhooks:
w.notification_configuration['http_method'] = 'POST'
w.save()
class Migration(migrations.Migration):
dependencies = [
('main', '0081_v360_notify_on_start'),
]
operations = [
migrations.RunPython(add_webhook_notification_template_fields, migrations.RunPython.noop),
]

View File

@ -43,7 +43,7 @@ class WebhookBackend(AWXBaseEmailBackend):
chosen_method = getattr(requests, self.http_method.lower(), None)
for m in messages:
auth = None
if self.username:
if self.username or self.password:
auth = (self.username, self.password)
r = chosen_method("{}".format(m.recipients()[0]),
auth=auth,