Merge pull request #1469 from anandpdoshi/fix/private-files-in-email

[fix] pass session to tasks.sendmail to give access to private files
This commit is contained in:
Anand Doshi 2015-12-21 16:01:04 +05:30
commit fd55a108cb
3 changed files with 8 additions and 3 deletions

View file

@ -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):

View file

@ -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:

View file

@ -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: