Merge pull request #36882 from AarDG10/disable-mail-for-impersonation

feat: skip sending mail when in developer mode for impersonation
This commit is contained in:
Aarol D'Souza 2026-02-09 15:06:51 +05:30 committed by GitHub
commit 92f70cd578
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1463,16 +1463,17 @@ def impersonate(user: str, reason: str):
notification.set("type", "Alert")
notification.insert(ignore_permissions=True)
# notify user via email too
user_email = frappe.db.get_value("User", user, "email")
email_message = _(
"User {0} has started an impersonation session as you. <br><br><b>Reason provided:</b> {1}"
).format(escape_html(impersonator), escape_html(reason))
if not frappe.conf.get("developer_mode"): # bypass for testing locally
user_email = frappe.db.get_value("User", user, "email")
email_message = _(
"User {0} has started an impersonation session as you. <br><br><b>Reason provided:</b> {1}"
).format(escape_html(impersonator), escape_html(reason))
frappe.sendmail(
recipients=[user_email],
subject=_("Security Alert: Your account is being impersonated"),
content=email_message,
)
frappe.sendmail(
recipients=[user_email],
subject=_("Security Alert: Your account is being impersonated"),
content=email_message,
)
frappe.local.login_manager.impersonate(user)