From 1df1bc5232e9dd7f459deb5e6febaefb84920af4 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Mon, 30 May 2022 17:15:44 +0530 Subject: [PATCH 1/2] fix: Don't update modified time on set_notifications_as_unseen --- frappe/desk/doctype/notification_log/notification_log.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frappe/desk/doctype/notification_log/notification_log.py b/frappe/desk/doctype/notification_log/notification_log.py index c4a082ff11..def626513c 100644 --- a/frappe/desk/doctype/notification_log/notification_log.py +++ b/frappe/desk/doctype/notification_log/notification_log.py @@ -148,6 +148,6 @@ def trigger_indicator_hide(): def set_notifications_as_unseen(user): try: - frappe.db.set_value("Notification Settings", user, "seen", 0) + frappe.db.set_value("Notification Settings", user, "seen", 0, update_modified=False) except frappe.DoesNotExistError: return From 3c7dd75047ac190c1a00b2953c40cb9fd98ddf2b Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Mon, 30 May 2022 17:28:12 +0530 Subject: [PATCH 2/2] fix: Update Notification Settings via doc.save toggle_notifications is called via User doc. Changes made through another doc should leave some trace. Using doc.save in order to maintain versions. --- .../notification_settings/notification_settings.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/frappe/desk/doctype/notification_settings/notification_settings.py b/frappe/desk/doctype/notification_settings/notification_settings.py index ee425e154b..1436ecc1cd 100644 --- a/frappe/desk/doctype/notification_settings/notification_settings.py +++ b/frappe/desk/doctype/notification_settings/notification_settings.py @@ -48,9 +48,15 @@ def create_notification_settings(user): _doc.insert(ignore_permissions=True) -def toggle_notifications(user, enable=False): - if frappe.db.exists("Notification Settings", user): - frappe.db.set_value("Notification Settings", user, "enabled", enable) +def toggle_notifications(user: str, enable: bool = False): + try: + settings = frappe.get_doc("Notification Settings", user) + except frappe.DoesNotExistError: + return + + if settings.enabled != enable: + settings.enabled = enable + settings.save() @frappe.whitelist()