File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -66,6 +66,8 @@ class AuditLog(TimeStampedModel):
66
66
and the deleted user/project/organization can be accessed via the ``log_*`` attributes.
67
67
"""
68
68
69
+ # pylint: disable=too-many-instance-attributes
70
+
69
71
PAGEVIEW = 'pageview'
70
72
DOWNLOAD = 'download'
71
73
AUTHN = 'authentication'
@@ -196,8 +198,18 @@ def save(self, **kwargs):
196
198
if self .organization :
197
199
self .log_organization_id = self .organization .id
198
200
self .log_organization_slug = self .organization .slug
201
+
202
+ self ._truncate_browser ()
203
+
199
204
super ().save (** kwargs )
200
205
206
+ def _truncate_browser (self ):
207
+ browser_max_length = self ._meta .get_field ("browser" ).max_length
208
+ if self .browser and len (self .browser ) > browser_max_length :
209
+ suffix = " - Truncated"
210
+ truncated_at = browser_max_length - len (suffix )
211
+ self .browser = self .browser [:truncated_at ] + suffix
212
+
201
213
def auth_backend_display (self ):
202
214
"""
203
215
Get a string representation for backends that aren't part of the normal login.
Original file line number Diff line number Diff line change @@ -77,3 +77,21 @@ def test_log_attached_to_organization_only(self):
77
77
self .assertEqual (log .organization , self .organization )
78
78
self .assertEqual (log .log_organization_id , self .organization .id )
79
79
self .assertEqual (log .log_organization_slug , self .organization .slug )
80
+
81
+ def test_truncate_browser (self ):
82
+ text = "a" * 250
83
+ log = get (
84
+ AuditLog ,
85
+ user = self .user ,
86
+ browser = text ,
87
+ )
88
+ self .assertEqual (log .browser , text )
89
+
90
+ text = "a" * 300
91
+ log = get (
92
+ AuditLog ,
93
+ user = self .user ,
94
+ browser = text ,
95
+ )
96
+ self .assertNotEqual (log .browser , text )
97
+ self .assertTrue (log .browser .endswith (" - Truncated" ))
You can’t perform that action at this time.
0 commit comments