Skip to content
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

fix: Use doctype setting to set auto-extracted file as private #24828

Merged
merged 7 commits into from Mar 15, 2024
8 changes: 5 additions & 3 deletions frappe/core/doctype/file/test_file.py
Expand Up @@ -717,16 +717,18 @@ def tearDown(self) -> None:

class TestFileUtils(FrappeTestCase):
def test_extract_images_from_doc(self):
is_private = not frappe.db.get_value("DocType", "ToDo", "make_attachments_public")
ankush marked this conversation as resolved.
Show resolved Hide resolved

# with filename in data URI
todo = frappe.get_doc(
{
"doctype": "ToDo",
"description": 'Test <img src="data:image/png;filename=pix.png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=">',
}
).insert()
self.assertTrue(frappe.db.exists("File", {"attached_to_name": todo.name}))
self.assertIn('<img src="/files/pix.png">', todo.description)
self.assertListEqual(get_attached_images("ToDo", [todo.name])[todo.name], ["/files/pix.png"])
self.assertTrue(frappe.db.exists("File", {"attached_to_name": todo.name, "is_private": is_private}))
self.assertIn('<img src="/private/files/pix.png">', todo.description)
self.assertListEqual(get_attached_images("ToDo", [todo.name])[todo.name], ["/private/files/pix.png"])

# without filename in data URI
todo = frappe.get_doc(
Expand Down
2 changes: 1 addition & 1 deletion frappe/core/doctype/file/utils.py
Expand Up @@ -216,7 +216,7 @@ def get_file_name(fname: str, optional_suffix: str | None = None) -> str:

def extract_images_from_doc(doc: "Document", fieldname: str):
content = doc.get(fieldname)
content = extract_images_from_html(doc, content)
content = extract_images_from_html(doc, content, is_private=(not doc.meta.make_attachments_public))
if frappe.flags.has_dataurl:
doc.set(fieldname, content)

Expand Down