From acdbb97ba5dd550e81ca334ad33f77823efd0957 Mon Sep 17 00:00:00 2001 From: Shreya Shah Date: Tue, 21 Nov 2017 15:46:51 +0530 Subject: [PATCH] Moved feed from Communication to Activity Log (#4435) * Removed comment_type 'updated' * New doctype activity log * Moved feed.py to activity_log * Updated feed gets stored in activity_log * Activity page fetches feed from activity_log * feed match condition change * modified * modified hooks.py * modified sessions.py * patch added * naming in patch * moved login, logout feed to activity_log * changes in auth.py, hooks.py * deleted doctype authentication_log and added test cases * added utils.py in core * moved some methods from communication.py to utils.py --- frappe/auth.py | 2 +- .../__init__.py | 0 .../core/doctype/activity_log/activity_log.js | 8 + .../doctype/activity_log/activity_log.json | 717 ++++++++++++++++++ .../core/doctype/activity_log/activity_log.py | 49 ++ .../activity_log_list.js} | 2 +- .../{communication => activity_log}/feed.py | 25 +- .../test_activity_log.py} | 10 +- .../authentication_log/authentication_log.js | 8 - .../authentication_log.json | 341 --------- .../authentication_log/authentication_log.py | 27 - .../doctype/communication/communication.json | 10 +- .../doctype/communication/communication.py | 60 +- frappe/core/doctype/communication/email.py | 8 +- .../communication/test_communication.js | 23 + frappe/core/utils.py | 34 + frappe/desk/page/activity/activity.py | 22 +- frappe/hooks.py | 6 +- frappe/model/delete_doc.py | 16 +- frappe/patches.txt | 3 +- .../patches/v9_1/move_feed_to_activity_log.py | 25 + frappe/sessions.py | 2 +- frappe/tests/ui/tests.txt | 2 +- 23 files changed, 945 insertions(+), 455 deletions(-) rename frappe/core/doctype/{authentication_log => activity_log}/__init__.py (100%) create mode 100644 frappe/core/doctype/activity_log/activity_log.js create mode 100644 frappe/core/doctype/activity_log/activity_log.json create mode 100644 frappe/core/doctype/activity_log/activity_log.py rename frappe/core/doctype/{authentication_log/authentication_log_list.js => activity_log/activity_log_list.js} (81%) rename frappe/core/doctype/{communication => activity_log}/feed.py (72%) rename frappe/core/doctype/{authentication_log/test_authentication_log.py => activity_log/test_activity_log.py} (79%) delete mode 100644 frappe/core/doctype/authentication_log/authentication_log.js delete mode 100644 frappe/core/doctype/authentication_log/authentication_log.json delete mode 100644 frappe/core/doctype/authentication_log/authentication_log.py create mode 100644 frappe/core/doctype/communication/test_communication.js create mode 100644 frappe/core/utils.py create mode 100644 frappe/patches/v9_1/move_feed_to_activity_log.py diff --git a/frappe/auth.py b/frappe/auth.py index 2e197eb94a..40694bbfef 100644 --- a/frappe/auth.py +++ b/frappe/auth.py @@ -15,7 +15,7 @@ from frappe.sessions import Session, clear_sessions, delete_session from frappe.modules.patch_handler import check_session_stopped from frappe.translate import get_lang_code from frappe.utils.password import check_password -from frappe.core.doctype.authentication_log.authentication_log import add_authentication_log +from frappe.core.doctype.activity_log.activity_log import add_authentication_log from frappe.utils.background_jobs import enqueue from frappe.twofactor import (should_run_2fa, authenticate_for_2factor, confirm_otp_token, get_cached_user_pass) diff --git a/frappe/core/doctype/authentication_log/__init__.py b/frappe/core/doctype/activity_log/__init__.py similarity index 100% rename from frappe/core/doctype/authentication_log/__init__.py rename to frappe/core/doctype/activity_log/__init__.py diff --git a/frappe/core/doctype/activity_log/activity_log.js b/frappe/core/doctype/activity_log/activity_log.js new file mode 100644 index 0000000000..97e49e4b34 --- /dev/null +++ b/frappe/core/doctype/activity_log/activity_log.js @@ -0,0 +1,8 @@ +// Copyright (c) 2017, Frappe Technologies and contributors +// For license information, please see license.txt + +frappe.ui.form.on('Activity Log', { + refresh: function() { + + } +}); diff --git a/frappe/core/doctype/activity_log/activity_log.json b/frappe/core/doctype/activity_log/activity_log.json new file mode 100644 index 0000000000..02360247af --- /dev/null +++ b/frappe/core/doctype/activity_log/activity_log.json @@ -0,0 +1,717 @@ +{ + "allow_copy": 0, + "allow_guest_to_view": 0, + "allow_import": 1, + "allow_rename": 0, + "autoname": "", + "beta": 0, + "creation": "2017-10-05 11:10:38.780133", + "custom": 0, + "description": "Keep track of all update feeds", + "docstatus": 0, + "doctype": "DocType", + "document_type": "Setup", + "editable_grid": 0, + "engine": "InnoDB", + "fields": [ + { + "allow_bulk_edit": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "subject", + "fieldtype": "Small Text", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 1, + "in_list_view": 1, + "in_standard_filter": 0, + "label": "Subject", + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 1, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, + { + "allow_bulk_edit": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "section_break_8", + "fieldtype": "Section Break", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, + { + "allow_bulk_edit": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "content", + "fieldtype": "Text Editor", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Message", + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0, + "width": "400" + }, + { + "allow_bulk_edit": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "column_break_5", + "fieldtype": "Column Break", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, + { + "allow_bulk_edit": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 1, + "columns": 0, + "fieldname": "additional_info", + "fieldtype": "Section Break", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "More Information", + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, + { + "allow_bulk_edit": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "default": "Now", + "fieldname": "communication_date", + "fieldtype": "Datetime", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Date", + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, + { + "allow_bulk_edit": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "column_break_7", + "fieldtype": "Column Break", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, + { + "allow_bulk_edit": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "operation", + "fieldtype": "Select", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Operation", + "length": 0, + "no_copy": 0, + "options": "\nLogin\nLogout", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, + { + "allow_bulk_edit": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "status", + "fieldtype": "Select", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 1, + "in_standard_filter": 0, + "label": "Status", + "length": 0, + "no_copy": 0, + "options": "\nSuccess\nFailed\nLinked\nClosed", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, + { + "allow_bulk_edit": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 1, + "columns": 0, + "fieldname": "reference_section", + "fieldtype": "Section Break", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Reference", + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, + { + "allow_bulk_edit": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "reference_doctype", + "fieldtype": "Link", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Reference DocType", + "length": 0, + "no_copy": 0, + "options": "DocType", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, + { + "allow_bulk_edit": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "reference_name", + "fieldtype": "Dynamic Link", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Reference Name", + "length": 0, + "no_copy": 0, + "options": "reference_doctype", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, + { + "allow_bulk_edit": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "reference_owner", + "fieldtype": "Read Only", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Reference Owner", + "length": 0, + "no_copy": 0, + "options": "reference_name.owner", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 1, + "set_only_once": 0, + "unique": 0 + }, + { + "allow_bulk_edit": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "column_break_14", + "fieldtype": "Column Break", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, + { + "allow_bulk_edit": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "timeline_doctype", + "fieldtype": "Link", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Timeline DocType", + "length": 0, + "no_copy": 0, + "options": "DocType", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, + { + "allow_bulk_edit": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "timeline_name", + "fieldtype": "Dynamic Link", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Timeline Name", + "length": 0, + "no_copy": 0, + "options": "timeline_doctype", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, + { + "allow_bulk_edit": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "link_doctype", + "fieldtype": "Link", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Link DocType", + "length": 0, + "no_copy": 0, + "options": "DocType", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 1, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, + { + "allow_bulk_edit": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "link_name", + "fieldtype": "Dynamic Link", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Link Name", + "length": 0, + "no_copy": 0, + "options": "link_doctype", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 1, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, + { + "allow_bulk_edit": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "default": "__user", + "fieldname": "user", + "fieldtype": "Link", + "hidden": 0, + "ignore_user_permissions": 1, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "User", + "length": 0, + "no_copy": 0, + "options": "User", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 1, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, + { + "allow_bulk_edit": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "full_name", + "fieldtype": "Data", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 1, + "in_standard_filter": 0, + "label": "Full Name", + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + } + ], + "has_web_view": 0, + "hide_heading": 0, + "hide_toolbar": 0, + "icon": "fa fa-comment", + "idx": 0, + "image_view": 0, + "in_create": 0, + "is_submittable": 0, + "issingle": 0, + "istable": 0, + "max_attachments": 0, + "modified": "2017-11-21 12:39:23.659308", + "modified_by": "Administrator", + "module": "Core", + "name": "Activity Log", + "name_case": "", + "owner": "Administrator", + "permissions": [ + { + "amend": 0, + "apply_user_permissions": 0, + "cancel": 0, + "create": 1, + "delete": 1, + "email": 1, + "export": 0, + "if_owner": 0, + "import": 0, + "permlevel": 0, + "print": 0, + "read": 1, + "report": 1, + "role": "System Manager", + "set_user_permissions": 0, + "share": 1, + "submit": 0, + "write": 0 + }, + { + "amend": 0, + "apply_user_permissions": 0, + "cancel": 0, + "create": 0, + "delete": 1, + "email": 1, + "export": 1, + "if_owner": 0, + "import": 0, + "permlevel": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "System Manager", + "set_user_permissions": 0, + "share": 1, + "submit": 0, + "write": 0 + }, + { + "amend": 0, + "apply_user_permissions": 1, + "cancel": 0, + "create": 0, + "delete": 1, + "email": 1, + "export": 0, + "if_owner": 1, + "import": 0, + "permlevel": 0, + "print": 0, + "read": 1, + "report": 0, + "role": "All", + "set_user_permissions": 0, + "share": 0, + "submit": 0, + "user_permission_doctypes": "[\"Email Account\"]", + "write": 0 + } + ], + "quick_entry": 0, + "read_only": 0, + "read_only_onload": 0, + "search_fields": "subject", + "show_name_in_global_search": 0, + "sort_field": "modified", + "sort_order": "DESC", + "title_field": "subject", + "track_changes": 1, + "track_seen": 1 +} \ No newline at end of file diff --git a/frappe/core/doctype/activity_log/activity_log.py b/frappe/core/doctype/activity_log/activity_log.py new file mode 100644 index 0000000000..33e444650b --- /dev/null +++ b/frappe/core/doctype/activity_log/activity_log.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2017, Frappe Technologies and contributors +# For license information, please see license.txt + +from __future__ import unicode_literals +from frappe import _ +from frappe.utils import get_fullname, now +from frappe.model.document import Document +from frappe.core.utils import get_parent_doc, set_timeline_doc +import frappe + +class ActivityLog(Document): + def before_insert(self): + self.full_name = get_fullname(self.user) + self.date = now() + + def validate(self): + self.set_status() + set_timeline_doc(self) + + def set_status(self): + if not self.is_new(): + return + + if self.reference_doctype and self.reference_name: + self.status = "Linked" + + def on_trash(self): # pylint: disable=no-self-use + frappe.throw(_("Sorry! You cannot delete auto-generated comments")) + +def on_doctype_update(): + """Add indexes in `tabActivity Log`""" + frappe.db.add_index("Activity Log", ["reference_doctype", "reference_name"]) + frappe.db.add_index("Activity Log", ["timeline_doctype", "timeline_name"]) + frappe.db.add_index("Activity Log", ["link_doctype", "link_name"]) + +def add_authentication_log(subject, user, operation="Login", status="Success"): + frappe.get_doc({ + "doctype": "Activity Log", + "user": user, + "status": status, + "subject": subject, + "operation": operation, + }).insert(ignore_permissions=True) + +def clear_authentication_logs(): + """clear 100 day old authentication logs""" + frappe.db.sql("""delete from `tabActivity Log` where \ + creation frappe.tests.make('Communication', [ + // values to be set + {key: 'value'} + ]), + () => { + assert.equal(cur_frm.doc.key, 'value'); + }, + () => done() + ]); + +}); diff --git a/frappe/core/utils.py b/frappe/core/utils.py new file mode 100644 index 0000000000..01f18c16d0 --- /dev/null +++ b/frappe/core/utils.py @@ -0,0 +1,34 @@ +# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors +# MIT License. See license.txt + +import frappe +from frappe import _ + +def get_parent_doc(doc): + """Returns document of `reference_doctype`, `reference_doctype`""" + if not hasattr(doc, "parent_doc"): + if doc.reference_doctype and doc.reference_name: + doc.parent_doc = frappe.get_doc(doc.reference_doctype, doc.reference_name) + else: + doc.parent_doc = None + return doc.parent_doc + +def set_timeline_doc(doc): + """Set timeline_doctype and timeline_name""" + parent_doc = get_parent_doc(doc) + if (doc.timeline_doctype and doc.timeline_name) or not parent_doc: + return + + timeline_field = parent_doc.meta.timeline_field + if not timeline_field: + return + + doctype = parent_doc.meta.get_link_doctype(timeline_field) + name = parent_doc.get(timeline_field) + + if doctype and name: + doc.timeline_doctype = doctype + doc.timeline_name = name + + else: + return \ No newline at end of file diff --git a/frappe/desk/page/activity/activity.py b/frappe/desk/page/activity/activity.py index 94b0296b6f..54d643ade2 100644 --- a/frappe/desk/page/activity/activity.py +++ b/frappe/desk/page/activity/activity.py @@ -4,25 +4,31 @@ from __future__ import unicode_literals import frappe from frappe.utils import cint -from frappe.core.doctype.communication.feed import get_feed_match_conditions +from frappe.core.doctype.activity_log.feed import get_feed_match_conditions @frappe.whitelist() def get_feed(start, page_length, show_likes=False): """get feed""" match_conditions = get_feed_match_conditions(frappe.session.user) - result = frappe.db.sql("""select name, owner, modified, creation, seen, comment_type, + result = frappe.db.sql("""select X.* + from (select name, owner, modified, creation, seen, comment_type, reference_doctype, reference_name, link_doctype, link_name, subject, communication_type, communication_medium, content - from `tabCommunication` - where + from `tabCommunication` + where communication_type in ("Communication", "Comment") and communication_medium != "Email" and (comment_type is null or comment_type != "Like" or (comment_type="Like" and (owner=%(user)s or reference_owner=%(user)s))) {match_conditions} {show_likes} - order by creation desc + union + select name, owner, modified, creation, '0', 'Updated', + reference_doctype, reference_name, link_doctype, link_name, subject, + 'Comment', '', content + from `tabActivity Log`) X + order by X.creation DESC limit %(start)s, %(page_length)s""" .format(match_conditions="and {0}".format(match_conditions) if match_conditions else "", show_likes="and comment_type='Like'" if show_likes else ""), @@ -43,10 +49,8 @@ def get_feed(start, page_length, show_likes=False): @frappe.whitelist() def get_heatmap_data(): return dict(frappe.db.sql("""select unix_timestamp(date(creation)), count(name) - from `tabCommunication` + from `tabActivity Log` where - communication_type in ("Communication", "Comment") - and communication_medium != "Email" - and date(creation) > subdate(curdate(), interval 1 year) + date(creation) > subdate(curdate(), interval 1 year) group by date(creation) order by creation asc""")) \ No newline at end of file diff --git a/frappe/hooks.py b/frappe/hooks.py index 503e60f811..11ab305296 100755 --- a/frappe/hooks.py +++ b/frappe/hooks.py @@ -68,7 +68,7 @@ calendars = ["Event"] # login on_session_creation = [ - "frappe.core.doctype.communication.feed.login_feed", + "frappe.core.doctype.activity_log.feed.login_feed", "frappe.core.doctype.user.user.notify_admin_access_to_system_manager", "frappe.limits.check_if_expired", "frappe.utils.scheduler.reset_enabled_scheduler_events", @@ -110,7 +110,7 @@ doc_events = { "*": { "on_update": [ "frappe.desk.notifications.clear_doctype_notifications", - "frappe.core.doctype.communication.feed.update_feed" + "frappe.core.doctype.activity_log.feed.update_feed" ], "after_rename": "frappe.desk.notifications.clear_doctype_notifications", "on_cancel": [ @@ -153,7 +153,7 @@ scheduler_events = { "frappe.utils.scheduler.restrict_scheduler_events_if_dormant", "frappe.email.doctype.auto_email_report.auto_email_report.send_daily", "frappe.core.doctype.feedback_request.feedback_request.delete_feedback_request", - "frappe.core.doctype.authentication_log.authentication_log.clear_authentication_logs" + "frappe.core.doctype.activity_log.activity_log.clear_authentication_logs" ], "daily_long": [ "frappe.integrations.doctype.dropbox_settings.dropbox_settings.take_backups_daily", diff --git a/frappe/model/delete_doc.py b/frappe/model/delete_doc.py index f528a4103c..8d6587b1bc 100644 --- a/frappe/model/delete_doc.py +++ b/frappe/model/delete_doc.py @@ -188,7 +188,7 @@ def check_if_doc_is_linked(doc, method="Delete"): for item in frappe.db.get_values(link_dt, {link_field:doc.name}, ["name", "parent", "parenttype", "docstatus"], as_dict=True): linked_doctype = item.parenttype if item.parent else link_dt - if linked_doctype in ("Communication", "ToDo", "DocShare", "Email Unsubscribe", 'File', 'Version'): + if linked_doctype in ("Communication", "ToDo", "DocShare", "Email Unsubscribe", 'File', 'Version', "Activity Log"): # don't check for communication and todo! continue @@ -204,7 +204,7 @@ def check_if_doc_is_linked(doc, method="Delete"): def check_if_doc_is_dynamically_linked(doc, method="Delete"): '''Raise `frappe.LinkExistsError` if the document is dynamically linked''' for df in get_dynamic_link_map().get(doc.doctype, []): - if df.parent in ("Communication", "ToDo", "DocShare", "Email Unsubscribe", 'File', 'Version'): + if df.parent in ("Communication", "ToDo", "DocShare", "Email Unsubscribe", "Activity Log", 'File', 'Version'): # don't check for communication and todo! continue @@ -276,6 +276,18 @@ def delete_dynamic_links(doctype, name): set timeline_doctype=null, timeline_name=null where timeline_doctype=%s and timeline_name=%s""", (doctype, name)) + # unlink activity_log reference_doctype + frappe.db.sql("""update `tabActivity Log` + set reference_doctype=null, reference_name=null + where + reference_doctype=%s + and reference_name=%s""", (doctype, name)) + + # unlink activity_log timeline_doctype + frappe.db.sql("""update `tabActivity Log` + set timeline_doctype=null, timeline_name=null + where timeline_doctype=%s and timeline_name=%s""", (doctype, name)) + def insert_feed(doc): from frappe.utils import get_fullname diff --git a/frappe/patches.txt b/frappe/patches.txt index e435669db4..f353e9a383 100644 --- a/frappe/patches.txt +++ b/frappe/patches.txt @@ -197,4 +197,5 @@ frappe.patches.v8_10.delete_static_web_page_from_global_search frappe.patches.v8_x.add_bgn_xaf_xof_currencies frappe.patches.v9_1.add_sms_sender_name_as_parameters frappe.patches.v9_1.resave_domain_settings -frappe.patches.v9_1.revert_domain_settings \ No newline at end of file +frappe.patches.v9_1.revert_domain_settings +frappe.patches.v9_1.move_feed_to_activity_log \ No newline at end of file diff --git a/frappe/patches/v9_1/move_feed_to_activity_log.py b/frappe/patches/v9_1/move_feed_to_activity_log.py new file mode 100644 index 0000000000..95ae500b1d --- /dev/null +++ b/frappe/patches/v9_1/move_feed_to_activity_log.py @@ -0,0 +1,25 @@ +import frappe + +def execute(): + frappe.reload_doc("core", "doctype", "communication") + frappe.reload_doc("core", "doctype", "activity_log") + + communication_data = frappe.get_all('Communication', filters= {'comment_type': 'Updated'}) + activity_log_fields = frappe.get_meta('Activity Log').fields + + for d in communication_data: + communication_doc = frappe.get_doc('Communication', d) + + activity_data = {'doctype': 'Activity Log'} + for field in activity_log_fields: + if communication_doc.get(field.fieldname): + activity_data[field.fieldname] = communication_doc.get_value(field.fieldname) + + activity_doc = frappe.get_doc(activity_data) + activity_doc.insert() + + frappe.db.sql("""update `tabActivity Log` set creation = %s,\ + modified = %s where name = %s""", (communication_doc.creation,communication_doc.modified,activity_doc.name)) + + frappe.db.sql("""delete from `tabCommunication` where name='{0}'""".format(communication_doc.name)) + frappe.delete_doc("DocType", "Authentication Log") diff --git a/frappe/sessions.py b/frappe/sessions.py index 2dc574014c..f35a667dc6 100644 --- a/frappe/sessions.py +++ b/frappe/sessions.py @@ -101,7 +101,7 @@ def get_sessions_to_clear(user=None, keep_current=False, device=None): (user, device)) def delete_session(sid=None, user=None, reason="Session Expired"): - from frappe.core.doctype.communication.feed import logout_feed + from frappe.core.doctype.activity_log.feed import logout_feed frappe.cache().hdel("session", sid) frappe.cache().hdel("last_db_session_update", sid) diff --git a/frappe/tests/ui/tests.txt b/frappe/tests/ui/tests.txt index da04d66d4f..2fcbf64851 100644 --- a/frappe/tests/ui/tests.txt +++ b/frappe/tests/ui/tests.txt @@ -17,4 +17,4 @@ frappe/core/doctype/role_profile/test_role_profile.js frappe/core/doctype/user/test_user_with_role_profile.js frappe/tests/ui/test_list_count.js frappe/workflow/doctype/workflow/tests/test_workflow_create.js -frappe/workflow/doctype/workflow/tests/test_workflow_test.js +frappe/workflow/doctype/workflow/tests/test_workflow_test.js \ No newline at end of file