Переглянути джерело

Merge pull request #11409 from Mangesh-Khairnar/fix-notification-links

fix(notification): add minor enhancements
version-14
mergify[bot] 4 роки тому
committed by GitHub
джерело
коміт
a8fcaec398
Не вдалося знайти GPG ключ що відповідає даному підпису Ідентифікатор GPG ключа: 4AEE18F83AFDEB23
5 змінених файлів з 35 додано та 14 видалено
  1. +2
    -1
      frappe/email/doctype/notification/notification.js
  2. +3
    -2
      frappe/email/doctype/notification/notification.json
  3. +7
    -1
      frappe/email/doctype/notification/notification.py
  4. +13
    -3
      frappe/integrations/doctype/twilio_settings/twilio_settings.json
  5. +10
    -7
      frappe/integrations/doctype/twilio_settings/twilio_settings.py

+ 2
- 1
frappe/email/doctype/notification/notification.js Переглянути файл

@@ -102,7 +102,7 @@ frappe.notification = {
<h5>Message Example</h5>

<pre>
Your {{ doc.name }} order of {{ doc.total }} has shipped and should be delivered on {{ doc.date }}. Details : {{doc.customer}}
Your appointment is coming up on {{ doc.date }} at {{ doc.time }}
</pre>`;
} else if (frm.doc.channel === 'Email') {
template = `<h5>Message Example</h5>
@@ -166,6 +166,7 @@ frappe.ui.form.on('Notification', {
},
refresh: function(frm) {
frappe.notification.setup_fieldname_select(frm);
frappe.notification.setup_example_message(frm);
frm.get_field('is_standard').toggle(frappe.boot.developer_mode);
frm.trigger('event');
},


+ 3
- 2
frappe/email/doctype/notification/notification.json Переглянути файл

@@ -67,7 +67,7 @@
},
{
"depends_on": "eval:doc.channel=='Slack'",
"description": "To use Slack Channel, add a <a href=\"\\#Form/Slack Webhook URL\">Slack Webhook URL</a>.",
"description": "To use Slack Channel, add a <a href=\"#List/Slack%20Webhook%20URL/List\">Slack Webhook URL</a>.",
"fieldname": "slack_webhook_url",
"fieldtype": "Link",
"label": "Slack Channel",
@@ -269,6 +269,7 @@
"fieldname": "twilio_number",
"fieldtype": "Link",
"label": "Twilio Number",
"mandatory_depends_on": "eval: doc.channel==='WhatsApp'",
"options": "Twilio Number Group"
},
{
@@ -290,7 +291,7 @@
"icon": "fa fa-envelope",
"index_web_pages_for_search": 1,
"links": [],
"modified": "2020-09-01 18:36:22.550891",
"modified": "2020-09-03 10:33:23.084590",
"modified_by": "Administrator",
"module": "Email",
"name": "Notification",


+ 7
- 1
frappe/email/doctype/notification/notification.py Переглянути файл

@@ -43,6 +43,7 @@ class Notification(Document):
self.validate_forbidden_types()
self.validate_condition()
self.validate_standard()
self.validate_twilio_settings()
frappe.cache().hdel('notifications', self.document_type)

def on_update(self):
@@ -69,6 +70,11 @@ def get_context(context):
if self.is_standard and not frappe.conf.developer_mode:
frappe.throw(_('Cannot edit Standard Notification. To edit, please disable this and duplicate it'))

def validate_twilio_settings(self):
if self.enabled and self.channel == "WhatsApp" \
and not frappe.db.get_single_value("Twilio Settings", "enabled"):
frappe.throw(_("Please enable Twilio settings to send WhatsApp messages"))

def validate_condition(self):
temp_doc = frappe.new_doc(self.document_type)
if self.condition:
@@ -425,4 +431,4 @@ def get_assignees(doc):

recipients = [d.owner for d in assignees]

return recipients
return recipients

+ 13
- 3
frappe/integrations/doctype/twilio_settings/twilio_settings.json Переглянути файл

@@ -5,6 +5,7 @@
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"enabled",
"account_sid",
"auth_token",
"column_break_2",
@@ -14,12 +15,14 @@
{
"fieldname": "account_sid",
"fieldtype": "Data",
"label": "Account SID"
"label": "Account SID",
"mandatory_depends_on": "eval: doc.enabled"
},
{
"fieldname": "auth_token",
"fieldtype": "Password",
"label": "Auth Token"
"label": "Auth Token",
"mandatory_depends_on": "eval: doc.enabled"
},
{
"fieldname": "column_break_2",
@@ -30,11 +33,18 @@
"fieldtype": "Table",
"label": "Twilio Number",
"options": "Twilio Number Group"
},
{
"default": "0",
"fieldname": "enabled",
"fieldtype": "Check",
"label": "Enabled"
}
],
"index_web_pages_for_search": 1,
"issingle": 1,
"links": [],
"modified": "2020-08-11 15:28:57.860554",
"modified": "2020-09-03 10:17:21.318743",
"modified_by": "Administrator",
"module": "Integrations",
"name": "Twilio Settings",


+ 10
- 7
frappe/integrations/doctype/twilio_settings/twilio_settings.py Переглянути файл

@@ -5,14 +5,16 @@
from __future__ import unicode_literals
import frappe
from frappe.model.document import Document
from twilio.rest import Client
from frappe import _
from frappe.utils.password import get_decrypted_password
from twilio.rest import Client
from six import string_types
from json import loads

class TwilioSettings(Document):
def validate(self):
self.validate_twilio_credentials()
def on_update(self):
if self.enabled:
self.validate_twilio_credentials()

def validate_twilio_credentials(self):
try:
@@ -23,14 +25,15 @@ class TwilioSettings(Document):
frappe.throw(_("Invalid Account SID or Auth Token."))

def send_whatsapp_message(sender, receiver_list, message):
import json
twilio_settings = frappe.get_doc("Twilio Settings")
if not twilio_settings.enabled:
frappe.throw(_("Please enable twilio settings before sending WhatsApp messages"))

if isinstance(receiver_list, string_types):
receiver_list = json.loads(receiver_list)
receiver_list = loads(receiver_list)
if not isinstance(receiver_list, list):
receiver_list = [receiver_list]


twilio_settings = frappe.get_doc("Twilio Settings")
auth_token = get_decrypted_password("Twilio Settings", "Twilio Settings", 'auth_token')
client = Client(twilio_settings.account_sid, auth_token)
args = {


Завантаження…
Відмінити
Зберегти