From 446f7ec739cc12479eee80e06e983ebf9d8f470d Mon Sep 17 00:00:00 2001 From: prssanna Date: Mon, 7 Oct 2019 13:54:51 +0530 Subject: [PATCH] fix: nable email for notification types --- .../notification_log/notification_log.py | 6 +++- .../notification_settings.json | 29 ++++++++++++++++++- .../notification_settings.py | 7 +++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/frappe/core/doctype/notification_log/notification_log.py b/frappe/core/doctype/notification_log/notification_log.py index eeb466606a..1939076955 100644 --- a/frappe/core/doctype/notification_log/notification_log.py +++ b/frappe/core/doctype/notification_log/notification_log.py @@ -7,7 +7,7 @@ import frappe from frappe import _ from frappe.model.document import Document from frappe.core.doctype.notification_settings.notification_settings import (is_notifications_enabled, - is_email_notifications_enabled) + is_email_notifications_enabled, is_email_notifications_enabled_for_type) class NotificationLog(Document): @@ -48,6 +48,10 @@ def create_notification_log(names, doc, email_content = None): _doc.insert(ignore_permissions=True) def send_notification_email(doc): + is_type_enabled = is_email_notifications_enabled_for_type(doc.user, doc.type) + if not is_type_enabled: + return + from frappe.utils import get_url_to_form, strip_html, get_url doc_link = get_url_to_form(doc.reference_doctype, doc.reference_name) diff --git a/frappe/core/doctype/notification_settings/notification_settings.json b/frappe/core/doctype/notification_settings/notification_settings.json index 9925f8ac51..31e05f4d10 100644 --- a/frappe/core/doctype/notification_settings/notification_settings.json +++ b/frappe/core/doctype/notification_settings/notification_settings.json @@ -9,6 +9,10 @@ "subscribed_documents", "column_break_3", "enable_email_notifications", + "enable_email_mention", + "enable_email_assignment", + "enable_email_energy_point", + "enable_email_doc_share", "user" ], "fields": [ @@ -44,10 +48,33 @@ "fieldname": "column_break_3", "fieldtype": "Section Break", "label": "Email Settings" + }, + { + "default": "0", + "fieldname": "enable_email_mention", + "fieldtype": "Check", + "label": "Mention" + }, + { + "default": "0", + "fieldname": "enable_email_assignment", + "fieldtype": "Check", + "label": "Assignment" + }, + { + "default": "0", + "fieldname": "enable_email_energy_point", + "fieldtype": "Check", + "label": "Energy Point" + }, + { + "fieldname": "enable_email_doc_share", + "fieldtype": "Data", + "label": "Document Share" } ], "in_create": 1, - "modified": "2019-10-07 11:42:39.596589", + "modified": "2019-10-07 12:57:35.130404", "modified_by": "Administrator", "module": "Core", "name": "Notification Settings", diff --git a/frappe/core/doctype/notification_settings/notification_settings.py b/frappe/core/doctype/notification_settings/notification_settings.py index 258117d339..4e7bc172b2 100644 --- a/frappe/core/doctype/notification_settings/notification_settings.py +++ b/frappe/core/doctype/notification_settings/notification_settings.py @@ -29,6 +29,13 @@ def is_email_notifications_enabled(user): else: return True +def is_email_notifications_enabled_for_type(user, notification_type): + type_field = 'enable_email_' + notification_type.lower() + if frappe.db.count('Notification Settings', {'user': user}) > 0: + return frappe.get_value('Notification Settings', {'user': user}, type_field) + else: + return True + @frappe.whitelist() def create_notification_settings():