feat(sec): log IP addresses of login/logout activities (#21844)
This commit is contained in:
parent
ef51dde052
commit
e31038d7f9
3 changed files with 17 additions and 2 deletions
|
|
@ -2,5 +2,8 @@
|
|||
// For license information, please see license.txt
|
||||
|
||||
frappe.ui.form.on("Activity Log", {
|
||||
refresh: function () {},
|
||||
refresh: function (frm) {
|
||||
// Nothing in this form is supposed to be editable.
|
||||
frm.disable_form();
|
||||
},
|
||||
});
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
"column_break_5",
|
||||
"additional_info",
|
||||
"communication_date",
|
||||
"ip_address",
|
||||
"column_break_7",
|
||||
"operation",
|
||||
"status",
|
||||
|
|
@ -148,12 +149,17 @@
|
|||
"fieldtype": "Data",
|
||||
"in_list_view": 1,
|
||||
"label": "Full Name"
|
||||
},
|
||||
{
|
||||
"fieldname": "ip_address",
|
||||
"fieldtype": "Data",
|
||||
"label": "IP Address"
|
||||
}
|
||||
],
|
||||
"icon": "fa fa-comment",
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2022-09-13 15:19:42.474114",
|
||||
"modified": "2023-07-28 13:26:32.281278",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Core",
|
||||
"name": "Activity Log",
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ class ActivityLog(Document):
|
|||
communication_date: DF.Datetime | None
|
||||
content: DF.TextEditor | None
|
||||
full_name: DF.Data | None
|
||||
ip_address: DF.Data | None
|
||||
link_doctype: DF.Link | None
|
||||
link_name: DF.DynamicLink | None
|
||||
operation: DF.Literal["", "Login", "Logout"]
|
||||
|
|
@ -40,6 +41,7 @@ class ActivityLog(Document):
|
|||
def validate(self):
|
||||
self.set_status()
|
||||
set_timeline_doc(self)
|
||||
self.set_ip_address()
|
||||
|
||||
def set_status(self):
|
||||
if not self.is_new():
|
||||
|
|
@ -48,6 +50,10 @@ class ActivityLog(Document):
|
|||
if self.reference_doctype and self.reference_name:
|
||||
self.status = "Linked"
|
||||
|
||||
def set_ip_address(self):
|
||||
if self.operation in ("Login", "Logout"):
|
||||
self.ip_address = getattr(frappe.local, "request_ip")
|
||||
|
||||
@staticmethod
|
||||
def clear_old_logs(days=None):
|
||||
if not days:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue