Merge pull request #37420 from diptanilsaha/nr_delete

fix: delete standard notification and report files after `commit`
This commit is contained in:
Sagar Vora 2026-02-23 21:53:01 +05:30 committed by GitHub
commit 39b0cea12f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 25 additions and 23 deletions

View file

@ -93,20 +93,23 @@ class Report(Document):
doc.prepared_report = 0
def on_trash(self):
if (
self.is_standard == "Yes"
and not cint(getattr(frappe.local.conf, "developer_mode", 0))
and not frappe.flags.in_migrate
and not frappe.flags.in_patch
):
frappe.throw(_("You are not allowed to delete Standard Report"))
if self.is_standard == "Yes":
if (
not cint(getattr(frappe.local.conf, "developer_mode", 0))
and not frappe.flags.in_migrate
and not frappe.flags.in_patch
):
frappe.throw(_("You are not allowed to delete Standard Report"))
if frappe.conf.developer_mode and not frappe.flags.in_test:
frappe.db.after_commit(self.delete_report_folder)
delete_custom_role("report", self.name)
def after_delete(self):
def delete_report_folder(self):
from frappe.modules.export_file import delete_folder
if not frappe.flags.in_test and frappe.conf.developer_mode:
delete_folder(self.module, "Report", self.name)
delete_folder(self.module, "Report", self.name)
def get_permission_log_options(self, event=None):
return {"fields": ["roles"]}

View file

@ -721,23 +721,22 @@ def get_context(context):
self.message = self.get_template(md_as_html=True)
def on_trash(self):
# Prevent deletion of standard notifications outside developer mode to avoid restoration during migration
if (
self.is_standard
and not frappe.conf.developer_mode
and not frappe.flags.in_migrate
and not frappe.flags.in_patch
):
frappe.throw(
_("You are not allowed to delete a standard Notification. You can disable it instead.")
)
if self.is_standard:
# Prevent deletion of standard notifications outside developer mode to avoid restoration during migration
if not frappe.conf.developer_mode and not frappe.flags.in_migrate and not frappe.flags.in_patch:
frappe.throw(
_("You are not allowed to delete a standard Notification. You can disable it instead.")
)
if frappe.conf.developer_mode and not frappe.flags.in_test:
frappe.db.after_commit(self.delete_notification_folder)
clear_notification_cache()
def after_delete(self):
def delete_notification_folder(self):
from frappe.modules.export_file import delete_folder
if not frappe.flags.in_test and frappe.conf.developer_mode:
delete_folder(self.module, "Notification", self.name)
delete_folder(self.module, "Notification", self.name)
def clear_notification_cache():