-
Notifications
You must be signed in to change notification settings - Fork 34
feat(core): authorization request for a document #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add email and name as well?
bloomstack_core/utils.py
Outdated
|
|
||
| @frappe.whitelist() | ||
| def make_authorization_request(source_name, target_doc=None): | ||
| print(locals()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Errr 😅
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be if not token or token != auth_req.token
bloomstack_core/utils.py
Outdated
| authorization_request.save() | ||
|
|
||
| authorized_doc = frappe.get_doc(authorization_request.linked_doctype, authorization_request.linked_docname) | ||
| try: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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).
bloomstack_core/utils.py
Outdated
|
|
||
| @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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
bloomstack_core/utils.py
Outdated
|
|
||
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 :