From c2a67c8d5cac1d6907bd59b37b2202d7149994e7 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Thu, 28 Jan 2021 17:06:49 +0530 Subject: [PATCH] added validation to not create user type if no limit set --- frappe/core/doctype/user_type/user_type.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/frappe/core/doctype/user_type/user_type.py b/frappe/core/doctype/user_type/user_type.py index d214d43277..d6b1154aa6 100644 --- a/frappe/core/doctype/user_type/user_type.py +++ b/frappe/core/doctype/user_type/user_type.py @@ -45,7 +45,15 @@ class UserType(Document): }) def validate_document_type_limit(self): - limit = frappe.conf.get('user_type_doctype_limit').get(frappe.scrub(self.name)) or 10 + limit = frappe.conf.get('user_type_doctype_limit', {}).get(frappe.scrub(self.name)) + + if not limit and frappe.session.user != 'Administrator': + frappe.throw(_('User does not have permission to create the new {0}') + .format(frappe.bold(_('User Type'))), title=_('Permission Error')) + + if not limit: + frappe.throw(_('The limit has not set for the user type {0} in the site config file.') + .format(frappe.bold(self.name)), title=_('Set Limit')) if self.user_doctypes and len(self.user_doctypes) > limit: frappe.throw(_('The total number of user document types limit has been crossed.'),