From a9526412fbb580ccc97c3613ddc362b11408469e Mon Sep 17 00:00:00 2001 From: Ankitashinde0 <53168131+Ankitashinde0@users.noreply.github.com> Date: Wed, 22 Jan 2020 18:16:54 +0530 Subject: [PATCH 1/2] Update admin.py --- src/auditlog/admin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/auditlog/admin.py b/src/auditlog/admin.py index 9724e3b4..091ce43f 100644 --- a/src/auditlog/admin.py +++ b/src/auditlog/admin.py @@ -7,7 +7,7 @@ class LogEntryAdmin(admin.ModelAdmin, LogEntryAdminMixin,MiddlewareMixinclass): - list_display = ['created','user_url','action','object_repr','msg_short','remote_addr'] + list_display = ['created','user_url','action','resource_url','msg_short','remote_addr'] search_fields = ['changes','remote_addr','object_repr'] list_filter = ['action',ResourceTypeFilter,'timestamp'] readonly_fields = ['created', 'resource_url', 'action', 'user_url', 'msg'] From 4667c097703978ceb7629b2f45d1e76f60e697da Mon Sep 17 00:00:00 2001 From: Ankitashinde0 <53168131+Ankitashinde0@users.noreply.github.com> Date: Wed, 22 Jan 2020 18:26:34 +0530 Subject: [PATCH 2/2] Update mixins.py --- src/auditlog/mixins.py | 73 +++++++++++++++++++++++++++++------------- 1 file changed, 50 insertions(+), 23 deletions(-) diff --git a/src/auditlog/mixins.py b/src/auditlog/mixins.py index 0f569da1..46f61845 100644 --- a/src/auditlog/mixins.py +++ b/src/auditlog/mixins.py @@ -38,22 +38,26 @@ def created(self, obj): new_ts = obj.timestamp.strftime("%m/%d/%Y %I:%M %p") new_ts = obj.timestamp.strptime(new_ts,"%m/%d/%Y %I:%M %p") system_tz = pytz.timezone(settings.TIME_ZONE) - local_tz = pytz.timezone('US/Eastern') #local tz set as ET - local_ts = system_tz.localize(new_ts).astimezone(local_tz) #returns datetime in the ET timezone + local_tz = pytz.timezone('US/Eastern') # local tz set as ET + local_ts = system_tz.localize(new_ts).astimezone(local_tz) # returns datetime in the ET timezone local_ts = local_ts.strftime("%m/%d/%Y %I:%M %p") return (local_ts +" ET") created.short_description = 'Date' + # returns entity type def entity_type(self,obj): - #entity type for KLC objects - if obj.content_type_id == 0: - return "N/A" - if obj.content_type_id == 8 or obj.content_type_id == 9: #Displays client for all models inside it - return "client" - if obj.content_type_id == 90 or obj.content_type_id == 10: #Displays user for all models inside it - return "user" - - return obj.content_type.model + if obj.content_type_id == 8 or obj.content_type_id == 9: # Displays client for all models inside it + return "Client: " + elif obj.content_type_id == 7: + return "Partner: " + if obj.content_type_id == 108: + return "Client group: " + if obj.content_type_id == 46: + return "Alert Type: " + if obj.content_type_id == 90 or obj.content_type_id == 10 or obj.content_type_id == 4: # Displays user for all models inside it + return "User: " + + return '' entity_type.short_description = "Entity type" def user_url(self, obj): @@ -65,11 +69,14 @@ def user_url(self, obj): except NoReverseMatch: return (obj.actor) return ( obj.actor) - return (obj.object_repr) #Previously returned system ,now changed to return object_repr(username) to display username in last_login entries - user_url.allow_tags = True #Returns user whose last_login is changed which is the username itself. + return (obj.object_repr) # Previously returned system ,now changed to return object_repr(username) to display username in last_login entries + user_url.allow_tags = True # Returns user whose last_login is changed which is the username itself. user_url.short_description = 'User' def resource_url(self, obj): + # entity name for KLC objects- no need of entity type + if obj.content_type_id == 0: + return obj.object_repr.capitalize() app_label, model = obj.content_type.app_label, obj.content_type.model viewname = 'admin:%s_%s_change' % (app_label, model) try: @@ -77,23 +84,43 @@ def resource_url(self, obj): link = urlresolvers.reverse(viewname, args=args) except NoReverseMatch: obj_store = obj.object_repr - return obj.object_repr + obj_type = str(LogEntryAdminMixin.entity_type(self,obj)) # converting entity type to string object + return obj_type + obj.object_repr #returning entity type and name else: obj_store = str(obj.object_repr) - return (obj.object_repr) + obj_type = str(LogEntryAdminMixin.entity_type(self,obj)) # converting entity type to string object + return obj_type + (obj.object_repr) #returning entity type and name resource_url.allow_tags = True resource_url.short_description = 'Entity name' +# returns source type for client api deletion message. + def source_type(self,obj): + if obj.action == 2 and obj.content_type_id == 8: + changes = json.loads(obj.changes) + if str(changes['source_type'][0]) == 'sophos': + return 'Next-Gen Endpoint Protection - Sophos' + elif str(changes['source_type'][0]) == 'kaseya': + return 'Security Profiler' + elif str(changes['source_type'][0]) == 'nlm': + return 'NLM' + elif str(changes['source_type'][0]) == 'firewall': + return 'Firewall' + elif str(changes['source_type'][0]) == 'webroot': + return 'Next-Gen Endpoint Protection - Webroot' + else: + return '' + def msg_short(self, obj): if obj.action == 3 or obj.action == 4 or obj.action == 0 and obj.content_type_id == 108 and obj.additional_data == "Client_name" or obj.action == 2 and obj.additional_data == "Client_name": #to display changes for actions of download-3,KLC-4 - return obj.changes #and also when create action-0 is done for client name in Client Group - if obj.action == 2: + return obj.changes # and also when create action-0 is done for client name in Client Group + if obj.action == 2: # deletion message returned with deleted object type if obj.content_type_id == 4: deleted_obj = "User" elif obj.content_type_id == 7: deleted_obj = "Partner" elif obj.content_type_id == 8: - deleted_obj = "Client API" + changes = json.loads(obj.changes) + deleted_obj = "Client source"+ ' ' +str(LogEntryAdminMixin.source_type(self,obj)) # to display source type in client api deletion message elif obj.content_type_id == 9: deleted_obj = "Client" elif obj.content_type_id == 10: @@ -123,23 +150,23 @@ def msg(self, obj): msg = '
No. | Field | From | To |
---|---|---|---|
%s | %s | %s | %s |