1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

implements #2933 - username in webhooks

This commit is contained in:
John Anderson
2019-03-24 15:31:12 -04:00
parent 3acc8ca3ab
commit 2170eedf08
4 changed files with 8 additions and 5 deletions

View File

@ -2,6 +2,7 @@ v2.5.9 (FUTURE)
## Enhancements ## Enhancements
* [#2933](https://github.com/digitalocean/netbox/issues/2933) - Add username to outbound webhook requests
* [#3011](https://github.com/digitalocean/netbox/issues/3011) - Add SSL support for django-rq (requires django-rq v1.3.1+) * [#3011](https://github.com/digitalocean/netbox/issues/3011) - Add SSL support for django-rq (requires django-rq v1.3.1+)
## Bug Fixes ## Bug Fixes

View File

@ -37,7 +37,7 @@ def _record_object_deleted(request, instance, **kwargs):
if hasattr(instance, 'log_change'): if hasattr(instance, 'log_change'):
instance.log_change(request.user, request.id, OBJECTCHANGE_ACTION_DELETE) instance.log_change(request.user, request.id, OBJECTCHANGE_ACTION_DELETE)
enqueue_webhooks(instance, OBJECTCHANGE_ACTION_DELETE) enqueue_webhooks(instance, request.user, OBJECTCHANGE_ACTION_DELETE)
class ObjectChangeMiddleware(object): class ObjectChangeMiddleware(object):
@ -83,7 +83,7 @@ class ObjectChangeMiddleware(object):
obj.log_change(request.user, request.id, action) obj.log_change(request.user, request.id, action)
# Enqueue webhooks # Enqueue webhooks
enqueue_webhooks(obj, action) enqueue_webhooks(obj, request.user, action)
# Housekeeping: 1% chance of clearing out expired ObjectChanges # Housekeeping: 1% chance of clearing out expired ObjectChanges
if _thread_locals.changed_objects and settings.CHANGELOG_RETENTION and random.randint(1, 100) == 1: if _thread_locals.changed_objects and settings.CHANGELOG_RETENTION and random.randint(1, 100) == 1:

View File

@ -9,7 +9,7 @@ from utilities.api import get_serializer_for_model
from .constants import WEBHOOK_MODELS from .constants import WEBHOOK_MODELS
def enqueue_webhooks(instance, action): def enqueue_webhooks(instance, user, action):
""" """
Find Webhook(s) assigned to this instance + action and enqueue them Find Webhook(s) assigned to this instance + action and enqueue them
to be processed to be processed
@ -47,5 +47,6 @@ def enqueue_webhooks(instance, action):
serializer.data, serializer.data,
instance._meta.model_name, instance._meta.model_name,
action, action,
str(datetime.datetime.now()) str(datetime.datetime.now()),
user.username
) )

View File

@ -10,7 +10,7 @@ from extras.constants import WEBHOOK_CT_JSON, WEBHOOK_CT_X_WWW_FORM_ENCODED, OBJ
@job('default') @job('default')
def process_webhook(webhook, data, model_name, event, timestamp): def process_webhook(webhook, data, model_name, event, timestamp, username):
""" """
Make a POST request to the defined Webhook Make a POST request to the defined Webhook
""" """
@ -18,6 +18,7 @@ def process_webhook(webhook, data, model_name, event, timestamp):
'event': dict(OBJECTCHANGE_ACTION_CHOICES)[event].lower(), 'event': dict(OBJECTCHANGE_ACTION_CHOICES)[event].lower(),
'timestamp': timestamp, 'timestamp': timestamp,
'model': model_name, 'model': model_name,
'username': username,
'data': data 'data': data
} }
headers = { headers = {