Procházet zdrojové kódy

feat: option to disable button in slack message

Add a checkbox that lets user disable button which has link to the
document.
version-14
Ankush Menat před 4 roky
rodič
revize
ba1c11008f
V databázi nebyl nalezen žádný známý klíč pro tento podpis ID GPG klíče: 8EA82E09BBD13AAF
2 změnil soubory, kde provedl 64 přidání a 124 odebrání
  1. +51
    -116
      frappe/integrations/doctype/slack_webhook_url/slack_webhook_url.json
  2. +13
    -8
      frappe/integrations/doctype/slack_webhook_url/slack_webhook_url.py

+ 51
- 116
frappe/integrations/doctype/slack_webhook_url/slack_webhook_url.json Zobrazit soubor

@@ -1,126 +1,61 @@
{
"allow_copy": 0,
"allow_guest_to_view": 0,
"allow_import": 0,
"allow_rename": 0,
"autoname": "field:webhook_name",
"beta": 0,
"creation": "2018-05-22 13:20:51.450815",
"custom": 0,
"docstatus": 0,
"doctype": "DocType",
"document_type": "",
"editable_grid": 1,
"engine": "InnoDB",
"actions": [],
"autoname": "field:webhook_name",
"creation": "2018-05-22 13:20:51.450815",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"webhook_name",
"webhook_url",
"show_document_link"
],
"fields": [
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "webhook_name",
"fieldtype": "Data",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 1,
"in_standard_filter": 0,
"label": "Name",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
"fieldname": "webhook_name",
"fieldtype": "Data",
"in_list_view": 1,
"label": "Name",
"reqd": 1,
"unique": 1
},
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "webhook_url",
"fieldtype": "Data",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 1,
"in_standard_filter": 0,
"label": "Webhook URL",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
"fieldname": "webhook_url",
"fieldtype": "Data",
"in_list_view": 1,
"label": "Webhook URL",
"reqd": 1
},
{
"allow_in_quick_entry": 1,
"default": "1",
"fieldname": "show_document_link",
"fieldtype": "Check",
"label": "Show link to document"
}
],
"has_web_view": 0,
"hide_heading": 0,
"hide_toolbar": 0,
"idx": 0,
"image_view": 0,
"in_create": 0,
"is_submittable": 0,
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"modified": "2018-05-22 13:25:24.621129",
"modified_by": "Administrator",
"module": "Integrations",
"name": "Slack Webhook URL",
"name_case": "",
"owner": "Administrator",
],
"links": [],
"modified": "2021-05-12 18:24:37.810235",
"modified_by": "Administrator",
"module": "Integrations",
"name": "Slack Webhook URL",
"owner": "Administrator",
"permissions": [
{
"amend": 0,
"cancel": 0,
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"if_owner": 0,
"import": 0,
"permlevel": 0,
"print": 1,
"read": 1,
"report": 1,
"role": "System Manager",
"set_user_permissions": 0,
"share": 1,
"submit": 0,
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "System Manager",
"share": 1,
"write": 1
}
],
"quick_entry": 1,
"read_only": 0,
"read_only_onload": 0,
"show_name_in_global_search": 0,
"sort_field": "modified",
"sort_order": "DESC",
"track_changes": 1,
"track_seen": 0
],
"quick_entry": 1,
"sort_field": "modified",
"sort_order": "DESC",
"track_changes": 1
}

+ 13
- 8
frappe/integrations/doctype/slack_webhook_url/slack_webhook_url.py Zobrazit soubor

@@ -25,22 +25,27 @@ class SlackWebhookURL(Document):


def send_slack_message(webhook_url, message, reference_doctype, reference_name):
slack_url = frappe.db.get_value("Slack Webhook URL", webhook_url, "webhook_url")
doc_url = get_url_to_form(reference_doctype, reference_name)
attachments = [
{
data = {"text": message, "attachments": []}

slack_url, show_link = frappe.db.get_value(
"Slack Webhook URL", webhook_url, ["webhook_url", "show_document_link"]
)

if show_link:
doc_url = get_url_to_form(reference_doctype, reference_name)
link_to_doc = {
"fallback": _("See the document at {0}").format(doc_url),
"actions": [
{
"type": "button",
"text": _("Go to the document"),
"url": doc_url,
"style": "primary"
"style": "primary",
}
]
],
}
]
data = {"text": message, "attachments": attachments}
data["attachments"].append(link_to_doc)
r = requests.post(slack_url, data=json.dumps(data))

if not r.ok:


Načítá se…
Zrušit
Uložit