diff --git a/crm/api/__init__.py b/crm/api/__init__.py index 141da446..58739de0 100644 --- a/crm/api/__init__.py +++ b/crm/api/__init__.py @@ -3,6 +3,7 @@ import frappe from frappe.translate import get_all_translations from frappe.utils import validate_email_address, split_emails, cstr from frappe.utils.telemetry import POSTHOG_HOST_FIELD, POSTHOG_PROJECT_FIELD +from frappe.core.api.file import get_max_file_size @frappe.whitelist(allow_guest=True) @@ -107,3 +108,20 @@ def invite_by_email(emails: str, role: str): for email in to_invite: frappe.get_doc(doctype="CRM Invitation", email=email, role=role).insert(ignore_permissions=True) + + +@frappe.whitelist() +def get_file_uploader_defaults(doctype: str): + max_number_of_files = None + make_attachments_public = False + if doctype: + meta = frappe.get_meta(doctype) + max_number_of_files = meta.get("max_attachments") + make_attachments_public = meta.get("make_attachments_public") + + return { + 'allowed_file_types': frappe.get_system_settings("allowed_file_extensions"), + 'max_file_size': get_max_file_size(), + 'max_number_of_files': max_number_of_files, + 'make_attachments_public': bool(make_attachments_public), + } \ No newline at end of file diff --git a/crm/api/activities.py b/crm/api/activities.py index 31d74580..8cc714eb 100644 --- a/crm/api/activities.py +++ b/crm/api/activities.py @@ -1,5 +1,6 @@ import json +from bs4 import BeautifulSoup import frappe from frappe import _ from frappe.utils.caching import redis_cache @@ -35,10 +36,11 @@ def get_deal_activities(name): calls = [] notes = [] tasks = [] + attachments = [] creation_text = "created this deal" if lead: - activities, calls, notes, tasks = get_lead_activities(lead) + activities, calls, notes, tasks, attachments = get_lead_activities(lead) creation_text = "converted the lead to this deal" activities.append({ @@ -131,14 +133,26 @@ def get_deal_activities(name): } activities.append(activity) + for attachment_log in docinfo.attachment_logs: + activity = { + "name": attachment_log.name, + "activity_type": "attachment_log", + "creation": attachment_log.creation, + "owner": attachment_log.owner, + "data": parse_attachment_log(attachment_log.content, attachment_log.comment_type), + "is_lead": False, + } + activities.append(activity) + calls = calls + get_linked_calls(name) notes = notes + get_linked_notes(name) tasks = tasks + get_linked_tasks(name) + attachments = attachments + get_attachments('CRM Deal', name) activities.sort(key=lambda x: x["creation"], reverse=True) activities = handle_multiple_versions(activities) - return activities, calls, notes, tasks + return activities, calls, notes, tasks, attachments def get_lead_activities(name): get_docinfo('', "CRM Lead", name) @@ -245,22 +259,34 @@ def get_lead_activities(name): } activities.append(activity) + for attachment_log in docinfo.attachment_logs: + activity = { + "name": attachment_log.name, + "activity_type": "attachment_log", + "creation": attachment_log.creation, + "owner": attachment_log.owner, + "data": parse_attachment_log(attachment_log.content, attachment_log.comment_type), + "is_lead": True, + } + activities.append(activity) + calls = get_linked_calls(name) notes = get_linked_notes(name) tasks = get_linked_tasks(name) + attachments = get_attachments('CRM Lead', name) activities.sort(key=lambda x: x["creation"], reverse=True) activities = handle_multiple_versions(activities) - return activities, calls, notes, tasks + return activities, calls, notes, tasks, attachments + -@redis_cache() def get_attachments(doctype, name): return frappe.db.get_all( "File", filters={"attached_to_doctype": doctype, "attached_to_name": name}, - fields=["name", "file_name", "file_url", "file_size", "is_private"], - ) + fields=["name", "file_name", "file_type", "file_url", "file_size", "is_private", "creation", "owner"], + ) or [] def handle_multiple_versions(versions): activities = [] @@ -342,3 +368,26 @@ def get_linked_tasks(name): ], ) return tasks or [] + +def parse_attachment_log(html, type): + soup = BeautifulSoup(html, "html.parser") + a_tag = soup.find("a") + type = "added" if type == "Attachment" else "removed" + if not a_tag: + return { + "type": type, + "file_name": html.replace("Removed ", ""), + "file_url": "", + "is_private": False, + } + + is_private = False + if "private/files" in a_tag["href"]: + is_private = True + + return { + "type": type, + "file_name": a_tag.text, + "file_url": a_tag["href"], + "is_private": is_private, + } \ No newline at end of file diff --git a/crm/www/crm.py b/crm/www/crm.py index 44347cf3..22b2ed58 100644 --- a/crm/www/crm.py +++ b/crm/www/crm.py @@ -9,11 +9,9 @@ no_cache = 1 def get_context(): - csrf_token = frappe.sessions.get_csrf_token() frappe.db.commit() context = frappe._dict() context.boot = get_boot() - context.boot.csrf_token = csrf_token if frappe.session.user != "Guest": capture("active_site", "crm") return context @@ -33,6 +31,7 @@ def get_boot(): "default_route": get_default_route(), "site_name": frappe.local.site, "read_only_mode": frappe.flags.read_only, + "csrf_token": frappe.sessions.get_csrf_token(), } ) diff --git a/frappe-ui b/frappe-ui index 427b7618..b2dbd419 160000 --- a/frappe-ui +++ b/frappe-ui @@ -1 +1 @@ -Subproject commit 427b76188fe8b20e683bccf9bb4003821253259f +Subproject commit b2dbd41936905aa46b18d3c22e5d09a7b08a9b98 diff --git a/frontend/package.json b/frontend/package.json index 18861947..56683963 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -14,7 +14,7 @@ "@vueuse/core": "^10.3.0", "@vueuse/integrations": "^10.3.0", "feather-icons": "^4.28.0", - "frappe-ui": "^0.1.70", + "frappe-ui": "^0.1.71", "gemoji": "^8.1.0", "lodash": "^4.17.21", "mime": "^4.0.1", diff --git a/frontend/src/components/Activities/Activities.vue b/frontend/src/components/Activities/Activities.vue index 55e6fae5..18ae007c 100644 --- a/frontend/src/components/Activities/Activities.vue +++ b/frontend/src/components/Activities/Activities.vue @@ -2,6 +2,7 @@ - +
@@ -103,6 +98,15 @@
+
+ +
+
+
+
+ {{ activity.owner_name }} + {{ __(activity.data.type) }} + + {{ activity.data.file_name }} + + {{ activity.data.file_name }} + +
+
+ +
+ {{ __(timeAgo(activity.creation)) }} +
+
+
+
+
+
@@ -395,6 +438,18 @@ :doctype="doctype" :doc="doc" /> + diff --git a/frontend/src/components/Activities/ActivityHeader.vue b/frontend/src/components/Activities/ActivityHeader.vue index 60a70898..9f734d4e 100644 --- a/frontend/src/components/Activities/ActivityHeader.vue +++ b/frontend/src/components/Activities/ActivityHeader.vue @@ -55,6 +55,16 @@ {{ __('New Task') }} +
+ + +
@@ -299,6 +304,18 @@ doctype="CRM Deal" @reload="() => fieldsLayout.reload()" /> +