Skip to content

Commit a324cc4

Browse files
authored
Merge pull request #38 from rtCamp/fix/s3-attachments
Enhance attachment handling by retrieving latest file URLs in get_attachments_data function
2 parents e52461b + 9840f4b commit a324cc4

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
exclude: 'node_modules|.git'
2-
default_stages: [commit]
2+
default_stages: [pre-commit]
33
fail_fast: false
44

55
repos:

frappe_gmail_thread/api/activity.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@
44
import frappe.utils
55

66

7+
def get_attachments_data(email):
8+
attachments_data = json.loads(email.attachments_data)
9+
# instead of using file_url from attachments_data, we have to use frappe.get_value to get the latest file_url
10+
for attachment in attachments_data:
11+
file_doc_name = attachment.get("file_doc_name")
12+
if file_doc_name:
13+
file_url = frappe.db.get_value("File", file_doc_name, "file_url")
14+
attachment["file_url"] = file_url
15+
return attachments_data
16+
17+
718
@frappe.whitelist()
819
def get_linked_gmail_threads(doctype, docname):
920
gmail_threads = frappe.get_all(
@@ -49,7 +60,7 @@ def get_linked_gmail_threads(doctype, docname):
4960
"read_by_recipient": email.read_by_recipient,
5061
"rating": 0, # TODO: add rating
5162
"recipients": email.recipients,
52-
"attachments": json.loads(email.attachments_data),
63+
"attachments": get_attachments_data(email),
5364
"_url": thread.get_url(),
5465
"_doc_status": (
5566
"Sent" if email.sent_or_received == "Sent" else "Received"

frappe_gmail_thread/utils/helpers.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ def process_attachments(new_email, gmail_thread, email_object):
205205
{
206206
"file_name": _file.file_name,
207207
"file_doc_name": _file.name,
208-
"file_url": _file.file_url,
209208
"is_private": _file.is_private,
210209
}
211210
)

0 commit comments

Comments
 (0)