fix: suggested email ids in New Email dialog (#20319)

* chore: enhance UX of New Email dialog

* do not show contacts without an email
* use name as value, y? if several contacts use the same email address, the entry will be displayed several times, but always with the same description, which leads to confusion - using name as value makes the entries distinguishable

* chore: ignore semgrep

Rewriting the query is not in the scope of this PR.

* chore: keep semgrep failing on raw query

[skip ci]

* fix: use email_id as value

* Revert "fix: use email_id as value"

This reverts commit e4c44e2094ddb9b525bc34d400642dcee5656096.

* chore: comment confusing code

---------

Co-authored-by: Raffael Meyer <14891507+barredterra@users.noreply.github.com>
Co-authored-by: Ankush Menat <ankushmenat@gmail.com>
This commit is contained in:
Samuel Danieli 2023-03-28 08:17:56 +02:00 committed by GitHub
parent 69b22f3af2
commit dc4509796d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -11,7 +11,7 @@ def sendmail_to_system_managers(subject, content):
@frappe.whitelist()
def get_contact_list(txt, page_length=20) -> list[dict]:
"""Returns contacts (from autosuggest)"""
"""Return email ids for a multiselect field."""
if cached_contacts := get_cached_contacts(txt):
return cached_contacts[:page_length]
@ -19,11 +19,14 @@ def get_contact_list(txt, page_length=20) -> list[dict]:
reportview_conditions = build_match_conditions("Contact")
match_conditions = f"and {reportview_conditions}" if reportview_conditions else ""
# The multiselect field will store the `label` as the selected value.
# The `value` is just used as a unique key to distinguish between the options.
# https://github.com/frappe/frappe/blob/6c6a89bcdd9454060a1333e23b855d0505c9ebc2/frappe/public/js/frappe/form/controls/autocomplete.js#L29-L35
out = frappe.db.sql(
f"""select email_id as value,
f"""select name as value, email_id as label,
concat(first_name, ifnull(concat(' ',last_name), '' )) as description
from tabContact
where name like %(txt)s or email_id like %(txt)s
where (name like %(txt)s or email_id like %(txt)s) and email_id != ''
{match_conditions}
limit %(page_length)s""",
{"txt": f"%{txt}%", "page_length": page_length},