Skip to content

Commit

Permalink
Merge branch 'production' into remove-nav-appversion
Browse files Browse the repository at this point in the history
  • Loading branch information
melton-jason authored Nov 17, 2024
2 parents d0bdd5d + 81a06b0 commit b971f0a
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions specifyweb/specify/auditlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
from django.db import connection
from django.conf import settings

from specifyweb.specify.models import Spauditlog
from specifyweb.specify.models import Spauditlogfield
from specifyweb.specify.models import Spauditlog, Spauditlogfield
from specifyweb.context.remote_prefs import get_remote_prefs, get_global_prefs
from specifyweb.specify.models import datamodel

Expand All @@ -18,6 +17,13 @@

from . import auditcodes

def truncate_str_to_bytes(string: str, bytes: int) -> str:
str_as_bytes = string.encode()
try:
return str_as_bytes[:bytes].decode()
except UnicodeDecodeError as err:
return str_as_bytes[:err.start].decode()

class AuditLog(object):

_auditingFlds = None
Expand Down Expand Up @@ -60,6 +66,8 @@ def insert(self, obj, agent, parent_record=None):
return self._log(auditcodes.INSERT, obj, agent, parent_record)

def remove(self, obj, agent, parent_record=None):
from specifyweb.specify.api import parse_uri

log_obj = self._log(auditcodes.REMOVE, obj, agent, parent_record)
if log_obj is not None:
for spfld in obj.specify_model.fields:
Expand Down Expand Up @@ -114,11 +122,12 @@ def _log(self, action, obj, agent, parent_record):
def _log_fld_update(self, vals, log, agent):
agent_id = agent if isinstance(agent, int) else (agent and agent.id)
newval = vals['new_value']
max_value_length = 2**16 - 1
if newval is not None:
newval = str(vals['new_value'])[:(2**16 - 1)]
newval = truncate_str_to_bytes(str(vals['new_value']), max_value_length)
oldval = vals['old_value']
if oldval is not None:
oldval = str(vals['old_value'])[:(2**16 - 1)]
oldval = truncate_str_to_bytes(str(vals['old_value']), max_value_length)
return Spauditlogfield.objects.create(
fieldname=vals['field_name'],
newvalue=newval,
Expand Down

0 comments on commit b971f0a

Please sign in to comment.