From a3008e1442b2dc8b73b1cb3dd9086e09993a206d Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Sat, 20 Jun 2020 20:23:25 +0530 Subject: [PATCH 1/2] fix: Do not allow user to delete admin owned fields --- frappe/custom/doctype/custom_field/custom_field.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/frappe/custom/doctype/custom_field/custom_field.py b/frappe/custom/doctype/custom_field/custom_field.py index 20da9ac0cc..23ee8efc98 100644 --- a/frappe/custom/doctype/custom_field/custom_field.py +++ b/frappe/custom/doctype/custom_field/custom_field.py @@ -72,6 +72,12 @@ class CustomField(Document): frappe.db.updatedb(self.dt) def on_trash(self): + #check if Admin owned field + if self.owner == 'Administrator' and frappe.session.user != 'Administrator': + frappe.throw(_('''Custom Field {0} is created by Administrator. + Administrator owned custom fields can only be deleted by Administrator''').format( + frappe.bold(self.label))) + # delete property setter entries frappe.db.sql("""\ DELETE FROM `tabProperty Setter` From fcc77e877e2010e0672599a3e3df9aff8d1392ac Mon Sep 17 00:00:00 2001 From: Chinmay Pai Date: Sun, 21 Jun 2020 12:51:08 +0530 Subject: [PATCH 2/2] chore: update exception string --- frappe/custom/doctype/custom_field/custom_field.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/frappe/custom/doctype/custom_field/custom_field.py b/frappe/custom/doctype/custom_field/custom_field.py index 23ee8efc98..bc325b654e 100644 --- a/frappe/custom/doctype/custom_field/custom_field.py +++ b/frappe/custom/doctype/custom_field/custom_field.py @@ -74,8 +74,7 @@ class CustomField(Document): def on_trash(self): #check if Admin owned field if self.owner == 'Administrator' and frappe.session.user != 'Administrator': - frappe.throw(_('''Custom Field {0} is created by Administrator. - Administrator owned custom fields can only be deleted by Administrator''').format( + frappe.throw(_("Custom Field {0} is created by the Administrator and can only be deleted through the Administrator account.").format( frappe.bold(self.label))) # delete property setter entries