* fix(contact): force type check in contact whitelisted methods * fix(google_indexing): force type check in google_indexing whitelisted methods * fix(assignment_rule): add type checks to assignment_rule whitelisted methods * refactor: remove unused args * fix(queue): add type hints to whitelisted methods in queue.py * fix(auto_email_report): add type hints to whitelisted methods * fix(dashboard): add type hints to whitelisted methods * fix(sidebar_item_group): add type hints to whitelisted methods * fix(weasyprint): add type hints to whitelisted methods * fix(backups): add type hints to whitelisted methods * fix(document_naming_settings): add type hints to whitelisted methods * fix(get_latest_submissions): add type hints to whitelisted methods * fix(custom_field): add type hints to whitelisted methods * fix(customize_form): add type hints to whitelisted methods * fix(personal_data_deletion_request): add type hints to whitelisted functions * fix(__init__): add type hints to whitelisted methods * fix(prepared_report): add type hints to whitelisted methods * fix(session_default_settings): add type hints to whitelisted methods * fix(document_follow): add type hints to whitelisted methods * fix(route_history): add type hints to whitelisted methods * fix(form_tour): add type hints to whitelisted methods * fix(dashboard_settings): add type hints to whitelisted methods * fix(address): add type hints to whitelisted methods * fix(contact): add type hints to whitelisted methods * fix(discussion_reply): add type hints to whitelisted methods * fix(auto_repeat): add type hints to whitelisted methods * fix: add the missing type hints and misc. corrections * fix(email): add type hints to whitelisted methods * fix(permitted_documents_for_users): add type hints to whitelisted methods * fix: correct the type hints * fix: int PK types --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Ankush Menat <ankushmenat@gmail.com> Co-authored-by: Ankush Menat <ankush@frappe.io>
72 lines
2 KiB
Python
72 lines
2 KiB
Python
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
|
# License: MIT. See LICENSE
|
|
|
|
from contextlib import suppress
|
|
|
|
import frappe
|
|
from frappe import _
|
|
from frappe.rate_limiter import rate_limit
|
|
from frappe.utils import escape_html, validate_email_address
|
|
|
|
sitemap = 1
|
|
|
|
|
|
def get_context(context):
|
|
doc = frappe.get_doc("Contact Us Settings", "Contact Us Settings")
|
|
if doc.is_disabled:
|
|
frappe.local.flags.redirect_location = "/404"
|
|
raise frappe.Redirect
|
|
|
|
if doc.query_options:
|
|
query_options = [opt.strip() for opt in doc.query_options.replace(",", "\n").split("\n") if opt]
|
|
else:
|
|
query_options = ["Sales", "Support", "General"]
|
|
|
|
out = {"query_options": query_options, "parents": [{"name": _("Home"), "route": "/"}]}
|
|
out.update(doc.as_dict())
|
|
|
|
return out
|
|
|
|
|
|
@frappe.whitelist(allow_guest=True)
|
|
@rate_limit(limit=1000, seconds=60 * 60)
|
|
def send_message(sender: str, message: str, subject: str = "Website Query"):
|
|
doc = frappe.get_doc("Contact Us Settings", "Contact Us Settings")
|
|
if doc.is_disabled:
|
|
return
|
|
|
|
sender = validate_email_address(sender, throw=True)
|
|
|
|
message = escape_html(message)
|
|
|
|
with suppress(frappe.OutgoingEmailError):
|
|
if forward_to_email := frappe.db.get_single_value("Contact Us Settings", "forward_to_email"):
|
|
frappe.sendmail(recipients=forward_to_email, reply_to=sender, content=message, subject=subject)
|
|
|
|
reply = _(
|
|
"""Thank you for reaching out to us. We will get back to you at the earliest.
|
|
|
|
|
|
Your query:
|
|
|
|
{0}"""
|
|
).format(message)
|
|
frappe.sendmail(
|
|
recipients=sender,
|
|
content=f"<div style='white-space: pre-wrap'>{reply}</div>",
|
|
subject=_("We've received your query!"),
|
|
)
|
|
|
|
# for clearing outgoing email error message
|
|
frappe.clear_last_message()
|
|
|
|
system_language = frappe.db.get_single_value("System Settings", "language")
|
|
# add to to-do ?
|
|
frappe.get_doc(
|
|
doctype="Communication",
|
|
sender=sender,
|
|
subject=_("New Message from Website Contact Page", system_language),
|
|
sent_or_received="Received",
|
|
content=message,
|
|
status="Open",
|
|
).insert(ignore_permissions=True)
|