Add more support for Webhook URL

pull/586/head
TonyJabbour 2021-09-28 20:48:47 +02:00
parent 06a886732c
commit bc91c202a8
2 changed files with 8 additions and 4 deletions

View File

@ -374,7 +374,7 @@ def api_validate_tracker_to_add(tracker , tracker_type, nb_words=1):
return ({"status": "error", "reason": "Incorrect type"}, 400)
return ({"status": "success", "tracker": tracker, "type": tracker_type}, 200)
def create_tracker(tracker, tracker_type, user_id, level, tags, mails, description, dashboard=0, tracker_uuid=None, sources=[]):
def create_tracker(tracker, tracker_type, user_id, level, tags, mails, description, webhook, dashboard=0, tracker_uuid=None, sources=[]):
# edit tracker
if tracker_uuid:
edit_tracker = True
@ -415,6 +415,9 @@ def create_tracker(tracker, tracker_type, user_id, level, tags, mails, descripti
if description:
r_serv_tracker.hset('tracker:{}'.format(tracker_uuid), 'description', description)
if webhook:
r_serv_tracker.hset('tracker:{}'.format(tracker_uuid), 'webhook', webhook)
# type change
if edit_tracker:
r_serv_tracker.srem('all:tracker:{}'.format(old_type), old_tracker)
@ -486,7 +489,8 @@ def api_add_tracker(dict_input, user_id):
nb_words = dict_input.get('nb_words', 1)
description = dict_input.get('description', '')
description = escape(description)
webhook = dict_input.get('webhook', '')
webhook = escape(webhook)
res = api_validate_tracker_to_add(tracker , tracker_type, nb_words=nb_words)
if res[1]!=200:
return res
@ -528,7 +532,7 @@ def api_add_tracker(dict_input, user_id):
if is_tracker_in_user_level(tracker, tracker_type, user_id) and not tracker_uuid:
return ({"status": "error", "reason": "Tracker already exist"}, 409)
tracker_uuid = create_tracker(tracker , tracker_type, user_id, level, tags, mails, description, tracker_uuid=tracker_uuid, sources=sources)
tracker_uuid = create_tracker(tracker , tracker_type, user_id, level, tags, mails, description, webhook, tracker_uuid=tracker_uuid, sources=sources)
return ({'tracker': tracker, 'type': tracker_type, 'uuid': tracker_uuid}, 200)

View File

@ -56,7 +56,7 @@
</div>
<div class="input-group mb-2 mr-sm-2">
<div class="input-group-prepend">
<div class="input-group-text bg-secondary text-white"><i class="fas fa-at"></i></div>
<div class="input-group-text bg-info text-white"><i class="fas fa-anchor"></i></div>
</div>
<input id="webhook" name="webhook" class="form-control" placeholder="Webhook URL" type="text" {%if dict_tracker%}{%if dict_tracker['webhook']%}value="{{dict_tracker['webhook']}}"{%endif%}{%endif%}>
</div>