From d14ea2333147cd29aceb6c6464cdb279f12cb7a5 Mon Sep 17 00:00:00 2001 From: prssanna Date: Tue, 19 Nov 2019 13:26:27 +0530 Subject: [PATCH] fix(patch): create notification settings for all users --- .../notification_settings.json | 2 +- .../notification_settings.py | 4 ++-- frappe/patches.txt | 2 +- .../create_notification_settings_for_user.py | 13 ++++++++++++ .../frappe/ui/notifications/notifications.js | 20 +++++-------------- 5 files changed, 22 insertions(+), 19 deletions(-) create mode 100644 frappe/patches/v12_0/create_notification_settings_for_user.py diff --git a/frappe/desk/doctype/notification_settings/notification_settings.json b/frappe/desk/doctype/notification_settings/notification_settings.json index c8bda705d9..6af325507b 100644 --- a/frappe/desk/doctype/notification_settings/notification_settings.json +++ b/frappe/desk/doctype/notification_settings/notification_settings.json @@ -86,7 +86,7 @@ } ], "in_create": 1, - "modified": "2019-11-14 11:55:09.198036", + "modified": "2019-11-19 12:57:59.356786", "modified_by": "Administrator", "module": "Desk", "name": "Notification Settings", diff --git a/frappe/desk/doctype/notification_settings/notification_settings.py b/frappe/desk/doctype/notification_settings/notification_settings.py index 667e13c1fd..ec969e485c 100644 --- a/frappe/desk/doctype/notification_settings/notification_settings.py +++ b/frappe/desk/doctype/notification_settings/notification_settings.py @@ -32,9 +32,9 @@ def is_email_notifications_enabled_for_type(user, notification_type): return enabled @frappe.whitelist() -def create_notification_settings(): +def create_notification_settings(user): _doc = frappe.new_doc('Notification Settings') - _doc.name = frappe.session.user + _doc.name = user _doc.insert(ignore_permissions=True) frappe.db.commit() diff --git a/frappe/patches.txt b/frappe/patches.txt index d4aaec5bfc..9473323059 100644 --- a/frappe/patches.txt +++ b/frappe/patches.txt @@ -253,7 +253,7 @@ frappe.patches.v12_0.move_email_and_phone_to_child_table frappe.patches.v12_0.delete_duplicate_indexes frappe.patches.v12_0.set_default_incoming_email_port frappe.patches.v12_0.update_global_search -execute:frappe.reload_doc('desk', 'doctype', 'notification_settings') frappe.patches.v12_0.setup_tags frappe.patches.v12_0.update_auto_repeat_status_and_not_submittable frappe.patches.v12_0.copy_to_parent_for_tags +frappe.patches.v12_0.create_notification_settings_for_user diff --git a/frappe/patches/v12_0/create_notification_settings_for_user.py b/frappe/patches/v12_0/create_notification_settings_for_user.py new file mode 100644 index 0000000000..ad12390c4f --- /dev/null +++ b/frappe/patches/v12_0/create_notification_settings_for_user.py @@ -0,0 +1,13 @@ +from __future__ import unicode_literals +import frappe +from frappe.desk.doctype.notification_settings.notification_settings import create_notification_settings + +def execute(): + frappe.reload_doc('desk', 'doctype', 'notification_settings') + + users = frappe.db.get_all('User', fields=['name']) + for user in users: + if frappe.db.exists("Notification Settings", user.name): + continue + + create_notification_settings(user.name) \ No newline at end of file diff --git a/frappe/public/js/frappe/ui/notifications/notifications.js b/frappe/public/js/frappe/ui/notifications/notifications.js index d50aa02391..a77053f9eb 100644 --- a/frappe/public/js/frappe/ui/notifications/notifications.js +++ b/frappe/public/js/frappe/ui/notifications/notifications.js @@ -35,24 +35,14 @@ frappe.ui.Notifications = class Notifications { frappe.search.utils.make_function_searchable( me.route_to_settings, __('Notification Settings'), - [this.notifications_settings], ); this.setup_notifications(); this.bind_events(); } - route_to_settings(settings_doc) { - let method = - 'frappe.desk.doctype.notification_settings.notification_settings.create_notification_settings'; - - return Promise.resolve() - .then(() => { - if (!settings_doc) return frappe.call(method); - }) - .then(() => { - frappe.set_route(`#Form/Notification Settings/${frappe.session.user}`); - }); + route_to_settings() { + frappe.set_route(`#Form/Notification Settings/${frappe.session.user}`); } setup_notifications() { @@ -375,7 +365,7 @@ frappe.ui.Notifications = class Notifications { let category_id = frappe.dom.get_unique_id(); let settings_html = category.value === 'Notifications' - ? ` + ? ` ${__('Settings')} ` : ''; @@ -417,11 +407,11 @@ frappe.ui.Notifications = class Notifications { ); } - make_and_route_to_settings(e) { + go_to_settings(e) { e.stopImmediatePropagation(); this.$dropdown.removeClass('open'); this.$dropdown.trigger('hide.bs.dropdown'); - this.route_to_settings(this.notifications_settings); + this.route_to_settings(); } bind_events() {