diff --git a/frappe/core/doctype/doctype/doctype.py b/frappe/core/doctype/doctype/doctype.py index 1b9f6b50f8..58ec4f8afa 100644 --- a/frappe/core/doctype/doctype/doctype.py +++ b/frappe/core/doctype/doctype/doctype.py @@ -1841,34 +1841,84 @@ def validate_permissions(doctype, for_remove=False, alert=False): def check_permission_dependency(d): if d.cancel and not d.submit: - frappe.throw(_("{0}: Cannot set Cancel without Submit").format(get_txt(d))) + frappe.throw( + _("{0}: The 'Cancel' permission cannot be granted without the 'Submit' permission.").format( + get_txt(d) + ) + ) if (d.submit or d.cancel or d.amend) and not d.write: - frappe.throw(_("{0}: Cannot set Submit, Cancel, Amend without Write").format(get_txt(d))) - if d.amend and not d.write: - frappe.throw(_("{0}: Cannot set Amend without Cancel").format(get_txt(d))) + frappe.throw( + _( + "{0}: The 'Submit', 'Cancel', and 'Amend' permissions cannot be granted without the 'Write' permission." + ).format(get_txt(d)) + ) + if d.amend and not d.create: + frappe.throw( + _("{0}: The 'Amend' permission cannot be granted without the 'Create' permission.").format( + get_txt(d) + ) + ) if d.get("import") and not d.create: - frappe.throw(_("{0}: Cannot set Import without Create").format(get_txt(d))) + frappe.throw( + _("{0}: The 'Import' permission cannot be granted without the 'Create' permission.").format( + get_txt(d) + ) + ) def remove_rights_for_single(d): if not issingle: return - if d.report: - frappe.msgprint(_("Report cannot be set for Single types")) - d.report = 0 + if d.get("report"): + d.set("report", 0) + frappe.msgprint( + _( + "{0}: The 'Report' permission was removed because it cannot be granted for a 'single' DocType." + ).format(get_txt(d)) + ) + + if d.get("import"): d.set("import", 0) + frappe.msgprint( + _( + "{0}: The 'Import' permission was removed because it cannot be granted for a 'single' DocType." + ).format(get_txt(d)) + ) + + if d.get("export"): d.set("export", 0) + frappe.msgprint( + _( + "{0}: The 'Export' permission was removed because it cannot be granted for a 'single' DocType." + ).format(get_txt(d)) + ) def check_if_submittable(d): - if d.submit and not issubmittable: - frappe.throw(_("{0}: Cannot set Assign Submit if not Submittable").format(get_txt(d))) - elif d.amend and not issubmittable: - frappe.throw(_("{0}: Cannot set Assign Amend if not Submittable").format(get_txt(d))) + if issubmittable: + return + + if d.submit: + frappe.throw( + _("{0}: The 'Submit' permission cannot be granted for a non-submittable DocType.").format( + get_txt(d) + ) + ) + + if d.amend: + frappe.throw( + _("{0}: The 'Amend' permission cannot be granted for a non-submittable DocType.").format( + get_txt(d) + ) + ) def check_if_importable(d): if d.get("import") and not isimportable: - frappe.throw(_("{0}: Cannot set import as {1} is not importable").format(get_txt(d), doctype)) + frappe.throw( + _("{0}: The 'Import' permission cannot be granted for a non-importable DocType.").format( + get_txt(d) + ) + ) def validate_permission_for_all_role(d): if frappe.session.user == "Administrator": @@ -1878,7 +1928,7 @@ def validate_permissions(doctype, for_remove=False, alert=False): if d.role in AUTOMATIC_ROLES: frappe.throw( _( - "Row # {0}: Non administrator user can not set the role {1} to the custom doctype" + "Row # {0}: Non-administrator users cannot add the role {1} to a custom DocType." ).format(d.idx, frappe.bold(_(d.role))), title=_("Permissions Error"), ) @@ -1888,7 +1938,7 @@ def validate_permissions(doctype, for_remove=False, alert=False): if d.role in roles: frappe.throw( _( - "Row # {0}: Non administrator user can not set the role {1} to the custom doctype" + "Row # {0}: Non-administrator users cannot add the role {1} to a custom DocType." ).format(d.idx, frappe.bold(_(d.role))), title=_("Permissions Error"), )