feat(core): authorization request for a document - #20
Conversation
| self.token_generated_on = now_datetime() | ||
| self.request_link = "http://localhost:8000/authorize_document?token={0}&name={1}".format(self.token, self.name) | ||
|
|
||
| def email_link(self): |
There was a problem hiding this comment.
Call this send_authorization_request instead?
| def generate_token(self): | ||
| self.token = frappe.generate_hash(self.name, 32) | ||
| self.token_generated_on = now_datetime() | ||
| self.request_link = "http://localhost:8000/authorize_document?token={0}&name={1}".format(self.token, self.name) |
There was a problem hiding this comment.
Use frappe.local.site to get sitename
|
|
||
| def email_link(self): | ||
| """ | ||
| Email the document link to user for them to authorize the document |
There was a problem hiding this comment.
Change to "Email the link to user for them to authorize the document"
| """ | ||
| message = frappe.render_template("templates/emails/authorization_request.html", { | ||
| "authorization_request": self, | ||
| "link": self.request_link |
There was a problem hiding this comment.
The authorization request will have the link anyway. No need to pass the link separately.
| }) | ||
|
|
||
| frappe.sendmail(recipients=[self.authorizer_email], subject="You have a document to authorize", message=message) | ||
| frappe.msgprint("Document has been successfully sent to Email") |
There was a problem hiding this comment.
Change this to "Request Link has been successfully sent to Email"
| if (!frm.doc.customer_signature) { | ||
| frm.add_custom_button(__("Authorize"), () => { | ||
| frappe.new_doc("Authorization Request", { | ||
| linked_doctype: frm.doc.doctype, |
There was a problem hiding this comment.
Add email and name as well?
|
|
||
| @frappe.whitelist() | ||
| def make_authorization_request(source_name, target_doc=None): | ||
| print(locals()) |
| docname = frappe.local.request.args.get("name") | ||
|
|
||
| auth_req = frappe.get_doc("Authorization Request", docname) | ||
| if not token or token == auth_req.token: |
There was a problem hiding this comment.
This should be if not token or token != auth_req.token
| authorization_request.save() | ||
|
|
||
| authorized_doc = frappe.get_doc(authorization_request.linked_doctype, authorization_request.linked_docname) | ||
| try: |
There was a problem hiding this comment.
You always want to except for a particular exception. I don't see the point of this try catch if you're going to do a .submit() anyway?
I think you should spend some time understanding how exception handling works
| frappe.ui.form.on("Authorization Request", { | ||
|
|
||
| }); | ||
| // frm.set_df_property("patient", "hidden", 0); |
There was a problem hiding this comment.
Remove this commented out code
| def generate_token(self): | ||
| self.token = frappe.generate_hash(self.name, 32) | ||
| self.token_generated_on = now_datetime() | ||
| self.request_link = "http://{0}/authorize_document?token={1}&name={2}".format(frappe.local.site, self.token, self.name) |
There was a problem hiding this comment.
| self.request_link = "http://{0}/authorize_document?token={1}&name={2}".format(frappe.local.site, self.token, self.name) | |
| from frappe.utils.data import get_url | |
| self.request_link = "{0}/authorize_document?token={1}&name={2}".format(get_url(), self.token, self.name) |
| @@ -0,0 +1 @@ | |||
| <p>Hi, a document has been generated for you to authorize, please go here {{ link }}</p> No newline at end of file | |||
There was a problem hiding this comment.
Ashwin shared an HTML file on the Task for this feature. Replace this HTML with that - maybe get @Er-Naren719 to help you with the template.
| $("#step2").on("click", function () { | ||
| var sign = $sigdiv.jSignature("getData"); | ||
| var signee = document.getElementById("signee").value; | ||
| if (!($sigdiv.jSignature('getData', 'native').length == 0) && signee) { |
There was a problem hiding this comment.
Maybe add some comments on what you're doing here exactly. Especially since you're using a separate library. Also fix formatting for this file ("Format Document" in VSCode).
|
|
||
| @frappe.whitelist(allow_guest=True) | ||
| def authorize_document(sign=None, signee=None, docname=None): | ||
| authorization_request = frappe.get_doc("Authorization Request", docname) |
There was a problem hiding this comment.
get_doc will fail if the document doesn't exist. Just as a sanity check, do:
| authorization_request = frappe.get_doc("Authorization Request", docname) | |
| if frappe.db.exists("Authorization Request", docname): | |
| authorization_request = frappe.get_doc("Authorization Request", docname) |
|
|
||
| authorized_doc = frappe.get_doc(authorization_request.linked_doctype, authorization_request.linked_docname) | ||
| if hasattr(authorized_doc, "is_signed"): | ||
| authorized_doc.is_signed = 1 |
There was a problem hiding this comment.
Only set this if the document is not already signed.
|
@Alchez Is this approved? |
|
@DeeMysterio, can you update the screenshots with the new web view and other changes? |
| frappe.local.flags.ignore_print_permissions = True | ||
| context.print_doc = frappe.get_print(auth_req.linked_doctype, auth_req.linked_docname) | ||
| print_doc = frappe.get_print(auth_req.linked_doctype, auth_req.linked_docname) | ||
| context.print_doc = print_doc[print_doc.find('<body>')+len('<body>'):len(print_doc)-len('</body>')] |
There was a problem hiding this comment.
Wow, there has to be a better way to do this 🤣
|
🎉 This PR is included in version 1.3.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Purpose-
You may want to get a draft document authorised by the customer first and then go ahead with further processing.
Updates :