@@ -25,6 +25,7 @@ import { Match, check } from 'meteor/check';
2525import { Meteor } from 'meteor/meteor' ;
2626import type { Filter } from 'mongodb' ;
2727
28+ import { UserChangedAuditStore } from '../../../../server/lib/auditServerEvents/userChanged' ;
2829import { i18n } from '../../../../server/lib/i18n' ;
2930import { resetUserE2EEncriptionKey } from '../../../../server/lib/resetUserE2EKey' ;
3031import { sendWelcomeEmail } from '../../../../server/lib/sendWelcomeEmail' ;
@@ -101,10 +102,17 @@ API.v1.addRoute(
101102 if ( userData . name && ! validateNameChars ( userData . name ) ) {
102103 return API . v1 . failure ( 'Name contains invalid characters' ) ;
103104 }
105+ const auditStore = new UserChangedAuditStore ( {
106+ _id : this . bodyParams . userId ,
107+ ip : this . requestIp ,
108+ useragent : this . request . headers [ 'user-agent' ] || '' ,
109+ username : ( await Meteor . userAsync ( ) ) ?. username || '' ,
110+ } ) ;
104111
105- const updater = Users . getUpdater ( ) ;
106- await saveUser ( this . userId , userData , updater ) ;
112+ const _updater = Users . getUpdater ( ) ;
113+ await saveUser ( this . userId , userData , { _updater , auditStore } ) ;
107114
115+ // Waiting for customfields refactor to be merged, then this will be audited within saveUser function
108116 if ( this . bodyParams . data . customFields ) {
109117 await saveCustomFields ( this . bodyParams . userId , this . bodyParams . data . customFields ) ;
110118 }
@@ -117,7 +125,20 @@ API.v1.addRoute(
117125 } = this . bodyParams ;
118126
119127 await Meteor . callAsync ( 'setUserActiveStatus' , userId , active , Boolean ( confirmRelinquish ) ) ;
128+ // This has no other use than for auditing active status changes
129+ // 'setUserActiveStatus' has a lot of side effects making it difficult to use updater
130+ // This updater should have been already commited by this point
131+ _updater . set ( 'active' , active ) ;
132+ }
133+
134+ if ( this . bodyParams . data . password || this . bodyParams . data . setRandomPassword ) {
135+ // Password is also not tracker by updater
136+ _updater . set ( 'services' , { password : { } } ) ;
120137 }
138+
139+ auditStore . setUpdateFilter ( _updater . _getUpdateFilter ( ) ) ;
140+ void auditStore . commitAuditEvent ( ) ;
141+
121142 const { fields } = await this . parseJsonQuery ( ) ;
122143
123144 const user = await Users . findOneById ( this . bodyParams . userId , { projection : fields } ) ;
0 commit comments