Просмотр исходного кода

Merge pull request #24181 from overleaf/bg-Project-Audit-Log-Transfer-ownership-is-missing-the-IP-address

add missing ip adress to audit log for transfer ownership

GitOrigin-RevId: c14494efce25efa92a6cd81bcf197d8f897571bb
Brian Gough 1 год назад
Родитель
Сommit
a04d3198a8

+ 1 - 0
services/web/app/src/Features/Collaborators/CollaboratorsController.mjs

@@ -122,6 +122,7 @@ async function transferOwnership(req, res, next) {
       {
         allowTransferToNonCollaborators: hasAdminAccess(sessionUser),
         sessionUserId: new ObjectId(sessionUser._id),
+        ipAddress: req.ip,
       }
     )
     res.sendStatus(204)

+ 7 - 2
services/web/app/src/Features/Collaborators/OwnershipTransferHandler.js

@@ -15,7 +15,12 @@ module.exports = {
 }
 
 async function transferOwnership(projectId, newOwnerId, options = {}) {
-  const { allowTransferToNonCollaborators, sessionUserId, skipEmails } = options
+  const {
+    allowTransferToNonCollaborators,
+    sessionUserId,
+    skipEmails,
+    ipAddress,
+  } = options
 
   // Fetch project and user
   const [project, newOwner] = await Promise.all([
@@ -49,7 +54,7 @@ async function transferOwnership(projectId, newOwnerId, options = {}) {
     projectId,
     'transfer-ownership',
     sessionUserId,
-    '', // IP address
+    ipAddress,
     { previousOwnerId, newOwnerId }
   )
 

+ 3 - 2
services/web/test/unit/src/Collaborators/OwnershipTransferHandlerTests.js

@@ -261,10 +261,11 @@ describe('OwnershipTransferHandler', function () {
 
     it('should write an entry in the audit log', async function () {
       const sessionUserId = new ObjectId()
+      const ipAddress = '1.2.3.4'
       await this.handler.promises.transferOwnership(
         this.project._id,
         this.collaborator._id,
-        { sessionUserId }
+        { sessionUserId, ipAddress }
       )
       expect(
         this.ProjectAuditLogHandler.promises.addEntry
@@ -272,7 +273,7 @@ describe('OwnershipTransferHandler', function () {
         this.project._id,
         'transfer-ownership',
         sessionUserId,
-        '', // IP address
+        ipAddress,
         {
           previousOwnerId: this.user._id,
           newOwnerId: this.collaborator._id,