From d254ca2f505833c6d74a5302c283b574f4d8ae9d Mon Sep 17 00:00:00 2001 From: MitulDavid Date: Wed, 6 Oct 2021 17:37:20 +0530 Subject: [PATCH 1/2] fix: Make images in comments private --- frappe/core/doctype/file/file.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frappe/core/doctype/file/file.py b/frappe/core/doctype/file/file.py index d9ecd85533..569c6ab23b 100755 --- a/frappe/core/doctype/file/file.py +++ b/frappe/core/doctype/file/file.py @@ -839,6 +839,7 @@ def extract_images_from_html(doc, content): doctype = doc.parenttype if doc.parent else doc.doctype name = doc.parent or doc.name + is_private = True if doctype == "Comment" else False _file = frappe.get_doc({ "doctype": "File", @@ -846,7 +847,8 @@ def extract_images_from_html(doc, content): "attached_to_doctype": doctype, "attached_to_name": name, "content": content, - "decode": False + "decode": False, + "is_private": is_private }) _file.save(ignore_permissions=True) file_url = _file.file_url From 05cb2c16cd037a9b6110a45295a46bfe2c07295b Mon Sep 17 00:00:00 2001 From: MitulDavid Date: Thu, 7 Oct 2021 16:41:44 +0530 Subject: [PATCH 2/2] fix: Optional parameter for setting extracted image as private --- frappe/core/doctype/file/file.py | 3 +-- frappe/desk/form/utils.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/frappe/core/doctype/file/file.py b/frappe/core/doctype/file/file.py index 569c6ab23b..4df9ef3132 100755 --- a/frappe/core/doctype/file/file.py +++ b/frappe/core/doctype/file/file.py @@ -813,7 +813,7 @@ def extract_images_from_doc(doc, fieldname): doc.set(fieldname, content) -def extract_images_from_html(doc, content): +def extract_images_from_html(doc, content, is_private=False): frappe.flags.has_dataurl = False def _save_file(match): @@ -839,7 +839,6 @@ def extract_images_from_html(doc, content): doctype = doc.parenttype if doc.parent else doc.doctype name = doc.parent or doc.name - is_private = True if doctype == "Comment" else False _file = frappe.get_doc({ "doctype": "File", diff --git a/frappe/desk/form/utils.py b/frappe/desk/form/utils.py index a4dcee4ab3..bd04e1915c 100644 --- a/frappe/desk/form/utils.py +++ b/frappe/desk/form/utils.py @@ -66,7 +66,7 @@ def add_comment(reference_doctype, reference_name, content, comment_email, comme comment_type='Comment', comment_by=comment_by )) - doc.content = extract_images_from_html(doc, content) + doc.content = extract_images_from_html(doc, content, is_private=True) doc.insert(ignore_permissions=True) follow_document(doc.reference_doctype, doc.reference_name, frappe.session.user)