[fix] pass session to tasks.sendmail to give access to private files
This commit is contained in:
parent
820b688c44
commit
5165df0af9
3 changed files with 8 additions and 3 deletions
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue