@@ -1803,7 +1803,9 @@ RestWrite.prototype.logAuditDataWrite = function () {
1803
1803
return Promise . resolve ( ) ;
1804
1804
}
1805
1805
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 ) {
1807
1809
return Promise . resolve ( ) ;
1808
1810
}
1809
1811
@@ -1815,8 +1817,10 @@ RestWrite.prototype.logAuditDataWrite = function () {
1815
1817
const isCreate = ! this . query ;
1816
1818
const isUpdate = ! ! this . query ;
1817
1819
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 ) ;
1820
1824
1821
1825
try {
1822
1826
if ( isCreate ) {
@@ -1849,15 +1853,14 @@ RestWrite.prototype.logAuditDataWrite = function () {
1849
1853
req : { config : this . config } ,
1850
1854
className : this . className ,
1851
1855
objectId : objectId ,
1852
- oldACL : this . originalData . ACL ,
1853
- newACL : this . data . ACL ,
1856
+ oldACL : originalACL ,
1857
+ newACL : newACL ,
1854
1858
success : true ,
1855
1859
} ) ;
1856
1860
}
1857
1861
} catch ( error ) {
1858
1862
// 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 } ) ;
1861
1864
}
1862
1865
1863
1866
return Promise . resolve ( ) ;
0 commit comments