-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: AssignmentRule.apply #26371
Changes from all commits
f4df116
97a6b12
be54e6f
d3294fa
1adcc7d
63099bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -88,24 +88,33 @@ def enqueue_create_notification(users: list[str] | str, doc: dict): | |||||
users = [user.strip() for user in users.split(",") if user.strip()] | ||||||
users = list(set(users)) | ||||||
|
||||||
frappe.enqueue( | ||||||
"frappe.desk.doctype.notification_log.notification_log.make_notification_logs", | ||||||
doc=doc, | ||||||
users=users, | ||||||
now=frappe.flags.in_test, | ||||||
) | ||||||
if frappe.flags.in_test: | ||||||
make_notification_log(doc, users) | ||||||
else: | ||||||
frappe.local.system_notifications_queue.append((doc, users)) | ||||||
if flush_system_notifications not in frappe.db.after_commit._functions: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Can do this instead of relying on internal attribute. Line will have to move up before There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This pattern is very common though, maybe we should have |
||||||
frappe.db.after_commit(flush_system_notifications) | ||||||
|
||||||
|
||||||
def flush_system_notifications(): | ||||||
if frappe.local.system_notifications_queue: | ||||||
frappe.enqueue( | ||||||
"frappe.desk.doctype.notification_log.notification_log.make_notification_logs", | ||||||
notifications=frappe.local.system_notifications_queue, | ||||||
) | ||||||
frappe.local.system_notifications_queue.clear() | ||||||
|
||||||
|
||||||
def make_notification_logs(notifications: list[tuple[str, list[str]]]): | ||||||
for doc, users in notifications: | ||||||
make_notification_log(doc, users) | ||||||
|
||||||
|
||||||
def make_notification_logs(doc, users): | ||||||
def make_notification_log(doc: dict, users: list[str]): | ||||||
for user in _get_user_ids(users): | ||||||
notification = frappe.new_doc("Notification Log") | ||||||
notification.update(doc) | ||||||
notification.for_user = user | ||||||
if ( | ||||||
notification.for_user != notification.from_user | ||||||
or doc.type == "Energy Point" | ||||||
or doc.type == "Alert" | ||||||
): | ||||||
if user != doc.from_user or doc.type == "Energy Point" or doc.type == "Alert": | ||||||
notification = frappe.new_doc("Notification Log").update(doc) | ||||||
notification.for_user = user | ||||||
notification.insert(ignore_permissions=True) | ||||||
|
||||||
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't this just be part of enqueue to flush after commit?
It implements same exact behavior: