Skip to content

Commit

Permalink
fix: generate signature key for pdf generation
Browse files Browse the repository at this point in the history
  • Loading branch information
shridarpatil committed Mar 21, 2023
1 parent eccfbf6 commit f10733f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ def validate(self):
if not any(field.fieldname == self.field_name for field in fields): # noqa
frappe.throw(f"Field name {self.field_name} does not exists")

if not frappe.has_permission(self.reference_doctype, ptype='print', user="Guest"):
frappe.throw(f"""
Add read and print permission to guest for <b>{self.reference_doctype}</b>
from Role Permission Manager to generate attachment""")


def execute_method(self) -> dict:
"""Specific to API endpoint Server Scripts."""
safe_exec(
Expand Down Expand Up @@ -103,14 +97,15 @@ def execute_doc(self, doc: Document):
"parameters": parameters
}]

key = frappe.get_doc(doc_data['doctype'], doc_data['name']).get_signature() # noqa
key = frappe.get_doc(doc_data['doctype'], doc_data['name']).get_document_share_key() # noqa
link = get_pdf_link(doc_data['doctype'], doc_data['name'])

data['template']['components'].append({
"type": "header",
"parameters": [{
"type": "document",
"document": {
"link": f'{frappe.utils.get_url()}{get_pdf_link(doc_data["doctype"], doc_data["name"])}', # noqa
"link": f'{frappe.utils.get_url()}{link}&key={key}',
"filename": f'{doc_data["name"]}.pdf'
}
}]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2023-03-21 11:20:04.891815",
"modified": "2023-03-21 13:22:49.965389",
"modified_by": "Administrator",
"module": "Frappe Whatsapp",
"name": "WhatsApp Templates",
Expand All @@ -126,12 +126,6 @@
"role": "System Manager",
"share": 1,
"write": 1
},
{
"print": 1,
"read": 1,
"role": "Guest",
"select": 1
}
],
"sort_field": "modified",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@
class WhatsAppTemplates(Document):
"""Create whatsapp template."""

def validate(self):
if not self.sample and not frappe.has_permission(self.doctype, ptype='print', user="Guest"):
frappe.throw(
f"""Add sample document or add read and print permission to guest user for
<b>{self.doctype}</b> doctype from <b>Role Permission Manager</b>""")

def after_insert(self):
"""Set template code."""
self.template_name = self.template_name.lower().replace(' ', '_')
Expand Down Expand Up @@ -137,7 +131,6 @@ def on_trash(self):
title=res.get("error_user_title", "Error"),
)


def get_header(self):
"""Get header format."""
header = {
Expand All @@ -149,7 +142,9 @@ def get_header(self):

else:
if not self.sample:
self.sample = f'{frappe.utils.get_url()}{get_pdf_link(self.doctype, self.name)}'
key = frappe.get_doc(self.doctype, self.name).get_document_share_key()
link = get_pdf_link(self.doctype, self.name)
self.sample = f'{frappe.utils.get_url()}{link}&key={key}'
header.update({"example": {
"header_handle": [self.sample]
}})
Expand Down

0 comments on commit f10733f

Please sign in to comment.