feat: enables, disables and deletes notification settings when a user is modified [CU-j8wutt] (#9)
This commit is contained in:
parent
71dd300ae3
commit
9e5ca78d78
3 changed files with 17 additions and 2 deletions
|
|
@ -8,7 +8,7 @@ from frappe.utils import cint, flt, has_gravatar, escape_html, format_datetime,
|
|||
from frappe import throw, msgprint, _
|
||||
from frappe.utils.password import update_password as _update_password, check_password
|
||||
from frappe.desk.notifications import clear_notifications
|
||||
from frappe.desk.doctype.notification_settings.notification_settings import create_notification_settings
|
||||
from frappe.desk.doctype.notification_settings.notification_settings import create_notification_settings, enable_disable_notifications
|
||||
from frappe.utils.user import get_system_managers
|
||||
from bs4 import BeautifulSoup
|
||||
import frappe.permissions
|
||||
|
|
@ -141,11 +141,17 @@ class User(Document):
|
|||
|
||||
if not cint(self.enabled):
|
||||
self.a_system_manager_should_exist()
|
||||
# disable notifications if the user has been disabled
|
||||
enable_disable_notifications(self.name, enabled=False)
|
||||
|
||||
# clear sessions if disabled
|
||||
if not cint(self.enabled) and getattr(frappe.local, "login_manager", None):
|
||||
frappe.local.login_manager.logout(user=self.name)
|
||||
|
||||
# enable notifications if the user has been enabled
|
||||
if cint(self.enabled):
|
||||
enable_disable_notifications(self.name, enabled=True)
|
||||
|
||||
def add_system_manager_role(self):
|
||||
# if adding system manager, do nothing
|
||||
if not cint(self.enabled) or ("System Manager" in [user_role.role for user_role in
|
||||
|
|
@ -358,6 +364,9 @@ class User(Document):
|
|||
set `user`=null
|
||||
where `user`=%s""", (self.name))
|
||||
|
||||
# delete notification settings
|
||||
frappe.delete_doc("Notification Settings", self.name, ignore_permissions=True)
|
||||
|
||||
|
||||
def before_rename(self, old_name, new_name, merge=False):
|
||||
self.check_demo()
|
||||
|
|
|
|||
|
|
@ -43,6 +43,9 @@ def create_notification_settings(user):
|
|||
_doc.name = user
|
||||
_doc.insert(ignore_permissions=True)
|
||||
|
||||
def enable_disable_notifications(user, enabled):
|
||||
frappe.set_value("Notification Settings", user, 'enabled', enabled)
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_subscribed_documents():
|
||||
|
|
|
|||
|
|
@ -319,7 +319,10 @@ def send_summary(timespan):
|
|||
|
||||
from_date = getdate(from_date)
|
||||
to_date = getdate()
|
||||
all_users = [user.email for user in get_enabled_system_users()]
|
||||
|
||||
# select only those users that have energy point email notifications enabled
|
||||
all_users = [user.email for user in get_enabled_system_users() if
|
||||
is_email_notifications_enabled_for_type(user.name, 'Energy Point')]
|
||||
|
||||
frappe.sendmail(
|
||||
subject = '{} energy points summary'.format(timespan),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue