From 5165df0af9f625cd41cb86bae7b8ec7af133df2c Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Mon, 21 Dec 2015 13:15:08 +0530 Subject: [PATCH] [fix] pass session to tasks.sendmail to give access to private files --- frappe/core/doctype/communication/communication.py | 2 +- frappe/tasks.py | 7 ++++++- frappe/utils/pdf.py | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/frappe/core/doctype/communication/communication.py b/frappe/core/doctype/communication/communication.py index 2b1ec594d4..a8053e672c 100644 --- a/frappe/core/doctype/communication/communication.py +++ b/frappe/core/doctype/communication/communication.py @@ -109,7 +109,7 @@ class Communication(Document): from frappe.tasks import sendmail sendmail.delay(frappe.local.site, self.name, print_html=print_html, print_format=print_format, attachments=attachments, - recipients=recipients, cc=cc, lang=frappe.local.lang) + recipients=recipients, cc=cc, lang=frappe.local.lang, session=frappe.local.session) def _notify(self, print_html=None, print_format=None, attachments=None, recipients=None, cc=None): diff --git a/frappe/tasks.py b/frappe/tasks.py index abdf7dc4fe..a68d2d2a2a 100644 --- a/frappe/tasks.py +++ b/frappe/tasks.py @@ -189,13 +189,18 @@ def run_async_task(self, site=None, user=None, cmd=None, form_dict=None, hijack_ @celery_task() def sendmail(site, communication_name, print_html=None, print_format=None, attachments=None, - recipients=None, cc=None, lang=None): + recipients=None, cc=None, lang=None, session=None): try: frappe.connect(site=site) if lang: frappe.local.lang = lang + if session: + # hack to enable access to private files in PDF + session['data'] = frappe._dict(session['data']) + frappe.local.session.update(session) + # upto 3 retries for i in xrange(3): try: diff --git a/frappe/utils/pdf.py b/frappe/utils/pdf.py index 417db25c82..6d8b8bf7a8 100644 --- a/frappe/utils/pdf.py +++ b/frappe/utils/pdf.py @@ -39,7 +39,7 @@ def get_pdf(html, options=None): filedata = fileobj.read() except IOError, e: - if "ContentNotFoundError" in e.message: + if "ContentNotFoundError" in e.message or "ContentOperationNotPermittedError" in e.message: # allow pdfs with missing images if file got created if os.path.exists(fname): with open(fname, "rb") as fileobj: