feat: skip sending mail when in developer mode for impersonation

This commit is contained in:
AarDG10 2026-02-09 14:55:39 +05:30
parent b9799a33fb
commit 6ae860f4bb

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)