Skip to content

Commit f2450ea

Browse files
khushi8112mergify[bot]
authored andcommitted
fix: add permission validation when prompting company details for incomplete letterhead data
(cherry picked from commit 256a258)
1 parent eb80a37 commit f2450ea

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

erpnext/controllers/accounts_controller.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4357,6 +4357,15 @@ def get_missing_company_details(doctype, docname):
43574357

43584358
address_display_list = get_address_display_list("Company", company)
43594359
address_line = address_display_list[0].get("address_line1") if address_display_list else ""
4360+
needs_new_company_address = not address_line
4361+
4362+
if needs_new_company_address and not frappe.has_permission("Address", "create", throw=False):
4363+
frappe.msgprint(
4364+
_(
4365+
"Company Address is missing. You don't have permission to create an Address. Please contact your System Manager."
4366+
)
4367+
)
4368+
return
43604369

43614370
required_fields.append(company_address)
43624371
required_fields.append(address_line)
@@ -4379,6 +4388,18 @@ def get_missing_company_details(doctype, docname):
43794388
def update_company_master_and_address(current_doctype, name, company, details):
43804389
from frappe.utils import validate_email_address
43814390

4391+
if not frappe.has_permission(current_doctype, "write", doc=name, throw=False):
4392+
frappe.throw(
4393+
_("You don't have permission to update this document. Please contact your System Manager."),
4394+
title=_("Insufficient Permissions"),
4395+
)
4396+
4397+
if not frappe.has_permission("Company", "write", doc=company, throw=False):
4398+
frappe.throw(
4399+
_("You don't have permission to update Company details. Please contact your System Manager."),
4400+
title=_("Insufficient Permissions"),
4401+
)
4402+
43824403
if isinstance(details, str):
43834404
details = frappe.parse_json(details)
43844405

@@ -4393,6 +4414,13 @@ def update_company_master_and_address(current_doctype, name, company, details):
43934414

43944415
company_address = details.get("company_address")
43954416
if details.get("address_line1"):
4417+
if not frappe.has_permission("Address", "create", throw=False):
4418+
frappe.throw(
4419+
_(
4420+
"You don't have permission to create a Company Address. Please contact your System Manager."
4421+
),
4422+
title=_("Insufficient Permissions"),
4423+
)
43964424
address_doc = frappe.get_doc(
43974425
{
43984426
"doctype": "Address",

0 commit comments

Comments
 (0)