fix(nestedset): clear user permissions cache when a new doc is created, if applicable

Signed-off-by: Akhil Narang <me@akhilnarang.dev>
This commit is contained in:
Akhil Narang 2025-08-11 18:02:57 +05:30
parent d5fcdff679
commit c0c0cae78a
No known key found for this signature in database
GPG key ID: 9DCC61E211BF645F

View file

@ -261,6 +261,19 @@ class NestedSet(Document):
if self.meta.get("nsm_parent_field"):
self.nsm_parent_field = self.meta.nsm_parent_field
def after_insert(self):
if (
frappe.flags.in_import
or frappe.flags.in_patch
or frappe.flags.in_migrate
or frappe.flags.in_install
):
return
# Clear user permissions cache, otherwise user can't access the new document
if frappe.db.exists("User Permission", {"user": frappe.session.user, "allow": self.doctype}):
frappe.cache.hdel("user_permissions", frappe.session.user)
def on_update(self):
update_nsm(self)
self.validate_ledger()