Only allow specified fields of doc
This commit is contained in:
parent
beb6318d88
commit
24a2656746
2 changed files with 10 additions and 4 deletions
|
|
@ -14,7 +14,7 @@ class Webhook(Document):
|
|||
def validate(self):
|
||||
self.validate_docevent()
|
||||
self.validate_request_url()
|
||||
self.validate_repeating_companies()
|
||||
self.validate_repeating_fields()
|
||||
def validate_docevent(self):
|
||||
if self.webhook_doctype:
|
||||
is_submittable = frappe.get_value("DocType", self.webhook_doctype, "is_submittable")
|
||||
|
|
@ -27,7 +27,7 @@ class Webhook(Document):
|
|||
raise frappe.ValidationError
|
||||
except Exception as e:
|
||||
frappe.throw(_("Check Request URL"), exc=e)
|
||||
def validate_repeating_companies(self):
|
||||
def validate_repeating_fields(self):
|
||||
"""Error when Same Field is entered multiple times in webhook_data"""
|
||||
webhook_data = []
|
||||
for entry in self.webhook_data:
|
||||
|
|
|
|||
|
|
@ -2,12 +2,13 @@
|
|||
# MIT License. See license.txt
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import frappe, requests
|
||||
import frappe, requests, json
|
||||
from frappe import _
|
||||
|
||||
# Doc Events Webhook
|
||||
def doc_event_webhook(doc, method=None, *args, **kwargs):
|
||||
headers = {}
|
||||
data = {}
|
||||
filters = {
|
||||
"webhook_doctype": doc.get("doctype"),
|
||||
"webhook_docevent": method
|
||||
|
|
@ -19,8 +20,13 @@ def doc_event_webhook(doc, method=None, *args, **kwargs):
|
|||
for h in webhook.webhook_headers:
|
||||
if h.get("key") and h.get("value"):
|
||||
headers[h.get("key")] = h.get("value")
|
||||
if webhook.webhook_data:
|
||||
for k, v in doc.as_dict().items():
|
||||
for w in webhook.webhook_data:
|
||||
if k == w.fieldname:
|
||||
data[w.key] = v
|
||||
try:
|
||||
r = requests.post(webhook.request_url, data=doc.as_json(), headers=headers, timeout=5)
|
||||
r = requests.post(webhook.request_url, data=json.dumps(data), headers=headers, timeout=5)
|
||||
frappe.logger().debug({"webhook_success":r.text, "webhook": webhook.as_json()})
|
||||
except Exception as e:
|
||||
frappe.logger().debug({"webhook_error":r.text, "webhook": webhook.as_json()})
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue