@@ -1803,7 +1803,9 @@ RestWrite.prototype.logAuditDataWrite = function () {
18031803    return  Promise . resolve ( ) ; 
18041804  } 
18051805
1806-   if  ( ( this . auth . isMaster  ||  this . auth . isMaintenance )  &&  ! this . auth . user )  { 
1806+   // Skip only master key operations without a user context 
1807+   // Maintenance mode operations should still be audited 
1808+   if  ( this . auth . isMaster  &&  ! this . auth . user )  { 
18071809    return  Promise . resolve ( ) ; 
18081810  } 
18091811
@@ -1815,8 +1817,10 @@ RestWrite.prototype.logAuditDataWrite = function () {
18151817  const  isCreate  =  ! this . query ; 
18161818  const  isUpdate  =  ! ! this . query ; 
18171819
1818-   const  aclModified  =  this . originalData  &&  this . originalData . ACL  &&  this . data . ACL  && 
1819-     JSON . stringify ( this . originalData . ACL )  !==  JSON . stringify ( this . data . ACL ) ; 
1820+   // Check if ACL was modified, including cases where ACL was added or removed 
1821+   const  originalACL  =  this . originalData ?. ACL  ??  null ; 
1822+   const  newACL  =  this . data ?. ACL  ??  null ; 
1823+   const  aclModified  =  isUpdate  &&  JSON . stringify ( originalACL )  !==  JSON . stringify ( newACL ) ; 
18201824
18211825  try  { 
18221826    if  ( isCreate )  { 
@@ -1849,15 +1853,14 @@ RestWrite.prototype.logAuditDataWrite = function () {
18491853        req : {  config : this . config  } , 
18501854        className : this . className , 
18511855        objectId : objectId , 
1852-         oldACL : this . originalData . ACL , 
1853-         newACL : this . data . ACL , 
1856+         oldACL : originalACL , 
1857+         newACL : newACL , 
18541858        success : true , 
18551859      } ) ; 
18561860    } 
18571861  }  catch  ( error )  { 
18581862    // Don't fail the write if audit logging fails 
1859-     // eslint-disable-next-line no-console 
1860-     console . error ( 'Audit logging error:' ,  error ) ; 
1863+     this . config . loggerController . error ( 'Audit logging error in RestWrite' ,  {  error } ) ; 
18611864  } 
18621865
18631866  return  Promise . resolve ( ) ; 
0 commit comments