fix(crm): match contact form sender to the signed-in user case-insensitively

This commit is contained in:
Nabin Hait
2026-10-22 12:25:37 +05:30
parent b895baa0c8
commit 78539a96ba
2 changed files with 28 additions and 1 deletions
+27
View File
@@ -39,3 +39,30 @@ class TestTemplateUtils(FrappeTestCase):
with self.set_user("Guest"):
send_message("_test_contact_us_disabled@example.com", "Hello", "Disabled")
self.assertFalse(frappe.db.exists("Lead", {"email_id": "_test_contact_us_disabled@example.com"}))
def test_contact_us_signed_in_sender_is_filed_against_own_customer(self):
from erpnext.tests.permission_test_utils import as_user, make_fenced_user
frappe.db.set_single_value("CRM Settings", "enable_opportunity_creation_from_contact_us", 1)
self.addCleanup(frappe.db.set_default, "company", frappe.db.get_default("company"))
frappe.db.set_default("company", "_Test Company")
user = make_fenced_user("_test_contact_us_signed_in@example.com", ["Customer"])
other = "_test_contact_us_colleague@example.com"
for email in (user, other):
frappe.get_doc(
{
"doctype": "Contact",
"first_name": email,
"email_ids": [{"email_id": email, "is_primary": 1}],
"links": [{"link_doctype": "Customer", "link_name": "_Test Customer"}],
}
).insert(ignore_permissions=True)
with as_user(user):
send_message(user.upper(), "Renewal request", "Own renewal")
send_message(other, "Renewal request", "Colleague renewal")
own = frappe.db.get_value("Opportunity", {"title": "Own renewal"}, ["opportunity_from", "party_name"])
colleague = frappe.db.get_value("Opportunity", {"title": "Colleague renewal"}, "opportunity_from")
self.assertEqual(own, ("Customer", "_Test Customer"))
self.assertEqual(colleague, "Lead")
+1 -1
View File
@@ -30,7 +30,7 @@ def send_message(sender: str, message: str, subject: str = "Website Query"):
lead = customer = None
# a guest's address is unverified, so only a signed-in sender is matched to a customer
if frappe.session.user == sender:
if frappe.session.user.lower() == sender.lower():
customer = frappe.db.sql(
"""select distinct dl.link_name from `tabDynamic Link` dl
left join `tabContact` c on dl.parent=c.name where dl.link_doctype='Customer'