fix: Docstring of has_permission & made error title translatable

- doctype -> DocType
- fixed other typo
This commit is contained in:
Suraj Shetty 2021-10-28 15:25:45 +05:30
parent 57df0bad82
commit 4e6ea8fdbd
3 changed files with 8 additions and 8 deletions

View file

@ -725,7 +725,7 @@ def has_permission(doctype=None, ptype="read", doc=None, user=None, verbose=Fals
:param ptype: Permission type (`read`, `write`, `create`, `submit`, `cancel`, `amend`). Default: `read`.
:param doc: [optional] Checks User permissions for given doc.
:param user: [optional] Check for given user. Default: current user.
:param parent_doctype: [optional] Useful while checking permission for child doctype. Default: None"""
:param parent_doctype: Required when checking permission for a child DocType (unless doc is specified)."""
if not doctype and doc:
doctype = doc.doctype

View file

@ -575,14 +575,14 @@ def has_child_table_permission(child_doctype, ptype="read", child_doc=None,
if parent_doctype:
if not is_parent_valid(child_doctype, parent_doctype):
frappe.throw(_("{0} is not a valid parent doctype {1}").format(
frappe.throw(_("{0} is not a valid parent DocType for {1}").format(
frappe.bold(parent_doctype),
frappe.bold(child_doctype)
), title="Invalid Parent DocType")
), title=_("Invalid Parent DocType"))
else:
frappe.throw(_("Please specify a valid parent doctype for {0}").format(
frappe.throw(_("Please specify a valid parent DocType for {0}").format(
frappe.bold(child_doctype)
), title="Parent DocType Required")
), title=_("Parent DocType Required"))
return has_permission(parent_doctype, ptype=ptype, doc=parent_doc,
verbose=verbose, user=user, raise_exception=raise_exception)

View file

@ -598,8 +598,8 @@ class TestPermissions(unittest.TestCase):
frappe.set_user("test@example.com")
self.assertIsInstance(frappe.get_list("Has Role", parent_doctype="User", limit=1), list)
self.assertRaisesRegex(frappe.exceptions.ValidationError,
".* is not a valid parent doctype .*", frappe.get_list, doctype="Has Role", parent_doctype="ToDo")
".* is not a valid parent DocType for .*", frappe.get_list, doctype="Has Role", parent_doctype="ToDo")
self.assertRaisesRegex(frappe.exceptions.ValidationError,
"Please specify a valid parent doctype for .*", frappe.get_list, "Has Role")
"Please specify a valid parent DocType for .*", frappe.get_list, "Has Role")
self.assertRaisesRegex(frappe.exceptions.ValidationError,
".* is not a valid parent doctype .*", frappe.get_list, doctype="Has Role", parent_doctype="Has Role")
".* is not a valid parent DocType for .*", frappe.get_list, doctype="Has Role", parent_doctype="Has Role")