Skip to content

Commit

Permalink
test: Comment + Comm.n file extraction & Attachments default to publi…
Browse files Browse the repository at this point in the history
…c for Communication

- Note: DocType Communication's records are used for emails that have the file link embedded in its content
- fix: The files extracted from a Communication must be public so that they are visible in an email (link in email)
- Test: Check if file is created appropriately from a Comment and a Communication
  • Loading branch information
marination committed Feb 9, 2024
1 parent ed6613c commit 7a17677
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
3 changes: 2 additions & 1 deletion frappe/core/doctype/communication/communication.json
Expand Up @@ -401,7 +401,8 @@
"icon": "fa fa-comment",
"idx": 1,
"links": [],
"modified": "2023-11-27 20:38:27.467076",
"make_attachments_public": 1,
"modified": "2024-02-09 12:10:01.200845",
"modified_by": "Administrator",
"module": "Core",
"name": "Communication",
Expand Down
46 changes: 45 additions & 1 deletion frappe/core/doctype/file/test_file.py
Expand Up @@ -18,7 +18,8 @@
unzip_file,
)
from frappe.core.doctype.file.exceptions import FileTypeNotAllowed
from frappe.core.doctype.file.utils import delete_file, get_extension
from frappe.core.doctype.file.utils import get_extension
from frappe.desk.form.utils import add_comment
from frappe.exceptions import ValidationError
from frappe.tests.utils import FrappeTestCase, change_settings
from frappe.utils import get_files_path, set_request
Expand Down Expand Up @@ -740,6 +741,49 @@ def test_extract_images_from_doc(self):
filename = frappe.db.exists("File", {"attached_to_name": todo.name})
self.assertIn(f'<img src="{frappe.get_doc("File", filename).file_url}', todo.description)

def test_extract_images_from_comment(self):
"""
Ensure that images are extracted from comments and become private attachments.
"""
is_private = not frappe.get_meta("ToDo").make_attachments_public

test_doc = frappe.get_doc(dict(doctype="ToDo", description="comment test"))
test_doc.insert()
comment = add_comment(
"ToDo",
test_doc.name,
'<div class="ql-editor read-mode"><img src="data:image/png;filename=pix.png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII="></div>',
frappe.session.user,
frappe.session.user,
)
self.assertTrue(
frappe.db.exists("File", {"attached_to_name": test_doc.name, "is_private": is_private})
)
self.assertIn('<img src="/private/files/pix.png">', comment.content)

def test_extract_images_from_communication(self):
"""
Ensure that images are extracted from communication and become public attachments.
"""
is_private = not frappe.get_meta("Communication").make_attachments_public

communication = frappe.get_doc(
{
"doctype": "Communication",
"communication_type": "Communication",
"communication_medium": "Email",
"content": '<div class="ql-editor read-mode"><img src="data:image/png;filename=pix.png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII="></div>',
"recipients": "to <to@test.com>",
"cc": None,
"bcc": None,
"sender": "sender@test.com",
}
).insert(ignore_permissions=True)
self.assertTrue(
frappe.db.exists("File", {"attached_to_name": communication.name, "is_private": is_private})
)
self.assertIn('<img src="/files/pix.png">', communication.content)

def test_create_new_folder(self):
folder = create_new_folder("test_folder", "Home")
self.assertTrue(folder.is_folder)
Expand Down

0 comments on commit 7a17677

Please sign in to comment.